| 47 | return embedding |
| 48 | |
| 49 | class ControlNetModel(ModelMixin, ConfigMixin): |
| 50 | |
| 51 | @register_to_config |
| 52 | def __init__( |
| 53 | self, |
| 54 | in_channels=4, |
| 55 | flip_sin_to_cos=True, |
| 56 | freq_shift=0, |
| 57 | down_block_types=( |
| 58 | "CrossAttnDownBlock2D", |
| 59 | "CrossAttnDownBlock2D", |
| 60 | "CrossAttnDownBlock2D", |
| 61 | "DownBlock2D", |
| 62 | ), |
| 63 | only_cross_attention=False, |
| 64 | block_out_channels=(320, 640, 1280, 1280), |
| 65 | layers_per_block=2, |
| 66 | downsample_padding=1, |
| 67 | mid_block_scale_factor=1, |
| 68 | act_fn="silu", |
| 69 | norm_num_groups=32, |
| 70 | norm_eps=1e-5, |
| 71 | cross_attention_dim=1280, |
| 72 | transformer_layers_per_block=1, |
| 73 | attention_head_dim=8, |
| 74 | use_linear_projection=False, |
| 75 | upcast_attention=False, |
| 76 | resnet_time_scale_shift="default", |
| 77 | conditioning_embedding_out_channels=(16, 32, 96, 256), |
| 78 | **kwargs, |
| 79 | ): |
| 80 | super().__init__() |
| 81 | |
| 82 | # Check inputs |
| 83 | if len(block_out_channels) != len(down_block_types): |
| 84 | raise ValueError( |
| 85 | f"Must provide the same number of `block_out_channels` as `down_block_types`. `block_out_channels`: {block_out_channels}. `down_block_types`: {down_block_types}." |
| 86 | ) |
| 87 | |
| 88 | if not isinstance(only_cross_attention, bool) and len(only_cross_attention) != len(down_block_types): |
| 89 | raise ValueError( |
| 90 | f"Must provide the same number of `only_cross_attention` as `down_block_types`. `only_cross_attention`: {only_cross_attention}. `down_block_types`: {down_block_types}." |
| 91 | ) |
| 92 | |
| 93 | if not isinstance(attention_head_dim, int) and len(attention_head_dim) != len(down_block_types): |
| 94 | raise ValueError( |
| 95 | f"Must provide the same number of `attention_head_dim` as `down_block_types`. `attention_head_dim`: {attention_head_dim}. `down_block_types`: {down_block_types}." |
| 96 | ) |
| 97 | |
| 98 | self._register_load_state_dict_pre_hook(linear_to_conv2d_map) |
| 99 | |
| 100 | # input |
| 101 | conv_in_kernel = 3 |
| 102 | conv_in_padding = (conv_in_kernel - 1) // 2 |
| 103 | self.conv_in = nn.Conv2d( |
| 104 | in_channels, block_out_channels[0], kernel_size=conv_in_kernel, padding=conv_in_padding |
| 105 | ) |
| 106 |
nothing calls this directly
no outgoing calls
no test coverage detected