(
self,
in_channels: int,
out_channels: int,
temb_channels: int,
resolution_idx: int,
dropout: float = 0.0,
num_layers: int = 5,
resnet_eps: float = 1e-5,
resnet_act_fn: str = "gelu",
resnet_group_size: Optional[int] = 32,
add_upsample: bool = True,
)
| 3456 | |
| 3457 | class KUpBlock2D(nn.Module): |
| 3458 | def __init__( |
| 3459 | self, |
| 3460 | in_channels: int, |
| 3461 | out_channels: int, |
| 3462 | temb_channels: int, |
| 3463 | resolution_idx: int, |
| 3464 | dropout: float = 0.0, |
| 3465 | num_layers: int = 5, |
| 3466 | resnet_eps: float = 1e-5, |
| 3467 | resnet_act_fn: str = "gelu", |
| 3468 | resnet_group_size: Optional[int] = 32, |
| 3469 | add_upsample: bool = True, |
| 3470 | ): |
| 3471 | super().__init__() |
| 3472 | resnets = [] |
| 3473 | k_in_channels = 2 * out_channels |
| 3474 | k_out_channels = in_channels |
| 3475 | num_layers = num_layers - 1 |
| 3476 | |
| 3477 | for i in range(num_layers): |
| 3478 | in_channels = k_in_channels if i == 0 else out_channels |
| 3479 | groups = in_channels // resnet_group_size |
| 3480 | groups_out = out_channels // resnet_group_size |
| 3481 | |
| 3482 | resnets.append( |
| 3483 | ResnetBlockCondNorm2D( |
| 3484 | in_channels=in_channels, |
| 3485 | out_channels=k_out_channels if (i == num_layers - 1) else out_channels, |
| 3486 | temb_channels=temb_channels, |
| 3487 | eps=resnet_eps, |
| 3488 | groups=groups, |
| 3489 | groups_out=groups_out, |
| 3490 | dropout=dropout, |
| 3491 | non_linearity=resnet_act_fn, |
| 3492 | time_embedding_norm="ada_group", |
| 3493 | conv_shortcut_bias=False, |
| 3494 | ) |
| 3495 | ) |
| 3496 | |
| 3497 | self.resnets = nn.ModuleList(resnets) |
| 3498 | |
| 3499 | if add_upsample: |
| 3500 | self.upsamplers = nn.ModuleList([KUpsample2D()]) |
| 3501 | else: |
| 3502 | self.upsamplers = None |
| 3503 | |
| 3504 | self.gradient_checkpointing = False |
| 3505 | self.resolution_idx = resolution_idx |
| 3506 | |
| 3507 | def forward( |
| 3508 | self, |
nothing calls this directly
no test coverage detected