class_docstr: VITS module (generator + discriminator).
  
  This is a module of VITS described in `Conditional Variational Autoencoder
  with Adversarial Learning for End-to-End Text-to-Speech`_.
  
  .. _`Conditional Variational Autoencoder with Adversarial Learning for End-to-End
      Text-to-Speech`: https://arxiv.org/abs/2006.04558
docstr: Perform generator forward.
  
  Args:
      text (LongTensor): Batch of padded character ids (B, T_text).
      text_lengths (LongTensor): Batch of lengths of each input batch (B,).
      feats (Tensor): Batch of padded target features (B, Lmax, odim).
      feats_lengths (LongTensor): Batch of the lengths of each target (B,).
      singing (Tensor): Singing waveform tensor (B, T_wav).
      singing_lengths (Tensor): Singing length tensor (B,).
      label (Optional[Dict]): key is "lab" or "score";
          value (LongTensor): Batch of padded label ids (B, T_text).
      label_lengths (Optional[Dict]): key is "lab" or "score";
          value (LongTensor): Batch of the lengths of padded label ids (B, ).
      melody (Optional[Dict]): key is "lab" or "score";
          value (LongTensor): Batch of padded melody (B, T_text).
      pitch (FloatTensor): Batch of padded f0 (B, T_feats).
      duration (Optional[Dict]): key is "lab", "score_phn" or "score_syb";
          value (LongTensor): Batch of padded duration (B, T_text).
      slur (FloatTensor): Batch of padded slur (B, T_text).
      spembs (Optional[Tensor]): Batch of speaker embeddings (B, spk_embed_dim).
      sids (Optional[Tensor]): Batch of speaker IDs (B, 1).
      lids (Optional[Tensor]): Batch of language IDs (B, 1).
      forward_generator (bool): Whether to forward generator.
  
  Returns:
      Dict[str, Any]:
          - loss (Tensor): Loss scalar tensor.
          - stats (Dict[str, float]): Statistics to be monitored.
          - weight (Tensor): Weight tensor to summarize losses.
          - optim_idx (int): Optimizer index (0 for G and 1 for D).
docstr_tok: ["Perform","generator","forward",".","Args",":","text","(","LongTensor",")",":","Batch","of","padded","character","ids","(","B",",","T_text",")",".","text_lengths","(","LongTensor",")",":","Batch","of","lengths","of","each","input","batch","(","B",",",")",".","feats","(","Tensor",")",":","Batch","of","padded","target","features","(","B",",","Lmax",",","odim",")",".","feats_lengths","(","LongTensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","singing","(","Tensor",")",":","Singing","waveform","tensor","(","B",",","T_wav",")",".","singing_lengths","(","Tensor",")",":","Singing","length","tensor","(","B",",",")",".","label","(","Optional","[","Dict","]",")",":","key","is","``","lab","''","or","``","score","''",";","value","(","LongTensor",")",":","Batch","of","padded","label","ids","(","B",",","T_text",")",".","label_lengths","(","Optional","[","Dict","]",")",":","key","is","``","lab","''","or","``","score","''",";","value","(","LongTensor",")",":","Batch","of","the","lengths","of","padded","label","ids","(","B",",",")",".","melody","(","Optional","[","Dict","]",")",":","key","is","``","lab","''","or","``","score","''",";","value","(","LongTensor",")",":","Batch","of","padded","melody","(","B",",","T_text",")",".","pitch","(","FloatTensor",")",":","Batch","of","padded","f0","(","B",",","T_feats",")",".","duration","(","Optional","[","Dict","]",")",":","key","is","``","lab","''",",","``","score_phn","''","or","``","score_syb","''",";","value","(","LongTensor",")",":","Batch","of","padded","duration","(","B",",","T_text",")",".","slur","(","FloatTensor",")",":","Batch","of","padded","slur","(","B",",","T_text",")",".","spembs","(","Optional","[","Tensor","]",")",":","Batch","of","speaker","embeddings","(","B",",","spk_embed_dim",")",".","sids","(","Optional","[","Tensor","]",")",":","Batch","of","speaker","IDs","(","B",",","1",")",".","lids","(","Optional","[","Tensor","]",")",":","Batch","of","language","IDs","(","B",",","1",")",".","forward_generator","(","bool",")",":","Whether","to","forward","generator",".","Returns",":","Dict","[","str",",","Any","]",":","-","loss","(","Tensor",")",":","Loss","scalar","tensor",".","-","stats","(","Dict","[","str",",","float","]",")",":","Statistics","to","be","monitored",".","-","weight","(","Tensor",")",":","Weight","tensor","to","summarize","losses",".","-","optim_idx","(","int",")",":","Optimizer","index","(","0","for","G","and","1","for","D",")","."]
code: def forward(
      self,
      text: torch.Tensor,
      text_lengths: torch.Tensor,
      feats: torch.Tensor,
      feats_lengths: torch.Tensor,
      singing: torch.Tensor,
      singing_lengths: torch.Tensor,
      label: Optional[Dict[str, torch.Tensor]] = None,
      label_lengths: Optional[Dict[str, torch.Tensor]] = None,
      melody: Optional[Dict[str, torch.Tensor]] = None,
      pitch: torch.LongTensor = None,
      ying: torch.Tensor = None,
      duration: Optional[Dict[str, torch.Tensor]] = None,
      slur: torch.LongTensor = None,
      spembs: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      forward_generator: bool = True,
  ) -> Dict[str, Any]:
      """Perform generator forward.
  
      Args:
          text (LongTensor): Batch of padded character ids (B, T_text).
          text_lengths (LongTensor): Batch of lengths of each input batch (B,).
          feats (Tensor): Batch of padded target features (B, Lmax, odim).
          feats_lengths (LongTensor): Batch of the lengths of each target (B,).
          singing (Tensor): Singing waveform tensor (B, T_wav).
          singing_lengths (Tensor): Singing length tensor (B,).
          label (Optional[Dict]): key is "lab" or "score";
              value (LongTensor): Batch of padded label ids (B, T_text).
          label_lengths (Optional[Dict]): key is "lab" or "score";
              value (LongTensor): Batch of the lengths of padded label ids (B, ).
          melody (Optional[Dict]): key is "lab" or "score";
              value (LongTensor): Batch of padded melody (B, T_text).
          pitch (FloatTensor): Batch of padded f0 (B, T_feats).
          duration (Optional[Dict]): key is "lab", "score_phn" or "score_syb";
              value (LongTensor): Batch of padded duration (B, T_text).
          slur (FloatTensor): Batch of padded slur (B, T_text).
          spembs (Optional[Tensor]): Batch of speaker embeddings (B, spk_embed_dim).
          sids (Optional[Tensor]): Batch of speaker IDs (B, 1).
          lids (Optional[Tensor]): Batch of language IDs (B, 1).
          forward_generator (bool): Whether to forward generator.
  
      Returns:
          Dict[str, Any]:
              - loss (Tensor): Loss scalar tensor.
              - stats (Dict[str, float]): Statistics to be monitored.
              - weight (Tensor): Weight tensor to summarize losses.
              - optim_idx (int): Optimizer index (0 for G and 1 for D).
  
      """
      score_dur = duration["score_syb"]
      gt_dur = duration["lab"]
      label = label["lab"]
      label_lengths = label_lengths["lab"]
      melody = melody["lab"]
  
      if forward_generator:
          return self._forward_generator(
              text=text,
              text_lengths=text_lengths,
              feats=feats,
              feats_lengths=feats_lengths,
              singing=singing,
              singing_lengths=singing_lengths,
              label=label,
              label_lengths=label_lengths,
              melody=melody,
              gt_dur=gt_dur,
              score_dur=score_dur,
              slur=slur,
              pitch=pitch,
              ying=ying,
              sids=sids,
              spembs=spembs,
              lids=lids,
          )
      else:
          return self._forward_discrminator(
              text=text,
              text_lengths=text_lengths,
              feats=feats,
              feats_lengths=feats_lengths,
              singing=singing,
              singing_lengths=singing_lengths,
              label=label,
              label_lengths=label_lengths,
              melody=melody,
              gt_dur=gt_dur,
              score_dur=score_dur,
              slur=slur,
              pitch=pitch,
              ying=ying,
              sids=sids,
              spembs=spembs,
              lids=lids,
          )
  
imports: from contextlib import contextmanager
  from distutils.version import LooseVersion
  from typing import Any, Dict, Optional
  import torch
  from torch.nn import functional
  from typeguard import check_argument_types
  from espnet2.gan_svs.abs_gan_svs import AbsGANSVS
  from espnet2.gan_svs.avocodo.avocodo import SBD, AvocodoDiscriminator, AvocodoDiscriminatorPlus, CoMBD
  from espnet2.gan_svs.visinger2.visinger2_vocoder import VISinger2Discriminator
  from espnet2.gan_svs.vits.generator import VISingerGenerator
  from espnet2.gan_tts.hifigan import HiFiGANMultiPeriodDiscriminator, HiFiGANMultiScaleDiscriminator, HiFiGANMultiScaleMultiPeriodDiscriminator, HiFiGANPeriodDiscriminator, HiFiGANScaleDiscriminator
  from espnet2.gan_tts.hifigan.loss import DiscriminatorAdversarialLoss, FeatureMatchLoss, GeneratorAdversarialLoss, MelSpectrogramLoss
  from espnet2.gan_tts.utils import get_segments
  from espnet2.gan_tts.vits.loss import KLDivergenceLoss, KLDivergenceLossWithoutFlow
  from espnet2.torch_utils.device_funcs import force_gatherable
label_desc: Use image node_id 4 for calling the VITS obj's underlying member method code with example usage: obj.forward(text, text_lengths, feats, feats_lengths, singing, singing_lengths, label, label_lengths, melody, pitch, ying, duration, slur, spembs, sids, lids, forward_generator) and returns: self, self