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

Method __init__

src/diffusers/models/unets/unet_2d_blocks.py:620–734  ·  view source on GitHub ↗
(
        self,
        in_channels: int,
        temb_channels: int,
        dropout: float = 0.0,
        num_layers: int = 1,
        resnet_eps: float = 1e-6,
        resnet_time_scale_shift: str = "default",  # default, spatial
        resnet_act_fn: str = "swish",
        resnet_groups: int = 32,
        attn_groups: int | None = None,
        resnet_pre_norm: bool = True,
        add_attention: bool = True,
        attention_head_dim: int = 1,
        output_scale_factor: float = 1.0,
    )

Source from the content-addressed store, hash-verified

618 """
619
620 def __init__(
621 self,
622 in_channels: int,
623 temb_channels: int,
624 dropout: float = 0.0,
625 num_layers: int = 1,
626 resnet_eps: float = 1e-6,
627 resnet_time_scale_shift: str = "default", # default, spatial
628 resnet_act_fn: str = "swish",
629 resnet_groups: int = 32,
630 attn_groups: int | None = None,
631 resnet_pre_norm: bool = True,
632 add_attention: bool = True,
633 attention_head_dim: int = 1,
634 output_scale_factor: float = 1.0,
635 ):
636 super().__init__()
637 resnet_groups = resnet_groups if resnet_groups is not None else min(in_channels // 4, 32)
638 self.add_attention = add_attention
639
640 if attn_groups is None:
641 attn_groups = resnet_groups if resnet_time_scale_shift == "default" else None
642
643 # there is always at least one resnet
644 if resnet_time_scale_shift == "spatial":
645 resnets = [
646 ResnetBlockCondNorm2D(
647 in_channels=in_channels,
648 out_channels=in_channels,
649 temb_channels=temb_channels,
650 eps=resnet_eps,
651 groups=resnet_groups,
652 dropout=dropout,
653 time_embedding_norm="spatial",
654 non_linearity=resnet_act_fn,
655 output_scale_factor=output_scale_factor,
656 )
657 ]
658 else:
659 resnets = [
660 ResnetBlock2D(
661 in_channels=in_channels,
662 out_channels=in_channels,
663 temb_channels=temb_channels,
664 eps=resnet_eps,
665 groups=resnet_groups,
666 dropout=dropout,
667 time_embedding_norm=resnet_time_scale_shift,
668 non_linearity=resnet_act_fn,
669 output_scale_factor=output_scale_factor,
670 pre_norm=resnet_pre_norm,
671 )
672 ]
673 attentions = []
674
675 if attention_head_dim is None:
676 logger.warning(
677 f"It is not recommend to pass `attention_head_dim=None`. Defaulting `attention_head_dim` to `in_channels`: {in_channels}."

Callers

nothing calls this directly

Calls 4

ResnetBlock2DClass · 0.85
AttentionClass · 0.50
__init__Method · 0.45

Tested by

no test coverage detected