(
self,
*,
in_channels: int,
out_channels: int | None = None,
conv_shortcut: bool = False,
dropout: float = 0.0,
temb_channels: int = 512,
groups: int = 32,
groups_out: int | None = None,
pre_norm: bool = True,
eps: float = 1e-6,
non_linearity: str = "swish",
skip_time_act: bool = False,
time_embedding_norm: str = "default", # default, scale_shift,
kernel: torch.Tensor | None = None,
output_scale_factor: float = 1.0,
use_in_shortcut: bool | None = None,
up: bool = False,
down: bool = False,
conv_shortcut_bias: bool = True,
conv_2d_out_channels: int | None = None,
)
| 217 | """ |
| 218 | |
| 219 | def __init__( |
| 220 | self, |
| 221 | *, |
| 222 | in_channels: int, |
| 223 | out_channels: int | None = None, |
| 224 | conv_shortcut: bool = False, |
| 225 | dropout: float = 0.0, |
| 226 | temb_channels: int = 512, |
| 227 | groups: int = 32, |
| 228 | groups_out: int | None = None, |
| 229 | pre_norm: bool = True, |
| 230 | eps: float = 1e-6, |
| 231 | non_linearity: str = "swish", |
| 232 | skip_time_act: bool = False, |
| 233 | time_embedding_norm: str = "default", # default, scale_shift, |
| 234 | kernel: torch.Tensor | None = None, |
| 235 | output_scale_factor: float = 1.0, |
| 236 | use_in_shortcut: bool | None = None, |
| 237 | up: bool = False, |
| 238 | down: bool = False, |
| 239 | conv_shortcut_bias: bool = True, |
| 240 | conv_2d_out_channels: int | None = None, |
| 241 | ): |
| 242 | super().__init__() |
| 243 | if time_embedding_norm == "ada_group": |
| 244 | raise ValueError( |
| 245 | "This class cannot be used with `time_embedding_norm==ada_group`, please use `ResnetBlockCondNorm2D` instead", |
| 246 | ) |
| 247 | if time_embedding_norm == "spatial": |
| 248 | raise ValueError( |
| 249 | "This class cannot be used with `time_embedding_norm==spatial`, please use `ResnetBlockCondNorm2D` instead", |
| 250 | ) |
| 251 | |
| 252 | self.pre_norm = True |
| 253 | self.in_channels = in_channels |
| 254 | out_channels = in_channels if out_channels is None else out_channels |
| 255 | self.out_channels = out_channels |
| 256 | self.use_conv_shortcut = conv_shortcut |
| 257 | self.up = up |
| 258 | self.down = down |
| 259 | self.output_scale_factor = output_scale_factor |
| 260 | self.time_embedding_norm = time_embedding_norm |
| 261 | self.skip_time_act = skip_time_act |
| 262 | |
| 263 | if groups_out is None: |
| 264 | groups_out = groups |
| 265 | |
| 266 | self.norm1 = torch.nn.GroupNorm(num_groups=groups, num_channels=in_channels, eps=eps, affine=True) |
| 267 | |
| 268 | self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1) |
| 269 | |
| 270 | if temb_channels is not None: |
| 271 | if self.time_embedding_norm == "default": |
| 272 | self.time_emb_proj = nn.Linear(temb_channels, out_channels) |
| 273 | elif self.time_embedding_norm == "scale_shift": |
| 274 | self.time_emb_proj = nn.Linear(temb_channels, 2 * out_channels) |
| 275 | else: |
| 276 | raise ValueError(f"unknown time_embedding_norm : {self.time_embedding_norm} ") |
nothing calls this directly
no test coverage detected