| 767 | |
| 768 | |
| 769 | class CrossAttnDownBlock2D(nn.Module): |
| 770 | def __init__( |
| 771 | self, |
| 772 | in_channels: int, |
| 773 | out_channels: int, |
| 774 | temb_channels: int, |
| 775 | dropout: float = 0.0, |
| 776 | num_layers: int = 1, |
| 777 | transformer_layers_per_block: Union[int, Tuple[int]] = 1, |
| 778 | resnet_eps: float = 1e-6, |
| 779 | resnet_time_scale_shift: str = "default", |
| 780 | resnet_act_fn: str = "swish", |
| 781 | resnet_groups: int = 32, |
| 782 | resnet_pre_norm: bool = True, |
| 783 | norm_type: str = "layer_norm", |
| 784 | num_attention_heads: int = 1, |
| 785 | cross_attention_dim: int = 1280, |
| 786 | cross_attention_norm: str | None = None, |
| 787 | output_scale_factor: float = 1.0, |
| 788 | downsample_padding: int = 1, |
| 789 | add_downsample: bool = True, |
| 790 | dual_cross_attention: bool = False, |
| 791 | use_linear_projection: bool = False, |
| 792 | only_cross_attention: bool = False, |
| 793 | upcast_attention: bool = False, |
| 794 | attention_type: str = "default", |
| 795 | attention_pre_only: bool = False, |
| 796 | attention_bias: bool = False, |
| 797 | use_attention_ffn: bool = True, |
| 798 | ): |
| 799 | super().__init__() |
| 800 | resnets = [] |
| 801 | attentions = [] |
| 802 | |
| 803 | self.has_cross_attention = True |
| 804 | self.num_attention_heads = num_attention_heads |
| 805 | if isinstance(transformer_layers_per_block, int): |
| 806 | transformer_layers_per_block = [transformer_layers_per_block] * num_layers |
| 807 | |
| 808 | for i in range(num_layers): |
| 809 | in_channels = in_channels if i == 0 else out_channels |
| 810 | resnets.append( |
| 811 | ResnetBlock2D( |
| 812 | in_channels=in_channels, |
| 813 | out_channels=out_channels, |
| 814 | temb_channels=temb_channels, |
| 815 | eps=resnet_eps, |
| 816 | groups=resnet_groups, |
| 817 | dropout=dropout, |
| 818 | time_embedding_norm=resnet_time_scale_shift, |
| 819 | non_linearity=resnet_act_fn, |
| 820 | output_scale_factor=output_scale_factor, |
| 821 | pre_norm=resnet_pre_norm, |
| 822 | ) |
| 823 | ) |
| 824 | attentions.append( |
| 825 | MatryoshkaTransformer2DModel( |
| 826 | num_attention_heads, |
no outgoing calls
no test coverage detected
searching dependent graphs…