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

Class AttnSkipDownBlock2D

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

Source from the content-addressed store, hash-verified

1552
1553
1554class AttnSkipDownBlock2D(nn.Module):
1555 def __init__(
1556 self,
1557 in_channels: int,
1558 out_channels: int,
1559 temb_channels: int,
1560 dropout: float = 0.0,
1561 num_layers: int = 1,
1562 resnet_eps: float = 1e-6,
1563 resnet_time_scale_shift: str = "default",
1564 resnet_act_fn: str = "swish",
1565 resnet_pre_norm: bool = True,
1566 attention_head_dim: int = 1,
1567 output_scale_factor: float = np.sqrt(2.0),
1568 add_downsample: bool = True,
1569 ):
1570 super().__init__()
1571 self.attentions = nn.ModuleList([])
1572 self.resnets = nn.ModuleList([])
1573
1574 if attention_head_dim is None:
1575 logger.warning(
1576 f"It is not recommend to pass `attention_head_dim=None`. Defaulting `attention_head_dim` to `in_channels`: {out_channels}."
1577 )
1578 attention_head_dim = out_channels
1579
1580 for i in range(num_layers):
1581 in_channels = in_channels if i == 0 else out_channels
1582 self.resnets.append(
1583 ResnetBlock2D(
1584 in_channels=in_channels,
1585 out_channels=out_channels,
1586 temb_channels=temb_channels,
1587 eps=resnet_eps,
1588 groups=min(in_channels // 4, 32),
1589 groups_out=min(out_channels // 4, 32),
1590 dropout=dropout,
1591 time_embedding_norm=resnet_time_scale_shift,
1592 non_linearity=resnet_act_fn,
1593 output_scale_factor=output_scale_factor,
1594 pre_norm=resnet_pre_norm,
1595 )
1596 )
1597 self.attentions.append(
1598 Attention(
1599 out_channels,
1600 heads=out_channels // attention_head_dim,
1601 dim_head=attention_head_dim,
1602 rescale_output_factor=output_scale_factor,
1603 eps=resnet_eps,
1604 norm_num_groups=32,
1605 residual_connection=True,
1606 bias=True,
1607 upcast_softmax=True,
1608 _from_deprecated_attn_block=True,
1609 )
1610 )
1611

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…