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

Method forward

diffusers/src/diffusers/models/resnet.py:149–186  ·  view source on GitHub ↗
(self, input_tensor: torch.Tensor, temb: torch.Tensor, *args, **kwargs)

Source from the content-addressed store, hash-verified

147 )
148
149 def forward(self, input_tensor: torch.Tensor, temb: torch.Tensor, *args, **kwargs) -> torch.Tensor:
150 if len(args) > 0 or kwargs.get("scale", None) is not None:
151 deprecation_message = "The `scale` argument is deprecated and will be ignored. Please remove it, as passing it will raise an error in the future. `scale` should directly be passed while calling the underlying pipeline component i.e., via `cross_attention_kwargs`."
152 deprecate("scale", "1.0.0", deprecation_message)
153
154 hidden_states = input_tensor
155
156 hidden_states = self.norm1(hidden_states, temb)
157
158 hidden_states = self.nonlinearity(hidden_states)
159
160 if self.upsample is not None:
161 # upsample_nearest_nhwc fails with large batch sizes. see https://github.com/huggingface/diffusers/issues/984
162 if hidden_states.shape[0] >= 64:
163 input_tensor = input_tensor.contiguous()
164 hidden_states = hidden_states.contiguous()
165 input_tensor = self.upsample(input_tensor)
166 hidden_states = self.upsample(hidden_states)
167
168 elif self.downsample is not None:
169 input_tensor = self.downsample(input_tensor)
170 hidden_states = self.downsample(hidden_states)
171
172 hidden_states = self.conv1(hidden_states)
173
174 hidden_states = self.norm2(hidden_states, temb)
175
176 hidden_states = self.nonlinearity(hidden_states)
177
178 hidden_states = self.dropout(hidden_states)
179 hidden_states = self.conv2(hidden_states)
180
181 if self.conv_shortcut is not None:
182 input_tensor = self.conv_shortcut(input_tensor)
183
184 output_tensor = (input_tensor + hidden_states) / self.output_scale_factor
185
186 return output_tensor
187
188
189class ResnetBlock2D(nn.Module):

Callers

nothing calls this directly

Calls 2

deprecateFunction · 0.85
downsampleMethod · 0.80

Tested by

no test coverage detected