class_docstr: A Resnet block.
  
  Parameters:
      in_channels (`int`): The number of channels in the input.
      out_channels (`int`, *optional*, default to be `None`):
          The number of output channels for the first conv2d layer. If None, same as `in_channels`.
      dropout (`float`, *optional*, defaults to `0.0`): The dropout probability to use.
      temb_channels (`int`, *optional*, default to `512`): the number of channels in timestep embedding.
      groups (`int`, *optional*, default to `32`): The number of groups to use for the first normalization layer.
      groups_out (`int`, *optional*, default to None):
          The number of groups to use for the second normalization layer. if set to None, same as `groups`.
      eps (`float`, *optional*, defaults to `1e-6`): The epsilon to use for the normalization.
      non_linearity (`str`, *optional*, default to `"swish"`): the activation function to use.
      time_embedding_norm (`str`, *optional*, default to `"default"` ): Time scale shift config.
          By default, apply timestep embedding conditioning with a simple shift mechanism. Choose "scale_shift" or
          "ada_group" for a stronger conditioning with scale and shift.
      kernel (`torch.FloatTensor`, optional, default to None): FIR filter, see
          [`~models.resnet.FirUpsample2D`] and [`~models.resnet.FirDownsample2D`].
      output_scale_factor (`float`, *optional*, default to be `1.0`): the scale factor to use for the output.
      use_in_shortcut (`bool`, *optional*, default to `True`):
          If `True`, add a 1x1 nn.conv2d layer for skip-connection.
      up (`bool`, *optional*, default to `False`): If `True`, add an upsample layer.
      down (`bool`, *optional*, default to `False`): If `True`, add a downsample layer.
      conv_shortcut_bias (`bool`, *optional*, default to `True`):  If `True`, adds a learnable bias to the
          `conv_shortcut` output.
      conv_2d_out_channels (`int`, *optional*, default to `None`): the number of channels in the output.
          If None, same as `out_channels`.
class_docstr_tok: ["A","Resnet","block",".","Parameters",":","in_channels","(","`","int","`",")",":","The","number","of","channels","in","the","input",".","out_channels","(","`","int","`",",","*","optional","*",",","default","to","be","`","None","`",")",":","The","number","of","output","channels","for","the","first","conv2d","layer",".","If","None",",","same","as","`","in_channels","`",".","dropout","(","`","float","`",",","*","optional","*",",","defaults","to","`","0.0","`",")",":","The","dropout","probability","to","use",".","temb_channels","(","`","int","`",",","*","optional","*",",","default","to","`","512","`",")",":","the","number","of","channels","in","timestep","embedding",".","groups","(","`","int","`",",","*","optional","*",",","default","to","`","32","`",")",":","The","number","of","groups","to","use","for","the","first","normalization","layer",".","groups_out","(","`","int","`",",","*","optional","*",",","default","to","None",")",":","The","number","of","groups","to","use","for","the","second","normalization","layer",".","if","set","to","None",",","same","as","`","groups","`",".","eps","(","`","float","`",",","*","optional","*",",","defaults","to","`","1e-6","`",")",":","The","epsilon","to","use","for","the","normalization",".","non_linearity","(","`","str","`",",","*","optional","*",",","default","to","`","``","swish","''","`",")",":","the","activation","function","to","use",".","time_embedding_norm","(","`","str","`",",","*","optional","*",",","default","to","`","``","default","''","`",")",":","Time","scale","shift","config",".","By","default",",","apply","timestep","embedding","conditioning","with","a","simple","shift","mechanism",".","Choose","``","scale_shift","''","or","``","ada_group","''","for","a","stronger","conditioning","with","scale","and","shift",".","kernel","(","`","torch.FloatTensor","`",",","optional",",","default","to","None",")",":","FIR","filter",",","see","[","`","~models.resnet.FirUpsample2D","`","]","and","[","`","~models.resnet.FirDownsample2D","`","]",".","output_scale_factor","(","`","float","`",",","*","optional","*",",","default","to","be","`","1.0","`",")",":","the","scale","factor","to","use","for","the","output",".","use_in_shortcut","(","`","bool","`",",","*","optional","*",",","default","to","`","True","`",")",":","If","`","True","`",",","add","a","1x1","nn.conv2d","layer","for","skip-connection",".","up","(","`","bool","`",",","*","optional","*",",","default","to","`","False","`",")",":","If","`","True","`",",","add","an","upsample","layer",".","down","(","`","bool","`",",","*","optional","*",",","default","to","`","False","`",")",":","If","`","True","`",",","add","a","downsample","layer",".","conv_shortcut_bias","(","`","bool","`",",","*","optional","*",",","default","to","`","True","`",")",":","If","`","True","`",",","adds","a","learnable","bias","to","the","`","conv_shortcut","`","output",".","conv_2d_out_channels","(","`","int","`",",","*","optional","*",",","default","to","`","None","`",")",":","the","number","of","channels","in","the","output",".","If","None",",","same","as","`","out_channels","`","."]
code: def forward(self, input_tensor, temb, scale: float = 1.0):
      hidden_states = input_tensor
  
      if (
          self.time_embedding_norm == "ada_group"
          or self.time_embedding_norm == "spatial"
      ):
          hidden_states = self.norm1(hidden_states, temb)
      else:
          hidden_states = self.norm1(hidden_states)
  
      hidden_states = self.nonlinearity(hidden_states)
  
      if self.upsample is not None:
          # upsample_nearest_nhwc fails with large batch sizes. see https://github.com/huggingface/diffusers/issues/984
          if hidden_states.shape[0] >= 64:
              input_tensor = input_tensor.contiguous()
              hidden_states = hidden_states.contiguous()
          input_tensor = (
              self.upsample(input_tensor, scale=scale)
              if isinstance(self.upsample, Upsample2D)
              else self.upsample(input_tensor)
          )
          hidden_states = (
              self.upsample(hidden_states, scale=scale)
              if isinstance(self.upsample, Upsample2D)
              else self.upsample(hidden_states)
          )
      elif self.downsample is not None:
          input_tensor = (
              self.downsample(input_tensor, scale=scale)
              if isinstance(self.downsample, Downsample2D)
              else self.downsample(input_tensor)
          )
          hidden_states = (
              self.downsample(hidden_states, scale=scale)
              if isinstance(self.downsample, Downsample2D)
              else self.downsample(hidden_states)
          )
  
      hidden_states = (
          self.conv1(hidden_states, scale)
          if not USE_PEFT_BACKEND
          else self.conv1(hidden_states)
      )
  
      if self.time_emb_proj is not None:
          if not self.skip_time_act:
              temb = self.nonlinearity(temb)
          temb = (
              self.time_emb_proj(temb, scale)[:, :, None, None]
              if not USE_PEFT_BACKEND
              else self.time_emb_proj(temb)[:, :, None, None]
          )
  
      if temb is not None and self.time_embedding_norm == "default":
          hidden_states = hidden_states + temb
  
      if (
          self.time_embedding_norm == "ada_group"
          or self.time_embedding_norm == "spatial"
      ):
          hidden_states = self.norm2(hidden_states, temb)
      else:
          hidden_states = self.norm2(hidden_states)
  
      if temb is not None and self.time_embedding_norm == "scale_shift":
          scale, shift = torch.chunk(temb, 2, dim=1)
          hidden_states = hidden_states * (1 + scale) + shift
  
      hidden_states = self.nonlinearity(hidden_states)
  
      hidden_states = self.dropout(hidden_states)
      hidden_states = (
          self.conv2(hidden_states, scale)
          if not USE_PEFT_BACKEND
          else self.conv2(hidden_states)
      )
  
      if self.conv_shortcut is not None:
          input_tensor = (
              self.conv_shortcut(input_tensor, scale)
              if not USE_PEFT_BACKEND
              else self.conv_shortcut(input_tensor)
          )
  
      output_tensor = (
          input_tensor + hidden_states
      ) / self.output_scale_factor
  
      return output_tensor
  
imports: from functools import partial
  from typing import Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from ..utils import USE_PEFT_BACKEND
  from .activations import get_activation
  from .attention import AdaGroupNorm
  from .attention_processor import SpatialNorm
  from .lora import LoRACompatibleConv, LoRACompatibleLinear
label_desc: Use image node_id 2 for calling the ResnetBlock2D obj's underlying member method code with example usage: obj.forward(input_tensor, temb, scale) and returns: output_tensor