(
self,
in_channels: int = 4,
conditioning_channels: int = 3,
flip_sin_to_cos: bool = True,
freq_shift: int = 0,
down_block_types: Tuple[str, ...] = (
"CrossAttnDownBlock2D",
"CrossAttnDownBlock2D",
"CrossAttnDownBlock2D",
"DownBlock2D",
),
mid_block_type: Optional[str] = "UNetMidBlock2DCrossAttn",
only_cross_attention: Union[bool, Tuple[bool]] = False,
block_out_channels: Tuple[int, ...] = (320, 640, 1280, 1280),
layers_per_block: int = 2,
downsample_padding: int = 1,
mid_block_scale_factor: float = 1,
act_fn: str = "silu",
norm_num_groups: Optional[int] = 32,
norm_eps: float = 1e-5,
cross_attention_dim: int = 1280,
transformer_layers_per_block: Union[int, Tuple[int, ...]] = 1,
encoder_hid_dim: Optional[int] = None,
encoder_hid_dim_type: Optional[str] = None,
attention_head_dim: Union[int, Tuple[int, ...]] = 8,
num_attention_heads: Optional[Union[int, Tuple[int, ...]]] = None,
use_linear_projection: bool = False,
class_embed_type: Optional[str] = None,
addition_embed_type: Optional[str] = None,
addition_time_embed_dim: Optional[int] = None,
num_class_embeds: Optional[int] = None,
upcast_attention: bool = False,
resnet_time_scale_shift: str = "default",
projection_class_embeddings_input_dim: Optional[int] = None,
controlnet_conditioning_channel_order: str = "rgb",
conditioning_embedding_out_channels: Optional[Tuple[int, ...]] = (16, 32, 96, 256),
global_pool_conditions: bool = False,
addition_embed_type_num_heads: int = 64,
)
| 181 | |
| 182 | @register_to_config |
| 183 | def __init__( |
| 184 | self, |
| 185 | in_channels: int = 4, |
| 186 | conditioning_channels: int = 3, |
| 187 | flip_sin_to_cos: bool = True, |
| 188 | freq_shift: int = 0, |
| 189 | down_block_types: Tuple[str, ...] = ( |
| 190 | "CrossAttnDownBlock2D", |
| 191 | "CrossAttnDownBlock2D", |
| 192 | "CrossAttnDownBlock2D", |
| 193 | "DownBlock2D", |
| 194 | ), |
| 195 | mid_block_type: Optional[str] = "UNetMidBlock2DCrossAttn", |
| 196 | only_cross_attention: Union[bool, Tuple[bool]] = False, |
| 197 | block_out_channels: Tuple[int, ...] = (320, 640, 1280, 1280), |
| 198 | layers_per_block: int = 2, |
| 199 | downsample_padding: int = 1, |
| 200 | mid_block_scale_factor: float = 1, |
| 201 | act_fn: str = "silu", |
| 202 | norm_num_groups: Optional[int] = 32, |
| 203 | norm_eps: float = 1e-5, |
| 204 | cross_attention_dim: int = 1280, |
| 205 | transformer_layers_per_block: Union[int, Tuple[int, ...]] = 1, |
| 206 | encoder_hid_dim: Optional[int] = None, |
| 207 | encoder_hid_dim_type: Optional[str] = None, |
| 208 | attention_head_dim: Union[int, Tuple[int, ...]] = 8, |
| 209 | num_attention_heads: Optional[Union[int, Tuple[int, ...]]] = None, |
| 210 | use_linear_projection: bool = False, |
| 211 | class_embed_type: Optional[str] = None, |
| 212 | addition_embed_type: Optional[str] = None, |
| 213 | addition_time_embed_dim: Optional[int] = None, |
| 214 | num_class_embeds: Optional[int] = None, |
| 215 | upcast_attention: bool = False, |
| 216 | resnet_time_scale_shift: str = "default", |
| 217 | projection_class_embeddings_input_dim: Optional[int] = None, |
| 218 | controlnet_conditioning_channel_order: str = "rgb", |
| 219 | conditioning_embedding_out_channels: Optional[Tuple[int, ...]] = (16, 32, 96, 256), |
| 220 | global_pool_conditions: bool = False, |
| 221 | addition_embed_type_num_heads: int = 64, |
| 222 | ): |
| 223 | super().__init__() |
| 224 | |
| 225 | # If `num_attention_heads` is not defined (which is the case for most models) |
| 226 | # it will default to `attention_head_dim`. This looks weird upon first reading it and it is. |
| 227 | # The reason for this behavior is to correct for incorrectly named variables that were introduced |
| 228 | # when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131 |
| 229 | # Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking |
| 230 | # which is why we correct for the naming here. |
| 231 | num_attention_heads = num_attention_heads or attention_head_dim |
| 232 | |
| 233 | # Check inputs |
| 234 | if len(block_out_channels) != len(down_block_types): |
| 235 | raise ValueError( |
| 236 | 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}." |
| 237 | ) |
| 238 | |
| 239 | if not isinstance(only_cross_attention, bool) and len(only_cross_attention) != len(down_block_types): |
| 240 | raise ValueError( |
no test coverage detected