MCPcopy Create free account
hub / github.com/apple/ml-stable-diffusion / UNet2DConditionModel

Class UNet2DConditionModel

python_coreml_stable_diffusion/unet.py:791–1038  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

789
790
791class UNet2DConditionModel(ModelMixin, ConfigMixin):
792
793 @register_to_config
794 def __init__(
795 self,
796 sample_size=None,
797 in_channels=4,
798 out_channels=4,
799 center_input_sample=False,
800 flip_sin_to_cos=True,
801 freq_shift=0,
802 down_block_types=(
803 "CrossAttnDownBlock2D",
804 "CrossAttnDownBlock2D",
805 "CrossAttnDownBlock2D",
806 "DownBlock2D",
807 ),
808 mid_block_type="UNetMidBlock2DCrossAttn",
809 up_block_types=("UpBlock2D", "CrossAttnUpBlock2D",
810 "CrossAttnUpBlock2D", "CrossAttnUpBlock2D"),
811 only_cross_attention=False,
812 block_out_channels=(320, 640, 1280, 1280),
813 layers_per_block=2,
814 downsample_padding=1,
815 mid_block_scale_factor=1,
816 act_fn="silu",
817 norm_num_groups=32,
818 norm_eps=1e-5,
819 cross_attention_dim=768,
820 transformer_layers_per_block=1,
821 attention_head_dim=8,
822 addition_embed_type=None,
823 addition_time_embed_dim=None,
824 projection_class_embeddings_input_dim=None,
825 **kwargs,
826 ):
827 if kwargs.get("dual_cross_attention", None):
828 raise NotImplementedError
829 if kwargs.get("num_classs_embeds", None):
830 raise NotImplementedError
831 if only_cross_attention:
832 raise NotImplementedError
833 if kwargs.get("use_linear_projection", None):
834 logger.warning("`use_linear_projection=True` is ignored!")
835
836 super().__init__()
837 self._register_load_state_dict_pre_hook(linear_to_conv2d_map)
838
839 self.sample_size = sample_size
840 time_embed_dim = block_out_channels[0] * 4
841
842 # input
843 self.conv_in = nn.Conv2d(in_channels,
844 block_out_channels[0],
845 kernel_size=3,
846 padding=(1, 1))
847
848 # time

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected