class_docstr: General class to jointly train text2mel and vocoder parts.
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,).
      speech (Tensor): Speech waveform tensor (B, T_wav).
      speech_lengths (Tensor): Speech length tensor (B,).
  
  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",",",")",".","speech","(","Tensor",")",":","Speech","waveform","tensor","(","B",",","T_wav",")",".","speech_lengths","(","Tensor",")",":","Speech","length","tensor","(","B",",",")",".","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,
      speech: torch.Tensor,
      speech_lengths: torch.Tensor,
      **kwargs,
  ) -> 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,).
          speech (Tensor): Speech waveform tensor (B, T_wav).
          speech_lengths (Tensor): Speech length tensor (B,).
  
      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)
      speech = speech.unsqueeze(1)
  
      # calculate generator outputs
      reuse_cache = True
      if not self.cache_generator_outputs or self._cache is None:
          reuse_cache = False
          # calculate text2mel outputs
          text2mel_loss, stats, feats_gen = self.generator["text2mel"](
              text=text,
              text_lengths=text_lengths,
              feats=feats,
              feats_lengths=feats_lengths,
              joint_training=True,
              **kwargs,
          )
          # get random segments
          feats_gen_, start_idxs = get_random_segments(
              x=feats_gen.transpose(1, 2),
              x_lengths=feats_lengths,
              segment_size=self.segment_size,
          )
          # calculate vocoder outputs
          speech_hat_ = self.generator["vocoder"](feats_gen_)
          if self.use_pqmf:
              speech_hat_ = self.pqmf.synthesis(speech_hat_)
      else:
          _, _, speech_hat_, start_idxs = self._cache
  
      # store cache
      if self.cache_generator_outputs and not reuse_cache:
          self._cache = (text2mel_loss, stats, speech_hat_, start_idxs)
  
      # parse outputs
      speech_ = get_segments(
          x=speech,
          start_idxs=start_idxs
          * self.generator["vocoder"].upsample_factor,
          segment_size=self.segment_size
          * self.generator["vocoder"].upsample_factor,
      )
  
      # calculate discriminator outputs
      p_hat = self.discriminator(speech_hat_.detach())
      p = self.discriminator(speech_)
  
      # calculate losses
      real_loss, fake_loss = self.discriminator_adv_loss(p_hat, p)
      loss = real_loss + fake_loss
  
      stats = dict(
          discriminator_loss=loss.item(),
          real_loss=real_loss.item(),
          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 typing import Any, Dict
  import torch
  from typeguard import check_argument_types
  from espnet2.gan_tts.abs_gan_tts import AbsGANTTS
  from espnet2.gan_tts.hifigan import HiFiGANGenerator, HiFiGANMultiPeriodDiscriminator, HiFiGANMultiScaleDiscriminator, HiFiGANMultiScaleMultiPeriodDiscriminator, HiFiGANPeriodDiscriminator, HiFiGANScaleDiscriminator
  from espnet2.gan_tts.hifigan.loss import DiscriminatorAdversarialLoss, FeatureMatchLoss, GeneratorAdversarialLoss, MelSpectrogramLoss
  from espnet2.gan_tts.melgan import MelGANGenerator, MelGANMultiScaleDiscriminator
  from espnet2.gan_tts.melgan.pqmf import PQMF
  from espnet2.gan_tts.parallel_wavegan import ParallelWaveGANDiscriminator, ParallelWaveGANGenerator
  from espnet2.gan_tts.style_melgan import StyleMelGANDiscriminator, StyleMelGANGenerator
  from espnet2.gan_tts.utils import get_random_segments, get_segments
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.tts.fastspeech import FastSpeech
  from espnet2.tts.fastspeech2 import FastSpeech2
  from espnet2.tts.tacotron2 import Tacotron2
  from espnet2.tts.transformer import Transformer
label_desc: Use image node_id 6 for calling the JointText2Wav obj's underlying member method code with example usage: obj._forward_discrminator(text, text_lengths, feats, feats_lengths, speech, speech_lengths) and returns: dict