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

Method forward

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

Source from the content-addressed store, hash-verified

318 )
319
320 def forward(self, input_tensor: torch.Tensor, temb: torch.Tensor, *args, **kwargs) -> torch.Tensor:
321 if len(args) > 0 or kwargs.get("scale", None) is not None:
322 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`."
323 deprecate("scale", "1.0.0", deprecation_message)
324
325 hidden_states = input_tensor
326
327 hidden_states = self.norm1(hidden_states)
328 hidden_states = self.nonlinearity(hidden_states)
329
330 if self.upsample is not None:
331 # upsample_nearest_nhwc fails with large batch sizes. see https://github.com/huggingface/diffusers/issues/984
332 if hidden_states.shape[0] >= 64:
333 input_tensor = input_tensor.contiguous()
334 hidden_states = hidden_states.contiguous()
335 input_tensor = self.upsample(input_tensor)
336 hidden_states = self.upsample(hidden_states)
337 elif self.downsample is not None:
338 input_tensor = self.downsample(input_tensor)
339 hidden_states = self.downsample(hidden_states)
340
341 hidden_states = self.conv1(hidden_states)
342
343 if self.time_emb_proj is not None:
344 if not self.skip_time_act:
345 temb = self.nonlinearity(temb)
346 temb = self.time_emb_proj(temb)[:, :, None, None]
347
348 if self.time_embedding_norm == "default":
349 if temb is not None:
350 hidden_states = hidden_states + temb
351 hidden_states = self.norm2(hidden_states)
352 elif self.time_embedding_norm == "scale_shift":
353 if temb is None:
354 raise ValueError(
355 f" `temb` should not be None when `time_embedding_norm` is {self.time_embedding_norm}"
356 )
357 time_scale, time_shift = torch.chunk(temb, 2, dim=1)
358 hidden_states = self.norm2(hidden_states)
359 hidden_states = hidden_states * (1 + time_scale) + time_shift
360 else:
361 hidden_states = self.norm2(hidden_states)
362
363 hidden_states = self.nonlinearity(hidden_states)
364
365 hidden_states = self.dropout(hidden_states)
366 hidden_states = self.conv2(hidden_states)
367
368 if self.conv_shortcut is not None:
369 input_tensor = self.conv_shortcut(input_tensor)
370
371 output_tensor = (input_tensor + hidden_states) / self.output_scale_factor
372
373 return output_tensor
374
375
376# unet_rl.py

Callers

nothing calls this directly

Calls 2

deprecateFunction · 0.85
downsampleMethod · 0.80

Tested by

no test coverage detected