class_docstr: Hybrid Demucs model from
  *Hybrid Spectrogram and Waveform Source Separation* :cite:`defossez2021hybrid`.
  
  See Also:
      * :class:`torchaudio.pipelines.SourceSeparationBundle`: Source separation pipeline with pre-trained models.
  
  Args:
      sources (List[str]): list of source names. List can contain the following source
          options: [``"bass"``, ``"drums"``, ``"other"``, ``"mixture"``, ``"vocals"``].
      audio_channels (int, optional): input/output audio channels. (Default: 2)
      channels (int, optional): initial number of hidden channels. (Default: 48)
      growth (int, optional): increase the number of hidden channels by this factor at each layer. (Default: 2)
      nfft (int, optional): number of fft bins. Note that changing this requires careful computation of
          various shape parameters and will not work out of the box for hybrid models. (Default: 4096)
      depth (int, optional): number of layers in encoder and decoder (Default: 6)
      freq_emb (float, optional): add frequency embedding after the first frequency layer if > 0,
          the actual value controls the weight of the embedding. (Default: 0.2)
      emb_scale (int, optional): equivalent to scaling the embedding learning rate (Default: 10)
      emb_smooth (bool, optional): initialize the embedding with a smooth one (with respect to frequencies).
          (Default: ``True``)
      kernel_size (int, optional): kernel_size for encoder and decoder layers. (Default: 8)
      time_stride (int, optional): stride for the final time layer, after the merge. (Default: 2)
      stride (int, optional): stride for encoder and decoder layers. (Default: 4)
      context (int, optional): context for 1x1 conv in the decoder. (Default: 4)
      context_enc (int, optional): context for 1x1 conv in the encoder. (Default: 0)
      norm_starts (int, optional): layer at which group norm starts being used.
          decoder layers are numbered in reverse order. (Default: 4)
      norm_groups (int, optional): number of groups for group norm. (Default: 4)
      dconv_depth (int, optional): depth of residual DConv branch. (Default: 2)
      dconv_comp (int, optional): compression of DConv branch. (Default: 4)
      dconv_attn (int, optional): adds attention layers in DConv branch starting at this layer. (Default: 4)
      dconv_lstm (int, optional): adds a LSTM layer in DConv branch starting at this layer. (Default: 4)
      dconv_init (float, optional): initial scale for the DConv branch LayerScale. (Default: 1e-4)
class_docstr_tok: ["Hybrid","Demucs","model","from","*","Hybrid","Spectrogram","and","Waveform","Source","Separation","*",":","cite",":","`","defossez2021hybrid","`",".","See","Also",":","*",":","class",":","`","torchaudio.pipelines.SourceSeparationBundle","`",":","Source","separation","pipeline","with","pre-trained","models",".","Args",":","sources","(","List","[","str","]",")",":","list","of","source","names",".","List","can","contain","the","following","source","options",":","[","``","``","bass","''","``",",","``","``","drums","''","``",",","``","``","other","''","``",",","``","``","mixture","''","``",",","``","``","vocals","''","``","]",".","audio_channels","(","int",",","optional",")",":","input\/output","audio","channels",".","(","Default",":","2",")","channels","(","int",",","optional",")",":","initial","number","of","hidden","channels",".","(","Default",":","48",")","growth","(","int",",","optional",")",":","increase","the","number","of","hidden","channels","by","this","factor","at","each","layer",".","(","Default",":","2",")","nfft","(","int",",","optional",")",":","number","of","fft","bins",".","Note","that","changing","this","requires","careful","computation","of","various","shape","parameters","and","will","not","work","out","of","the","box","for","hybrid","models",".","(","Default",":","4096",")","depth","(","int",",","optional",")",":","number","of","layers","in","encoder","and","decoder","(","Default",":","6",")","freq_emb","(","float",",","optional",")",":","add","frequency","embedding","after","the","first","frequency","layer","if",">","0",",","the","actual","value","controls","the","weight","of","the","embedding",".","(","Default",":","0.2",")","emb_scale","(","int",",","optional",")",":","equivalent","to","scaling","the","embedding","learning","rate","(","Default",":","10",")","emb_smooth","(","bool",",","optional",")",":","initialize","the","embedding","with","a","smooth","one","(","with","respect","to","frequencies",")",".","(","Default",":","``","True","``",")","kernel_size","(","int",",","optional",")",":","kernel_size","for","encoder","and","decoder","layers",".","(","Default",":","8",")","time_stride","(","int",",","optional",")",":","stride","for","the","final","time","layer",",","after","the","merge",".","(","Default",":","2",")","stride","(","int",",","optional",")",":","stride","for","encoder","and","decoder","layers",".","(","Default",":","4",")","context","(","int",",","optional",")",":","context","for","1x1","conv","in","the","decoder",".","(","Default",":","4",")","context_enc","(","int",",","optional",")",":","context","for","1x1","conv","in","the","encoder",".","(","Default",":","0",")","norm_starts","(","int",",","optional",")",":","layer","at","which","group","norm","starts","being","used",".","decoder","layers","are","numbered","in","reverse","order",".","(","Default",":","4",")","norm_groups","(","int",",","optional",")",":","number","of","groups","for","group","norm",".","(","Default",":","4",")","dconv_depth","(","int",",","optional",")",":","depth","of","residual","DConv","branch",".","(","Default",":","2",")","dconv_comp","(","int",",","optional",")",":","compression","of","DConv","branch",".","(","Default",":","4",")","dconv_attn","(","int",",","optional",")",":","adds","attention","layers","in","DConv","branch","starting","at","this","layer",".","(","Default",":","4",")","dconv_lstm","(","int",",","optional",")",":","adds","a","LSTM","layer","in","DConv","branch","starting","at","this","layer",".","(","Default",":","4",")","dconv_init","(","float",",","optional",")",":","initial","scale","for","the","DConv","branch","LayerScale",".","(","Default",":","1e-4",")"]
code: def __init__(
      self,
      sources: List[str],
      audio_channels: int = 2,
      channels: int = 48,
      growth: int = 2,
      nfft: int = 4096,
      depth: int = 6,
      freq_emb: float = 0.2,
      emb_scale: int = 10,
      emb_smooth: bool = True,
      kernel_size: int = 8,
      time_stride: int = 2,
      stride: int = 4,
      context: int = 1,
      context_enc: int = 0,
      norm_starts: int = 4,
      norm_groups: int = 4,
      dconv_depth: int = 2,
      dconv_comp: int = 4,
      dconv_attn: int = 4,
      dconv_lstm: int = 4,
      dconv_init: float = 1e-4,
  ):
      super().__init__()
      self.depth = depth
      self.nfft = nfft
      self.audio_channels = audio_channels
      self.sources = sources
      self.kernel_size = kernel_size
      self.context = context
      self.stride = stride
      self.channels = channels
  
      self.hop_length = self.nfft // 4
      self.freq_emb = None
  
      self.freq_encoder = nn.ModuleList()
      self.freq_decoder = nn.ModuleList()
  
      self.time_encoder = nn.ModuleList()
      self.time_decoder = nn.ModuleList()
  
      chin = audio_channels
      chin_z = chin * 2  # number of channels for the freq branch
      chout = channels
      chout_z = channels
      freqs = self.nfft // 2
  
      for index in range(self.depth):
          lstm = index >= dconv_lstm
          attn = index >= dconv_attn
          norm_type = "group_norm" if index >= norm_starts else "none"
          freq = freqs > 1
          stri = stride
          ker = kernel_size
          if not freq:
              if freqs != 1:
                  raise ValueError(
                      "When freq is false, freqs must be 1."
                  )
              ker = time_stride * 2
              stri = time_stride
  
          pad = True
          last_freq = False
          if freq and freqs <= kernel_size:
              ker = freqs
              pad = False
              last_freq = True
  
          kw = {
              "kernel_size": ker,
              "stride": stri,
              "freq": freq,
              "pad": pad,
              "norm_type": norm_type,
              "norm_groups": norm_groups,
              "dconv_kw": {
                  "lstm": lstm,
                  "attn": attn,
                  "depth": dconv_depth,
                  "compress": dconv_comp,
                  "init": dconv_init,
              },
          }
          kwt = dict(kw)
          kwt["freq"] = 0
          kwt["kernel_size"] = kernel_size
          kwt["stride"] = stride
          kwt["pad"] = True
          kw_dec = dict(kw)
  
          if last_freq:
              chout_z = max(chout, chout_z)
              chout = chout_z
  
          enc = _HEncLayer(chin_z, chout_z, context=context_enc, **kw)
          if freq:
              if last_freq is True and nfft == 2048:
                  kwt["stride"] = 2
                  kwt["kernel_size"] = 4
              tenc = _HEncLayer(
                  chin,
                  chout,
                  context=context_enc,
                  empty=last_freq,
                  **kwt,
              )
              self.time_encoder.append(tenc)
  
          self.freq_encoder.append(enc)
          if index == 0:
              chin = self.audio_channels * len(self.sources)
              chin_z = chin * 2
          dec = _HDecLayer(
              chout_z,
              chin_z,
              last=index == 0,
              context=context,
              **kw_dec,
          )
          if freq:
              tdec = _HDecLayer(
                  chout,
                  chin,
                  empty=last_freq,
                  last=index == 0,
                  context=context,
                  **kwt,
              )
              self.time_decoder.insert(0, tdec)
          self.freq_decoder.insert(0, dec)
  
          chin = chout
          chin_z = chout_z
          chout = int(growth * chout)
          chout_z = int(growth * chout_z)
          if freq:
              if freqs <= kernel_size:
                  freqs = 1
              else:
                  freqs //= stride
          if index == 0 and freq_emb:
              self.freq_emb = _ScaledEmbedding(
                  freqs, chin_z, smooth=emb_smooth, scale=emb_scale
              )
              self.freq_emb_scale = freq_emb
  
      _rescale_module(self)
  
imports: import math
  import typing
  from typing import Any, Dict, List, Optional
  import torch
  from torch import nn
  from torch.nn import functional
label_desc: Use image node_id 1 to create a new HDemucs object from inherited base classes: torch.nn with example: obj = HDemucs(sources, audio_channels, channels, growth, nfft, depth, freq_emb, emb_scale, emb_smooth, kernel_size, time_stride, stride, context, context_enc, norm_starts, norm_groups, dconv_depth, dconv_comp, dconv_attn, dconv_lstm, dconv_init)