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

Class AttnDownBlock2D

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

Source from the content-addressed store, hash-verified

1025
1026
1027class AttnDownBlock2D(nn.Module):
1028 def __init__(
1029 self,
1030 in_channels: int,
1031 out_channels: int,
1032 temb_channels: int,
1033 dropout: float = 0.0,
1034 num_layers: int = 1,
1035 resnet_eps: float = 1e-6,
1036 resnet_time_scale_shift: str = "default",
1037 resnet_act_fn: str = "swish",
1038 resnet_groups: int = 32,
1039 resnet_pre_norm: bool = True,
1040 attention_head_dim: int = 1,
1041 output_scale_factor: float = 1.0,
1042 downsample_padding: int = 1,
1043 downsample_type: str = "conv",
1044 ):
1045 super().__init__()
1046 resnets = []
1047 attentions = []
1048 self.downsample_type = downsample_type
1049
1050 if attention_head_dim is None:
1051 logger.warning(
1052 f"It is not recommend to pass `attention_head_dim=None`. Defaulting `attention_head_dim` to `in_channels`: {out_channels}."
1053 )
1054 attention_head_dim = out_channels
1055
1056 for i in range(num_layers):
1057 in_channels = in_channels if i == 0 else out_channels
1058 resnets.append(
1059 ResnetBlock2D(
1060 in_channels=in_channels,
1061 out_channels=out_channels,
1062 temb_channels=temb_channels,
1063 eps=resnet_eps,
1064 groups=resnet_groups,
1065 dropout=dropout,
1066 time_embedding_norm=resnet_time_scale_shift,
1067 non_linearity=resnet_act_fn,
1068 output_scale_factor=output_scale_factor,
1069 pre_norm=resnet_pre_norm,
1070 )
1071 )
1072 attentions.append(
1073 Attention(
1074 out_channels,
1075 heads=out_channels // attention_head_dim,
1076 dim_head=attention_head_dim,
1077 rescale_output_factor=output_scale_factor,
1078 eps=resnet_eps,
1079 norm_num_groups=resnet_groups,
1080 residual_connection=True,
1081 bias=True,
1082 upcast_softmax=True,
1083 _from_deprecated_attn_block=True,
1084 )

Callers 1

get_down_blockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected