class_docstr: A residual block that can optionally change the number of channels.
  :param channels: the number of input channels.
  :param emb_channels: the number of timestep embedding channels.
  :param dropout: the rate of dropout.
  :param out_channels: if specified, the number of out channels.
  :param use_conv: if True and out_channels is specified, use a spatial
      convolution instead of a smaller 1x1 convolution to change the
      channels in the skip connection.
  :param dims: determines if the signal is 1D, 2D, or 3D.
  :param use_checkpoint: if True, use gradient checkpointing on this module.
  :param up: if True, use this block for upsampling.
  :param down: if True, use this block for downsampling.
class_docstr_tok: ["A","residual","block","that","can","optionally","change","the","number","of","channels",".",":","param","channels",":","the","number","of","input","channels",".",":","param","emb_channels",":","the","number","of","timestep","embedding","channels",".",":","param","dropout",":","the","rate","of","dropout",".",":","param","out_channels",":","if","specified",",","the","number","of","out","channels",".",":","param","use_conv",":","if","True","and","out_channels","is","specified",",","use","a","spatial","convolution","instead","of","a","smaller","1x1","convolution","to","change","the","channels","in","the","skip","connection",".",":","param","dims",":","determines","if","the","signal","is","1D",",","2D",",","or","3D",".",":","param","use_checkpoint",":","if","True",",","use","gradient","checkpointing","on","this","module",".",":","param","up",":","if","True",",","use","this","block","for","upsampling",".",":","param","down",":","if","True",",","use","this","block","for","downsampling","."]
code: def __init__(
      self,
      channels: int,
      emb_channels: int,
      dropout: float,
      out_channels: Optional[int] = None,
      use_conv: bool = False,
      use_scale_shift_norm: bool = False,
      dims: int = 2,
      use_checkpoint: bool = False,
      up: bool = False,
      down: bool = False,
      kernel_size: int = 3,
      exchange_temb_dims: bool = False,
      skip_t_emb: bool = False,
  ):
      super().__init__()
      self.channels = channels
      self.emb_channels = emb_channels
      self.dropout = dropout
      self.out_channels = out_channels or channels
      self.use_conv = use_conv
      self.use_checkpoint = use_checkpoint
      self.use_scale_shift_norm = use_scale_shift_norm
      self.exchange_temb_dims = exchange_temb_dims
  
      if isinstance(kernel_size, Iterable):
          padding = [k // 2 for k in kernel_size]
      else:
          padding = kernel_size // 2
  
      self.in_layers = nn.Sequential(
          normalization(channels),
          nn.SiLU(),
          conv_nd(
              dims,
              channels,
              self.out_channels,
              kernel_size,
              padding=padding,
          ),
      )
  
      self.updown = up or down
  
      if up:
          self.h_upd = Upsample(channels, False, dims)
          self.x_upd = Upsample(channels, False, dims)
      elif down:
          self.h_upd = Downsample(channels, False, dims)
          self.x_upd = Downsample(channels, False, dims)
      else:
          self.h_upd = self.x_upd = nn.Identity()
  
      self.skip_t_emb = skip_t_emb
      self.emb_out_channels = (
          2 * self.out_channels
          if use_scale_shift_norm
          else self.out_channels
      )
      if self.skip_t_emb:
          logpy.info(
              f"Skipping timestep embedding in {self.__class__.__name__}"
          )
          assert not self.use_scale_shift_norm
          self.emb_layers = None
          self.exchange_temb_dims = False
      else:
          self.emb_layers = nn.Sequential(
              nn.SiLU(),
              linear(
                  emb_channels,
                  self.emb_out_channels,
              ),
          )
  
      self.out_layers = nn.Sequential(
          normalization(self.out_channels),
          nn.SiLU(),
          nn.Dropout(p=dropout),
          zero_module(
              conv_nd(
                  dims,
                  self.out_channels,
                  self.out_channels,
                  kernel_size,
                  padding=padding,
              )
          ),
      )
  
      if self.out_channels == channels:
          self.skip_connection = nn.Identity()
      elif use_conv:
          self.skip_connection = conv_nd(
              dims,
              channels,
              self.out_channels,
              kernel_size,
              padding=padding,
          )
      else:
          self.skip_connection = conv_nd(
              dims, channels, self.out_channels, 1
          )
  
imports: import logging
  import math
  from abc import abstractmethod
  from typing import Iterable, List, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from einops import rearrange
  from torch.utils.checkpoint import checkpoint
  from ...modules.attention import SpatialTransformer
  from ...modules.diffusionmodules.util import avg_pool_nd, conv_nd, linear, normalization, timestep_embedding, zero_module
  from ...modules.video_attention import SpatialVideoTransformer
  from ...util import exists
label_desc: Use image node_id 1 to create a new ResBlock object from inherited base classes: TimestepBlock with example: obj = ResBlock(channels, emb_channels, dropout, out_channels, use_conv, use_scale_shift_norm, dims, use_checkpoint, up, down, kernel_size, exchange_temb_dims, skip_t_emb)