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",")"]
docstr: HDemucs forward call
  
  Args:
      input (torch.Tensor): input mixed tensor of shape `(batch_size, channel, num_frames)`
  
  Returns:
      Tensor
          output tensor split into sources of shape `(batch_size, num_sources, channel, num_frames)`
docstr_tok: ["HDemucs","forward","call","Args",":","input","(","torch.Tensor",")",":","input","mixed","tensor","of","shape","`","(","batch_size",",","channel",",","num_frames",")","`","Returns",":","Tensor","output","tensor","split","into","sources","of","shape","`","(","batch_size",",","num_sources",",","channel",",","num_frames",")","`"]
code: def forward(self, input: torch.Tensor):
      r"""HDemucs forward call
  
      Args:
          input (torch.Tensor): input mixed tensor of shape `(batch_size, channel, num_frames)`
  
      Returns:
          Tensor
              output tensor split into sources of shape `(batch_size, num_sources, channel, num_frames)`
      """
  
      if input.ndim != 3:
          raise ValueError(
              f"Expected 3D tensor with dimensions (batch, channel, frames). Found: {input.shape}"
          )
  
      if input.shape[1] != self.audio_channels:
          raise ValueError(
              f"The channel dimension of input Tensor must match `audio_channels` of HDemucs model. "
              f"Found:{input.shape[1]}."
          )
  
      x = input
      length = x.shape[-1]
  
      z = self._spec(input)
      mag = self._magnitude(z)
      x = mag
  
      B, C, Fq, T = x.shape
  
      # unlike previous Demucs, we always normalize because it is easier.
      mean = x.mean(dim=(1, 2, 3), keepdim=True)
      std = x.std(dim=(1, 2, 3), keepdim=True)
      x = (x - mean) / (1e-5 + std)
      # x will be the freq. branch input.
  
      # Prepare the time branch input.
      xt = input
      meant = xt.mean(dim=(1, 2), keepdim=True)
      stdt = xt.std(dim=(1, 2), keepdim=True)
      xt = (xt - meant) / (1e-5 + stdt)
  
      saved = []  # skip connections, freq.
      saved_t = []  # skip connections, time.
      lengths: List[
          int
      ] = []  # saved lengths to properly remove padding, freq branch.
      lengths_t: List[int] = []  # saved lengths for time branch.
  
      for idx, encode in enumerate(self.freq_encoder):
          lengths.append(x.shape[-1])
          inject = None
          if idx < len(self.time_encoder):
              # we have not yet merged branches.
              lengths_t.append(xt.shape[-1])
              tenc = self.time_encoder[idx]
              xt = tenc(xt)
              if not tenc.empty:
                  # save for skip connection
                  saved_t.append(xt)
              else:
                  # tenc contains just the first conv., so that now time and freq.
                  # branches have the same shape and can be merged.
                  inject = xt
          x = encode(x, inject)
          if idx == 0 and self.freq_emb is not None:
              # add frequency embedding to allow for non equivariant convolutions
              # over the frequency axis.
              frs = torch.arange(x.shape[-2], device=x.device)
              emb = (
                  self.freq_emb(frs).t()[None, :, :, None].expand_as(x)
              )
              x = x + self.freq_emb_scale * emb
  
          saved.append(x)
  
      x = torch.zeros_like(x)
      xt = torch.zeros_like(x)
      # initialize everything to zero (signal will go through u-net skips).
  
      for idx, decode in enumerate(self.freq_decoder):
          skip = saved.pop(-1)
          x, pre = decode(x, skip, lengths.pop(-1))
          # `pre` contains the output just before final transposed convolution,
          # which is used when the freq. and time branch separate.
          offset = self.depth - len(self.time_decoder)
          if idx >= offset:
              tdec = self.time_decoder[idx - offset]
              length_t = lengths_t.pop(-1)
              if tdec.empty:
                  if pre.shape[2] != 1:
                      raise ValueError(
                          f"If tdec empty is True, pre shape does not match {pre.shape}"
                      )
                  pre = pre[:, :, 0]
                  xt, _ = tdec(pre, None, length_t)
              else:
                  skip = saved_t.pop(-1)
                  xt, _ = tdec(xt, skip, length_t)
  
      if len(saved) != 0:
          raise AssertionError("saved is not empty")
      if len(lengths_t) != 0:
          raise AssertionError("lengths_t is not empty")
      if len(saved_t) != 0:
          raise AssertionError("saved_t is not empty")
  
      S = len(self.sources)
      x = x.view(B, S, -1, Fq, T)
      x = x * std[:, None] + mean[:, None]
  
      zout = self._mask(x)
      x = self._ispec(zout, length)
  
      xt = xt.view(B, S, -1, length)
      xt = xt * stdt[:, None] + meant[:, None]
      x = xt + x
      return x
  
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 7 for calling the HDemucs obj's underlying member method code with example usage: obj.forward(input) and returns: x