MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / KUpBlock2D

Class KUpBlock2D

diffusers/src/diffusers/models/unets/unet_2d_blocks.py:3379–3470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3377
3378
3379class KUpBlock2D(nn.Module):
3380 def __init__(
3381 self,
3382 in_channels: int,
3383 out_channels: int,
3384 temb_channels: int,
3385 resolution_idx: int,
3386 dropout: float = 0.0,
3387 num_layers: int = 5,
3388 resnet_eps: float = 1e-5,
3389 resnet_act_fn: str = "gelu",
3390 resnet_group_size: Optional[int] = 32,
3391 add_upsample: bool = True,
3392 ):
3393 super().__init__()
3394 resnets = []
3395 k_in_channels = 2 * out_channels
3396 k_out_channels = in_channels
3397 num_layers = num_layers - 1
3398
3399 for i in range(num_layers):
3400 in_channels = k_in_channels if i == 0 else out_channels
3401 groups = in_channels // resnet_group_size
3402 groups_out = out_channels // resnet_group_size
3403
3404 resnets.append(
3405 ResnetBlockCondNorm2D(
3406 in_channels=in_channels,
3407 out_channels=k_out_channels if (i == num_layers - 1) else out_channels,
3408 temb_channels=temb_channels,
3409 eps=resnet_eps,
3410 groups=groups,
3411 groups_out=groups_out,
3412 dropout=dropout,
3413 non_linearity=resnet_act_fn,
3414 time_embedding_norm="ada_group",
3415 conv_shortcut_bias=False,
3416 )
3417 )
3418
3419 self.resnets = nn.ModuleList(resnets)
3420
3421 if add_upsample:
3422 self.upsamplers = nn.ModuleList([KUpsample2D()])
3423 else:
3424 self.upsamplers = None
3425
3426 self.gradient_checkpointing = False
3427 self.resolution_idx = resolution_idx
3428
3429 def forward(
3430 self,
3431 hidden_states: torch.Tensor,
3432 res_hidden_states_tuple: Tuple[torch.Tensor, ...],
3433 temb: Optional[torch.Tensor] = None,
3434 upsample_size: Optional[int] = None,
3435 *args,
3436 **kwargs,

Callers 1

get_up_blockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected