(self)
| 184 | return self.init(rngs, sample, timesteps, encoder_hidden_states, controlnet_cond)["params"] |
| 185 | |
| 186 | def setup(self) -> None: |
| 187 | block_out_channels = self.block_out_channels |
| 188 | time_embed_dim = block_out_channels[0] * 4 |
| 189 | |
| 190 | # If `num_attention_heads` is not defined (which is the case for most models) |
| 191 | # it will default to `attention_head_dim`. This looks weird upon first reading it and it is. |
| 192 | # The reason for this behavior is to correct for incorrectly named variables that were introduced |
| 193 | # when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131 |
| 194 | # Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking |
| 195 | # which is why we correct for the naming here. |
| 196 | num_attention_heads = self.num_attention_heads or self.attention_head_dim |
| 197 | |
| 198 | # input |
| 199 | self.conv_in = nn.Conv( |
| 200 | block_out_channels[0], |
| 201 | kernel_size=(3, 3), |
| 202 | strides=(1, 1), |
| 203 | padding=((1, 1), (1, 1)), |
| 204 | dtype=self.dtype, |
| 205 | ) |
| 206 | |
| 207 | # time |
| 208 | self.time_proj = FlaxTimesteps( |
| 209 | block_out_channels[0], flip_sin_to_cos=self.flip_sin_to_cos, freq_shift=self.config.freq_shift |
| 210 | ) |
| 211 | self.time_embedding = FlaxTimestepEmbedding(time_embed_dim, dtype=self.dtype) |
| 212 | |
| 213 | self.controlnet_cond_embedding = FlaxControlNetConditioningEmbedding( |
| 214 | conditioning_embedding_channels=block_out_channels[0], |
| 215 | block_out_channels=self.conditioning_embedding_out_channels, |
| 216 | ) |
| 217 | |
| 218 | only_cross_attention = self.only_cross_attention |
| 219 | if isinstance(only_cross_attention, bool): |
| 220 | only_cross_attention = (only_cross_attention,) * len(self.down_block_types) |
| 221 | |
| 222 | if isinstance(num_attention_heads, int): |
| 223 | num_attention_heads = (num_attention_heads,) * len(self.down_block_types) |
| 224 | |
| 225 | # down |
| 226 | down_blocks = [] |
| 227 | controlnet_down_blocks = [] |
| 228 | |
| 229 | output_channel = block_out_channels[0] |
| 230 | |
| 231 | controlnet_block = nn.Conv( |
| 232 | output_channel, |
| 233 | kernel_size=(1, 1), |
| 234 | padding="VALID", |
| 235 | kernel_init=nn.initializers.zeros_init(), |
| 236 | bias_init=nn.initializers.zeros_init(), |
| 237 | dtype=self.dtype, |
| 238 | ) |
| 239 | controlnet_down_blocks.append(controlnet_block) |
| 240 | |
| 241 | for i, down_block_type in enumerate(self.down_block_types): |
| 242 | input_channel = output_channel |
| 243 | output_channel = block_out_channels[i] |
nothing calls this directly
no test coverage detected