class_docstr: A residual block that can optionally change the number of channels.
  
  Arguments
  ---------
  channels: int
      the number of input channels.
  emb_channels: int
      the number of timestep embedding channels.
  dropout: float
      the rate of dropout.
  out_channels: int
      if specified, the number of out channels.
  use_conv: bool
      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.
  dims: int
      determines if the signal is 1D, 2D, or 3D.
  up: bool
      if True, use this block for upsampling.
  down: bool
      if True, use this block for downsampling.
  norm_num_groups: int
      the number of groups for group normalization
  use_fixup_init: bool
      whether to use FixUp initialization
  
  Example
  -------
  >>> res = ResBlock(
  ...     channels=4,
  ...     emb_channels=8,
  ...     dropout=0.1,
  ...     norm_num_groups=2,
  ...     use_conv=True,
  ... )
  >>> x = torch.randn(2, 4, 32, 32)
  >>> emb = torch.randn(2, 8)
  >>> res_out = res(x, emb)
  >>> res_out.shape
  torch.Size([2, 4, 32, 32])
class_docstr_tok: ["A","residual","block","that","can","optionally","change","the","number","of","channels",".","Arguments","--","--","--","--","-","channels",":","int","the","number","of","input","channels",".","emb_channels",":","int","the","number","of","timestep","embedding","channels",".","dropout",":","float","the","rate","of","dropout",".","out_channels",":","int","if","specified",",","the","number","of","out","channels",".","use_conv",":","bool","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",".","dims",":","int","determines","if","the","signal","is","1D",",","2D",",","or","3D",".","up",":","bool","if","True",",","use","this","block","for","upsampling",".","down",":","bool","if","True",",","use","this","block","for","downsampling",".","norm_num_groups",":","int","the","number","of","groups","for","group","normalization","use_fixup_init",":","bool","whether","to","use","FixUp","initialization","Example","--","--","--","-",">",">",">","res","=","ResBlock","(","...","channels=4",",","...","emb_channels=8",",","...","dropout=0.1",",","...","norm_num_groups=2",",","...","use_conv=True",",","...",")",">",">",">","x","=","torch.randn","(","2",",","4",",","32",",","32",")",">",">",">","emb","=","torch.randn","(","2",",","8",")",">",">",">","res_out","=","res","(","x",",","emb",")",">",">",">","res_out.shape","torch.Size","(","[","2",",","4",",","32",",","32","]",")"]
code: def __init__(
      self,
      channels,
      emb_channels,
      dropout,
      out_channels=None,
      use_conv=False,
      dims=2,
      up=False,
      down=False,
      norm_num_groups=32,
      use_fixup_init=True,
  ):
      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.in_layers = nn.Sequential(
          nn.GroupNorm(norm_num_groups, 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()
  
      if emb_channels is not None:
          self.emb_layers = nn.Sequential(
              nn.SiLU(),
              nn.Linear(
                  emb_channels,
                  self.out_channels,
              ),
          )
      else:
          self.emb_layers = None
      self.out_layers = nn.Sequential(
          nn.GroupNorm(norm_num_groups, self.out_channels),
          nn.SiLU(),
          nn.Dropout(p=dropout),
          fixup(
              conv_nd(
                  dims,
                  self.out_channels,
                  self.out_channels,
                  3,
                  padding=1,
              ),
              use_fixup_init=use_fixup_init,
          ),
      )
  
      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 speechbrain.utils.data_utils import pad_divisible
  from .autoencoders import NormalizingAutoencoder
  import math
  import torch
  import torch.nn
  import torch.nn.functional
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, dims, up, down, norm_num_groups, use_fixup_init)