class_docstr: FastSpeech2 module.
  
  This is a module of FastSpeech2 described in `FastSpeech 2: Fast and
  High-Quality End-to-End Text to Speech`_. Instead of quantized pitch and
  energy, we use token-averaged value introduced in `FastPitch: Parallel
  Text-to-speech with Pitch Prediction`_.
  
  .. _`FastSpeech 2: Fast and High-Quality End-to-End Text to Speech`:
      https://arxiv.org/abs/2006.04558
  .. _`FastPitch: Parallel Text-to-speech with Pitch Prediction`:
      https://arxiv.org/abs/2006.06873
class_docstr_tok: ["FastSpeech2","module",".","This","is","a","module","of","FastSpeech2","described","in","`","FastSpeech","2",":","Fast","and","High-Quality","End-to-End","Text","to","Speech","`","_",".","Instead","of","quantized","pitch","and","energy",",","we","use","token-averaged","value","introduced","in","`","FastPitch",":","Parallel","Text-to-speech","with","Pitch","Prediction","`","_",".","..","_","`","FastSpeech","2",":","Fast","and","High-Quality","End-to-End","Text","to","Speech","`",":","https",":","\/\/arxiv.org\/abs\/2006.04558","..","_","`","FastPitch",":","Parallel","Text-to-speech","with","Pitch","Prediction","`",":","https",":","\/\/arxiv.org\/abs\/2006.06873"]
code: def _forward(
      self,
      xs: torch.Tensor,
      ilens: torch.Tensor,
      ys: Optional[torch.Tensor] = None,
      olens: Optional[torch.Tensor] = None,
      ds: Optional[torch.Tensor] = None,
      ps: Optional[torch.Tensor] = None,
      es: Optional[torch.Tensor] = None,
      spembs: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      is_inference: bool = False,
      alpha: float = 1.0,
  ) -> Sequence[torch.Tensor]:
      # forward encoder
      x_masks = self._source_mask(ilens)
      hs, _ = self.encoder(xs, x_masks)  # (B, T_text, adim)
  
      # integrate with GST
      if self.use_gst:
          style_embs = self.gst(ys)
          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 duration predictor and variance predictors
      d_masks = make_pad_mask(ilens).to(xs.device)
  
      if self.stop_gradient_from_pitch_predictor:
          p_outs = self.pitch_predictor(
              hs.detach(), d_masks.unsqueeze(-1)
          )
      else:
          p_outs = self.pitch_predictor(hs, d_masks.unsqueeze(-1))
      if self.stop_gradient_from_energy_predictor:
          e_outs = self.energy_predictor(
              hs.detach(), d_masks.unsqueeze(-1)
          )
      else:
          e_outs = self.energy_predictor(hs, d_masks.unsqueeze(-1))
  
      if is_inference:
          d_outs = self.duration_predictor.inference(
              hs, d_masks
          )  # (B, T_text)
          # use prediction in inference
          p_embs = self.pitch_embed(p_outs.transpose(1, 2)).transpose(
              1, 2
          )
          e_embs = self.energy_embed(e_outs.transpose(1, 2)).transpose(
              1, 2
          )
          hs = hs + e_embs + p_embs
          hs = self.length_regulator(
              hs, d_outs, alpha
          )  # (B, T_feats, adim)
      else:
          d_outs = self.duration_predictor(hs, d_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
          hs = self.length_regulator(hs, ds)  # (B, T_feats, adim)
  
      # forward decoder
      if olens is not None and not is_inference:
          if self.reduction_factor > 1:
              olens_in = olens.new(
                  [
                      torch.div(
                          olen,
                          self.reduction_factor,
                          rounding_mode="trunc",
                      )
                      for olen in olens
                  ]
              )
          else:
              olens_in = olens
          h_masks = self._source_mask(olens_in)
      else:
          h_masks = None
      zs, _ = self.decoder(hs, h_masks)  # (B, T_feats, adim)
      before_outs = self.feat_out(zs).view(
          zs.size(0), -1, self.odim
      )  # (B, T_feats, odim)
  
      # postnet -> (B, T_feats//r * r, odim)
      if self.postnet is None:
          after_outs = before_outs
      else:
          after_outs = before_outs + self.postnet(
              before_outs.transpose(1, 2)
          ).transpose(1, 2)
  
      return before_outs, after_outs, d_outs, p_outs, e_outs
  
imports: import logging
  from typing import Dict, Optional, Sequence, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.torch_utils.initialize import initialize
  from espnet2.tts.abs_tts import AbsTTS
  from espnet2.tts.fastspeech2.loss import FastSpeech2Loss
  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.fastspeech.length_regulator import LengthRegulator
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask, make_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  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 3 for calling the FastSpeech2 obj's underlying member method code with example usage: obj._forward(xs, ilens, ys, olens, ds, ps, es, spembs, sids, lids, is_inference, alpha) and returns: before_outs,  after_outs,  d_outs,  p_outs,  e_outs