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

Class UNetMidBlock2DCrossAttn

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

Source from the content-addressed store, hash-verified

749
750
751class UNetMidBlock2DCrossAttn(nn.Module):
752 def __init__(
753 self,
754 in_channels: int,
755 temb_channels: int,
756 out_channels: int | None = None,
757 dropout: float = 0.0,
758 num_layers: int = 1,
759 transformer_layers_per_block: int | tuple[int] = 1,
760 resnet_eps: float = 1e-6,
761 resnet_time_scale_shift: str = "default",
762 resnet_act_fn: str = "swish",
763 resnet_groups: int = 32,
764 resnet_groups_out: int | None = None,
765 resnet_pre_norm: bool = True,
766 num_attention_heads: int = 1,
767 output_scale_factor: float = 1.0,
768 cross_attention_dim: int = 1280,
769 dual_cross_attention: bool = False,
770 use_linear_projection: bool = False,
771 upcast_attention: bool = False,
772 attention_type: str = "default",
773 ):
774 super().__init__()
775
776 out_channels = out_channels or in_channels
777 self.in_channels = in_channels
778 self.out_channels = out_channels
779
780 self.has_cross_attention = True
781 self.num_attention_heads = num_attention_heads
782 resnet_groups = resnet_groups if resnet_groups is not None else min(in_channels // 4, 32)
783
784 # support for variable transformer layers per block
785 if isinstance(transformer_layers_per_block, int):
786 transformer_layers_per_block = [transformer_layers_per_block] * num_layers
787
788 resnet_groups_out = resnet_groups_out or resnet_groups
789
790 # there is always at least one resnet
791 resnets = [
792 ResnetBlock2D(
793 in_channels=in_channels,
794 out_channels=out_channels,
795 temb_channels=temb_channels,
796 eps=resnet_eps,
797 groups=resnet_groups,
798 groups_out=resnet_groups_out,
799 dropout=dropout,
800 time_embedding_norm=resnet_time_scale_shift,
801 non_linearity=resnet_act_fn,
802 output_scale_factor=output_scale_factor,
803 pre_norm=resnet_pre_norm,
804 )
805 ]
806 attentions = []
807
808 for i in range(num_layers):

Callers 7

get_mid_blockFunction · 0.70
__init__Method · 0.70
__init__Method · 0.50
__init__Method · 0.50
get_mid_block_adapterFunction · 0.50
__init__Method · 0.50
__init__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…