class_docstr: Generator module in JETS.
docstr: Calculate forward propagation.
  
  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,).
      pitch (Tensor): Batch of padded token-averaged pitch (B, T_text, 1).
      pitch_lengths (LongTensor): Batch of pitch lengths (B, T_text).
      energy (Tensor): Batch of padded token-averaged energy (B, T_text, 1).
      energy_lengths (LongTensor): Batch of energy lengths (B, T_text).
      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:
      Tensor: Waveform tensor (B, 1, segment_size * upsample_factor).
      Tensor: Binarization loss ().
      Tensor: Log probability attention matrix (B, T_feats, T_text).
      Tensor: Segments start index tensor (B,).
      Tensor: predicted duration (B, T_text).
      Tensor: ground-truth duration obtained from an alignment module (B, T_text).
      Tensor: predicted pitch (B, T_text,1).
      Tensor: ground-truth averaged pitch (B, T_text, 1).
      Tensor: predicted energy (B, T_text, 1).
      Tensor: ground-truth averaged energy (B, T_text, 1).
docstr_tok: ["Calculate","forward","propagation",".","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",",",")",".","pitch","(","Tensor",")",":","Batch","of","padded","token-averaged","pitch","(","B",",","T_text",",","1",")",".","pitch_lengths","(","LongTensor",")",":","Batch","of","pitch","lengths","(","B",",","T_text",")",".","energy","(","Tensor",")",":","Batch","of","padded","token-averaged","energy","(","B",",","T_text",",","1",")",".","energy_lengths","(","LongTensor",")",":","Batch","of","energy","lengths","(","B",",","T_text",")",".","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",":","Tensor",":","Waveform","tensor","(","B",",","1",",","segment_size","*","upsample_factor",")",".","Tensor",":","Binarization","loss","(",")",".","Tensor",":","Log","probability","attention","matrix","(","B",",","T_feats",",","T_text",")",".","Tensor",":","Segments","start","index","tensor","(","B",",",")",".","Tensor",":","predicted","duration","(","B",",","T_text",")",".","Tensor",":","ground-truth","duration","obtained","from","an","alignment","module","(","B",",","T_text",")",".","Tensor",":","predicted","pitch","(","B",",","T_text,1",")",".","Tensor",":","ground-truth","averaged","pitch","(","B",",","T_text",",","1",")",".","Tensor",":","predicted","energy","(","B",",","T_text",",","1",")",".","Tensor",":","ground-truth","averaged","energy","(","B",",","T_text",",","1",")","."]
code: def forward(
      self,
      text: torch.Tensor,
      text_lengths: torch.Tensor,
      feats: torch.Tensor,
      feats_lengths: torch.Tensor,
      pitch: torch.Tensor,
      pitch_lengths: torch.Tensor,
      energy: torch.Tensor,
      energy_lengths: torch.Tensor,
      sids: Optional[torch.Tensor] = None,
      spembs: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
  ) -> Tuple[
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
  ]:
      """Calculate forward propagation.
  
      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,).
          pitch (Tensor): Batch of padded token-averaged pitch (B, T_text, 1).
          pitch_lengths (LongTensor): Batch of pitch lengths (B, T_text).
          energy (Tensor): Batch of padded token-averaged energy (B, T_text, 1).
          energy_lengths (LongTensor): Batch of energy lengths (B, T_text).
          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:
          Tensor: Waveform tensor (B, 1, segment_size * upsample_factor).
          Tensor: Binarization loss ().
          Tensor: Log probability attention matrix (B, T_feats, T_text).
          Tensor: Segments start index tensor (B,).
          Tensor: predicted duration (B, T_text).
          Tensor: ground-truth duration obtained from an alignment module (B, T_text).
          Tensor: predicted pitch (B, T_text,1).
          Tensor: ground-truth averaged pitch (B, T_text, 1).
          Tensor: predicted energy (B, T_text, 1).
          Tensor: ground-truth averaged energy (B, T_text, 1).
  
      """
      text = text[:, : text_lengths.max()]  # for data-parallel
      feats = feats[:, : feats_lengths.max()]  # for data-parallel
      pitch = pitch[:, : pitch_lengths.max()]  # for data-parallel
      energy = energy[:, : energy_lengths.max()]  # for data-parallel
  
      # forward encoder
      x_masks = self._source_mask(text_lengths)
      hs, _ = self.encoder(text, x_masks)  # (B, T_text, adim)
  
      # integrate with GST
      if self.use_gst:
          style_embs = self.gst(feats)
          hs = hs + style_embs.unsqueeze(1)
  
      # integrate with SID and LID embeddings
      if self.spks is not None:
          sid_embs = self.sid_emb(sids.view(-1))
          hs = hs + sid_embs.unsqueeze(1)
      if self.langs is not None:
          lid_embs = self.lid_emb(lids.view(-1))
          hs = hs + lid_embs.unsqueeze(1)
  
      # integrate speaker embedding
      if self.spk_embed_dim is not None:
          hs = self._integrate_with_spk_embed(hs, spembs)
  
      # forward alignment module and obtain duration, averaged pitch, energy
      h_masks = make_pad_mask(text_lengths).to(hs.device)
      log_p_attn = self.alignment_module(
          hs,
          feats,
          text_lengths,
          feats_lengths,
          h_masks,
      )
      ds, bin_loss = viterbi_decode(
          log_p_attn, text_lengths, feats_lengths
      )
      ps = average_by_duration(
          ds, pitch.squeeze(-1), text_lengths, feats_lengths
      ).unsqueeze(-1)
      es = average_by_duration(
          ds, energy.squeeze(-1), text_lengths, feats_lengths
      ).unsqueeze(-1)
  
      # forward duration predictor and variance predictors
      if self.stop_gradient_from_pitch_predictor:
          p_outs = self.pitch_predictor(
              hs.detach(), h_masks.unsqueeze(-1)
          )
      else:
          p_outs = self.pitch_predictor(hs, h_masks.unsqueeze(-1))
      if self.stop_gradient_from_energy_predictor:
          e_outs = self.energy_predictor(
              hs.detach(), h_masks.unsqueeze(-1)
          )
      else:
          e_outs = self.energy_predictor(hs, h_masks.unsqueeze(-1))
      d_outs = self.duration_predictor(hs, h_masks)
  
      # use groundtruth in training
      p_embs = self.pitch_embed(ps.transpose(1, 2)).transpose(1, 2)
      e_embs = self.energy_embed(es.transpose(1, 2)).transpose(1, 2)
      hs = hs + e_embs + p_embs
  
      # upsampling
      h_masks = make_non_pad_mask(feats_lengths).to(hs.device)
      d_masks = make_non_pad_mask(text_lengths).to(ds.device)
      hs = self.length_regulator(
          hs, ds, h_masks, d_masks
      )  # (B, T_feats, adim)
  
      # forward decoder
      h_masks = self._source_mask(feats_lengths)
      zs, _ = self.decoder(hs, h_masks)  # (B, T_feats, adim)
  
      # get random segments
      z_segments, z_start_idxs = get_random_segments(
          zs.transpose(1, 2),
          feats_lengths,
          self.segment_size,
      )
      # forward generator
      wav = self.generator(z_segments)
  
      return (
          wav,
          bin_loss,
          log_p_attn,
          z_start_idxs,
          d_outs,
          ds,
          p_outs,
          ps,
          e_outs,
          es,
      )
  
imports: import logging
  from typing import Any, Dict, List, Optional, Sequence, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from espnet2.gan_tts.hifigan import HiFiGANGenerator
  from espnet2.gan_tts.jets.alignments import AlignmentModule, average_by_duration, viterbi_decode
  from espnet2.gan_tts.jets.length_regulator import GaussianUpsampling
  from espnet2.gan_tts.utils import get_random_segments
  from espnet2.torch_utils.initialize import initialize
  from espnet2.tts.fastspeech2.variance_predictor import VariancePredictor
  from espnet2.tts.gst.style_encoder import StyleEncoder
  from espnet.nets.pytorch_backend.conformer.encoder import Encoder
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictor
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask, make_pad_mask
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
label_desc: Use image node_id 2 for calling the JETSGenerator obj's underlying member method code with example usage: obj.forward(text, text_lengths, feats, feats_lengths, pitch, pitch_lengths, energy, energy_lengths, sids, spembs, lids) and returns: wav,  bin_loss,  log_p_attn,  z_start_idxs,  d_outs,  ds,  p_outs,  ps,  e_outs,  es