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,
      emb_channels,
      dropout,
      out_channels=None,
      use_conv=False,
      use_scale_shift_norm=False,
      dims=2,
      use_checkpoint=False,
      up=False,
      down=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.in_layers = nn.Sequential(
          normalization(channels),
          nn.SiLU(),
          conv_nd(dims, channels, self.out_channels, 3, padding=1),
      )
  
      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.emb_layers = nn.Sequential(
          nn.SiLU(),
          linear(
              emb_channels,
              2 * self.out_channels
              if use_scale_shift_norm
              else self.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,
                  3,
                  padding=1,
              )
          ),
      )
  
      if self.out_channels == channels:
          self.skip_connection = nn.Identity()
      elif use_conv:
          self.skip_connection = conv_nd(
              dims, channels, self.out_channels, 3, padding=1
          )
      else:
          self.skip_connection = conv_nd(
              dims, channels, self.out_channels, 1
          )
  
imports: from abc import abstractmethod
  from functools import partial
  import math
  from typing import Iterable
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from ldm.modules.diffusionmodules.util import checkpoint, conv_nd, linear, avg_pool_nd, zero_module, normalization, timestep_embedding
  from ldm.modules.attention import SpatialTransformer
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)