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 discriminator forward.
  
  Args:
      text (Tensor): Text index tensor (B, T_text).
      text_lengths (Tensor): Text length tensor (B,).
      feats (Tensor): Feature tensor (B, T_feats, aux_channels).
      feats_lengths (Tensor): Feature length tensor (B,).
      singing (Tensor): Singing waveform tensor (B, T_wav).
      singing_lengths (Tensor): Singing length tensor (B,).
      label (Tensor): Label index tensor (B, T_text).
      label_lengths (Tensor): Label length tensor (B,).
      melody (Tensor): Melody index tensor (B, T_text).
      gt_dur (Tensor): Groundtruth duration tensor (B, T_text).
      score_dur (Tensor): Score duration tensor (B, T_text).
      slur (Tensor): Slur index tensor (B, T_text).
      pitch (FloatTensor): Batch of padded f0 (B, T_feats).
      ying (Optional[Tensor]): Yin pitch tensor (B, T_feats).
      sids (Optional[Tensor]): Speaker index tensor (B,) or (B, 1).
      spembs (Optional[Tensor]): Speaker embedding tensor (B, spk_embed_dim).
      lids (Optional[Tensor]): Language index tensor (B,) or (B, 1).
  
  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","discriminator","forward",".","Args",":","text","(","Tensor",")",":","Text","index","tensor","(","B",",","T_text",")",".","text_lengths","(","Tensor",")",":","Text","length","tensor","(","B",",",")",".","feats","(","Tensor",")",":","Feature","tensor","(","B",",","T_feats",",","aux_channels",")",".","feats_lengths","(","Tensor",")",":","Feature","length","tensor","(","B",",",")",".","singing","(","Tensor",")",":","Singing","waveform","tensor","(","B",",","T_wav",")",".","singing_lengths","(","Tensor",")",":","Singing","length","tensor","(","B",",",")",".","label","(","Tensor",")",":","Label","index","tensor","(","B",",","T_text",")",".","label_lengths","(","Tensor",")",":","Label","length","tensor","(","B",",",")",".","melody","(","Tensor",")",":","Melody","index","tensor","(","B",",","T_text",")",".","gt_dur","(","Tensor",")",":","Groundtruth","duration","tensor","(","B",",","T_text",")",".","score_dur","(","Tensor",")",":","Score","duration","tensor","(","B",",","T_text",")",".","slur","(","Tensor",")",":","Slur","index","tensor","(","B",",","T_text",")",".","pitch","(","FloatTensor",")",":","Batch","of","padded","f0","(","B",",","T_feats",")",".","ying","(","Optional","[","Tensor","]",")",":","Yin","pitch","tensor","(","B",",","T_feats",")",".","sids","(","Optional","[","Tensor","]",")",":","Speaker","index","tensor","(","B",",",")","or","(","B",",","1",")",".","spembs","(","Optional","[","Tensor","]",")",":","Speaker","embedding","tensor","(","B",",","spk_embed_dim",")",".","lids","(","Optional","[","Tensor","]",")",":","Language","index","tensor","(","B",",",")","or","(","B",",","1",")",".","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_discrminator(
      self,
      text: torch.Tensor,
      text_lengths: torch.Tensor,
      feats: torch.Tensor,
      feats_lengths: torch.Tensor,
      singing: torch.Tensor,
      singing_lengths: torch.Tensor,
      label: torch.Tensor = None,
      label_lengths: torch.Tensor = None,
      melody: torch.Tensor = None,
      gt_dur: torch.Tensor = None,
      score_dur: torch.Tensor = None,
      slur: torch.Tensor = None,
      pitch: torch.Tensor = None,
      ying: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      spembs: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
  ) -> Dict[str, Any]:
      """Perform discriminator forward.
  
      Args:
          text (Tensor): Text index tensor (B, T_text).
          text_lengths (Tensor): Text length tensor (B,).
          feats (Tensor): Feature tensor (B, T_feats, aux_channels).
          feats_lengths (Tensor): Feature length tensor (B,).
          singing (Tensor): Singing waveform tensor (B, T_wav).
          singing_lengths (Tensor): Singing length tensor (B,).
          label (Tensor): Label index tensor (B, T_text).
          label_lengths (Tensor): Label length tensor (B,).
          melody (Tensor): Melody index tensor (B, T_text).
          gt_dur (Tensor): Groundtruth duration tensor (B, T_text).
          score_dur (Tensor): Score duration tensor (B, T_text).
          slur (Tensor): Slur index tensor (B, T_text).
          pitch (FloatTensor): Batch of padded f0 (B, T_feats).
          ying (Optional[Tensor]): Yin pitch tensor (B, T_feats).
          sids (Optional[Tensor]): Speaker index tensor (B,) or (B, 1).
          spembs (Optional[Tensor]): Speaker embedding tensor (B, spk_embed_dim).
          lids (Optional[Tensor]): Language index tensor (B,) or (B, 1).
  
      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).
  
      """
      # setup
      batch_size = text.size(0)
      feats = feats.transpose(1, 2)
      singing = singing.unsqueeze(1)
  
      # calculate generator outputs
      reuse_cache = True
      if not self.cache_generator_outputs or self._cache is None:
          reuse_cache = False
          outs = self.generator(
              text=text,
              text_lengths=text_lengths,
              feats=feats,
              feats_lengths=feats_lengths,
              gt_dur=gt_dur,
              label=label,
              label_lengths=label_lengths,
              melody=melody,
              score_dur=score_dur,
              slur=slur,
              pitch=pitch,
              ying=ying,
              sids=sids,
              spembs=spembs,
              lids=lids,
          )
      else:
          outs = self._cache
  
      # store cache
      if self.cache_generator_outputs and not reuse_cache:
          self._cache = outs
  
      # parse outputs
      # remove dp loss
      singing_hat_, start_idxs, *_ = outs
      singing_ = get_segments(
          x=singing,
          start_idxs=start_idxs * self.generator.upsample_factor,
          segment_size=self.generator.segment_size
          * self.generator.upsample_factor,
      )
  
      # calculate discriminator outputs
      if "avocodo" in self.discriminator_type:
          detached_singing_hat_ = [x.detach() for x in singing_hat_]
          p, p_hat, fmaps_real, fmaps_fake = self.discriminator(
              singing_, detached_singing_hat_
          )
      else:
          p_hat = self.discriminator(singing_hat_.detach())
          p = self.discriminator(singing_)
  
      # calculate losses
      with autocast(enabled=False):
          real_loss, fake_loss = self.discriminator_adv_loss(p_hat, p)
          loss = real_loss + fake_loss
  
      stats = dict(
          discriminator_loss=loss.item(),
          discriminator_real_loss=real_loss.item(),
          discriminator_fake_loss=fake_loss.item(),
      )
      loss, stats, weight = force_gatherable(
          (loss, stats, batch_size), loss.device
      )
  
      # reset cache
      if reuse_cache or not self.training:
          self._cache = None
  
      return {
          "loss": loss,
          "stats": stats,
          "weight": weight,
          "optim_idx": 1,  # needed for trainer
      }
  
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 6 for calling the VITS obj's underlying member method code with example usage: obj._forward_discrminator(text, text_lengths, feats, feats_lengths, singing, singing_lengths, label, label_lengths, melody, gt_dur, score_dur, slur, pitch, ying, sids, spembs, lids) and returns: dict