MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / __init__

Method __init__

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

Source from the content-addressed store, hash-verified

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