(
self,
sample_size: int | tuple[int, int] | None = None,
in_channels: int = 3,
out_channels: int = 3,
center_input_sample: bool = False,
time_embedding_type: str = "positional",
time_embedding_dim: int | None = None,
freq_shift: int = 0,
flip_sin_to_cos: bool = True,
down_block_types: tuple[str, ...] = ("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D"),
mid_block_type: str | None = "UNetMidBlock2D",
up_block_types: tuple[str, ...] = ("AttnUpBlock2D", "AttnUpBlock2D", "AttnUpBlock2D", "UpBlock2D"),
block_out_channels: tuple[int, ...] = (224, 448, 672, 896),
layers_per_block: int = 2,
mid_block_scale_factor: float = 1,
downsample_padding: int = 1,
downsample_type: str = "conv",
upsample_type: str = "conv",
dropout: float = 0.0,
act_fn: str = "silu",
attention_head_dim: int | None = 8,
norm_num_groups: int = 32,
attn_norm_num_groups: int | None = None,
norm_eps: float = 1e-5,
resnet_time_scale_shift: str = "default",
add_attention: bool = True,
class_embed_type: str | None = None,
num_class_embeds: int | None = None,
num_train_timesteps: int | None = None,
)
| 93 | |
| 94 | @register_to_config |
| 95 | def __init__( |
| 96 | self, |
| 97 | sample_size: int | tuple[int, int] | None = None, |
| 98 | in_channels: int = 3, |
| 99 | out_channels: int = 3, |
| 100 | center_input_sample: bool = False, |
| 101 | time_embedding_type: str = "positional", |
| 102 | time_embedding_dim: int | None = None, |
| 103 | freq_shift: int = 0, |
| 104 | flip_sin_to_cos: bool = True, |
| 105 | down_block_types: tuple[str, ...] = ("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D"), |
| 106 | mid_block_type: str | None = "UNetMidBlock2D", |
| 107 | up_block_types: tuple[str, ...] = ("AttnUpBlock2D", "AttnUpBlock2D", "AttnUpBlock2D", "UpBlock2D"), |
| 108 | block_out_channels: tuple[int, ...] = (224, 448, 672, 896), |
| 109 | layers_per_block: int = 2, |
| 110 | mid_block_scale_factor: float = 1, |
| 111 | downsample_padding: int = 1, |
| 112 | downsample_type: str = "conv", |
| 113 | upsample_type: str = "conv", |
| 114 | dropout: float = 0.0, |
| 115 | act_fn: str = "silu", |
| 116 | attention_head_dim: int | None = 8, |
| 117 | norm_num_groups: int = 32, |
| 118 | attn_norm_num_groups: int | None = None, |
| 119 | norm_eps: float = 1e-5, |
| 120 | resnet_time_scale_shift: str = "default", |
| 121 | add_attention: bool = True, |
| 122 | class_embed_type: str | None = None, |
| 123 | num_class_embeds: int | None = None, |
| 124 | num_train_timesteps: int | None = None, |
| 125 | ): |
| 126 | super().__init__() |
| 127 | |
| 128 | self.sample_size = sample_size |
| 129 | time_embed_dim = time_embedding_dim or block_out_channels[0] * 4 |
| 130 | |
| 131 | # Check inputs |
| 132 | if len(down_block_types) != len(up_block_types): |
| 133 | raise ValueError( |
| 134 | f"Must provide the same number of `down_block_types` as `up_block_types`. `down_block_types`: {down_block_types}. `up_block_types`: {up_block_types}." |
| 135 | ) |
| 136 | |
| 137 | if len(block_out_channels) != len(down_block_types): |
| 138 | raise ValueError( |
| 139 | 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}." |
| 140 | ) |
| 141 | |
| 142 | # input |
| 143 | self.conv_in = nn.Conv2d(in_channels, block_out_channels[0], kernel_size=3, padding=(1, 1)) |
| 144 | |
| 145 | # time |
| 146 | if time_embedding_type == "fourier": |
| 147 | self.time_proj = GaussianFourierProjection(embedding_size=block_out_channels[0], scale=16) |
| 148 | timestep_input_dim = 2 * block_out_channels[0] |
| 149 | elif time_embedding_type == "positional": |
| 150 | self.time_proj = Timesteps(block_out_channels[0], flip_sin_to_cos, freq_shift) |
| 151 | timestep_input_dim = block_out_channels[0] |
| 152 | elif time_embedding_type == "learned": |
nothing calls this directly
no test coverage detected