MCPcopy Index your code
hub / github.com/huggingface/diffusers / __init__

Method __init__

src/diffusers/models/upsampling.py:90–138  ·  view source on GitHub ↗
(
        self,
        channels: int,
        use_conv: bool = False,
        use_conv_transpose: bool = False,
        out_channels: int | None = None,
        name: str = "conv",
        kernel_size: int | None = None,
        padding=1,
        norm_type=None,
        eps=None,
        elementwise_affine=None,
        bias=True,
        interpolate=True,
    )

Source from the content-addressed store, hash-verified

88 """
89
90 def __init__(
91 self,
92 channels: int,
93 use_conv: bool = False,
94 use_conv_transpose: bool = False,
95 out_channels: int | None = None,
96 name: str = "conv",
97 kernel_size: int | None = None,
98 padding=1,
99 norm_type=None,
100 eps=None,
101 elementwise_affine=None,
102 bias=True,
103 interpolate=True,
104 ):
105 super().__init__()
106 self.channels = channels
107 self.out_channels = out_channels or channels
108 self.use_conv = use_conv
109 self.use_conv_transpose = use_conv_transpose
110 self.name = name
111 self.interpolate = interpolate
112
113 if norm_type == "ln_norm":
114 self.norm = nn.LayerNorm(channels, eps, elementwise_affine)
115 elif norm_type == "rms_norm":
116 self.norm = RMSNorm(channels, eps, elementwise_affine)
117 elif norm_type is None:
118 self.norm = None
119 else:
120 raise ValueError(f"unknown norm_type: {norm_type}")
121
122 conv = None
123 if use_conv_transpose:
124 if kernel_size is None:
125 kernel_size = 4
126 conv = nn.ConvTranspose2d(
127 channels, self.out_channels, kernel_size=kernel_size, stride=2, padding=padding, bias=bias
128 )
129 elif use_conv:
130 if kernel_size is None:
131 kernel_size = 3
132 conv = nn.Conv2d(self.channels, self.out_channels, kernel_size=kernel_size, padding=padding, bias=bias)
133
134 # TODO(Suraj, Patrick) - clean up after weight dicts are correctly renamed
135 if name == "conv":
136 self.conv = conv
137 else:
138 self.Conv2d_0 = conv
139
140 def forward(self, hidden_states: torch.Tensor, output_size: int | None = None, *args, **kwargs) -> torch.Tensor:
141 if len(args) > 0 or kwargs.get("scale", None) is not None:

Callers

nothing calls this directly

Calls 2

RMSNormClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected