docstr: Calculate forward propagation.
  
  Args:
      d_outs (LongTensor): Batch of outputs of duration predictor (B, T_text).
      ds (LongTensor): Batch of durations (B, T_text).
      p_outs (Tensor): Batch of outputs of pitch predictor (B, T_text, 1).
      ps (Tensor): Batch of target token-averaged pitch (B, T_text, 1).
      e_outs (Tensor): Batch of outputs of energy predictor (B, T_text, 1).
      es (Tensor): Batch of target token-averaged energy (B, T_text, 1).
      ilens (LongTensor): Batch of the lengths of each input (B,).
  
  Returns:
      Tensor: Duration predictor loss value.
      Tensor: Pitch predictor loss value.
      Tensor: Energy predictor loss value.
docstr_tok: ["Calculate","forward","propagation",".","Args",":","d_outs","(","LongTensor",")",":","Batch","of","outputs","of","duration","predictor","(","B",",","T_text",")",".","ds","(","LongTensor",")",":","Batch","of","durations","(","B",",","T_text",")",".","p_outs","(","Tensor",")",":","Batch","of","outputs","of","pitch","predictor","(","B",",","T_text",",","1",")",".","ps","(","Tensor",")",":","Batch","of","target","token-averaged","pitch","(","B",",","T_text",",","1",")",".","e_outs","(","Tensor",")",":","Batch","of","outputs","of","energy","predictor","(","B",",","T_text",",","1",")",".","es","(","Tensor",")",":","Batch","of","target","token-averaged","energy","(","B",",","T_text",",","1",")",".","ilens","(","LongTensor",")",":","Batch","of","the","lengths","of","each","input","(","B",",",")",".","Returns",":","Tensor",":","Duration","predictor","loss","value",".","Tensor",":","Pitch","predictor","loss","value",".","Tensor",":","Energy","predictor","loss","value","."]
code: def forward(
      self,
      d_outs: torch.Tensor,
      ds: torch.Tensor,
      p_outs: torch.Tensor,
      ps: torch.Tensor,
      e_outs: torch.Tensor,
      es: torch.Tensor,
      ilens: torch.Tensor,
  ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
      """Calculate forward propagation.
  
      Args:
          d_outs (LongTensor): Batch of outputs of duration predictor (B, T_text).
          ds (LongTensor): Batch of durations (B, T_text).
          p_outs (Tensor): Batch of outputs of pitch predictor (B, T_text, 1).
          ps (Tensor): Batch of target token-averaged pitch (B, T_text, 1).
          e_outs (Tensor): Batch of outputs of energy predictor (B, T_text, 1).
          es (Tensor): Batch of target token-averaged energy (B, T_text, 1).
          ilens (LongTensor): Batch of the lengths of each input (B,).
  
      Returns:
          Tensor: Duration predictor loss value.
          Tensor: Pitch predictor loss value.
          Tensor: Energy predictor loss value.
  
      """
      # apply mask to remove padded part
      if self.use_masking:
          duration_masks = make_non_pad_mask(ilens).to(ds.device)
          d_outs = d_outs.masked_select(duration_masks)
          ds = ds.masked_select(duration_masks)
          pitch_masks = (
              make_non_pad_mask(ilens).unsqueeze(-1).to(ds.device)
          )
          p_outs = p_outs.masked_select(pitch_masks)
          e_outs = e_outs.masked_select(pitch_masks)
          ps = ps.masked_select(pitch_masks)
          es = es.masked_select(pitch_masks)
  
      # calculate loss
      duration_loss = self.duration_criterion(d_outs, ds)
      pitch_loss = self.mse_criterion(p_outs, ps)
      energy_loss = self.mse_criterion(e_outs, es)
  
      # make weighted mask and apply it
      if self.use_weighted_masking:
          duration_masks = make_non_pad_mask(ilens).to(ds.device)
          duration_weights = (
              duration_masks.float()
              / duration_masks.sum(dim=1, keepdim=True).float()
          )
          duration_weights /= ds.size(0)
  
          # apply weight
          duration_loss = (
              duration_loss.mul(duration_weights)
              .masked_select(duration_masks)
              .sum()
          )
          pitch_masks = duration_masks.unsqueeze(-1)
          pitch_weights = duration_weights.unsqueeze(-1)
          pitch_loss = (
              pitch_loss.mul(pitch_weights)
              .masked_select(pitch_masks)
              .sum()
          )
          energy_loss = (
              energy_loss.mul(pitch_weights)
              .masked_select(pitch_masks)
              .sum()
          )
  
      return duration_loss, pitch_loss, energy_loss
  
file_path: espnet/espnet2/gan_tts/jets/loss.py
imports: from typing import Tuple
  import numpy
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictorLoss
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
label_desc: Use image node_id 2 for calling the VarianceLoss obj's underlying member method code with example usage: obj.forward(d_outs, ds, p_outs, ps, e_outs, es, ilens) and returns: duration_loss,  pitch_loss,  energy_loss