MCPcopy Create free account
hub / github.com/huggingface/diffusers / KCrossAttnDownBlock2D

Class KCrossAttnDownBlock2D

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

Source from the content-addressed store, hash-verified

2065
2066
2067class KCrossAttnDownBlock2D(nn.Module):
2068 def __init__(
2069 self,
2070 in_channels: int,
2071 out_channels: int,
2072 temb_channels: int,
2073 cross_attention_dim: int,
2074 dropout: float = 0.0,
2075 num_layers: int = 4,
2076 resnet_group_size: int = 32,
2077 add_downsample: bool = True,
2078 attention_head_dim: int = 64,
2079 add_self_attention: bool = False,
2080 resnet_eps: float = 1e-5,
2081 resnet_act_fn: str = "gelu",
2082 ):
2083 super().__init__()
2084 resnets = []
2085 attentions = []
2086
2087 self.has_cross_attention = True
2088
2089 for i in range(num_layers):
2090 in_channels = in_channels if i == 0 else out_channels
2091 groups = in_channels // resnet_group_size
2092 groups_out = out_channels // resnet_group_size
2093
2094 resnets.append(
2095 ResnetBlockCondNorm2D(
2096 in_channels=in_channels,
2097 out_channels=out_channels,
2098 dropout=dropout,
2099 temb_channels=temb_channels,
2100 groups=groups,
2101 groups_out=groups_out,
2102 eps=resnet_eps,
2103 non_linearity=resnet_act_fn,
2104 time_embedding_norm="ada_group",
2105 conv_shortcut_bias=False,
2106 )
2107 )
2108 attentions.append(
2109 KAttentionBlock(
2110 out_channels,
2111 out_channels // attention_head_dim,
2112 attention_head_dim,
2113 cross_attention_dim=cross_attention_dim,
2114 temb_channels=temb_channels,
2115 attention_bias=True,
2116 add_self_attention=add_self_attention,
2117 cross_attention_norm="layer_norm",
2118 group_size=resnet_group_size,
2119 )
2120 )
2121
2122 self.resnets = nn.ModuleList(resnets)
2123 self.attentions = nn.ModuleList(attentions)
2124

Callers 1

get_down_blockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…