class_docstr: Duration calculator module for FastSpeech.
  
  Todo:
      * Fix the duplicated calculation of diagonal head decision
class_docstr_tok: ["Duration","calculator","module","for","FastSpeech",".","Todo",":","*","Fix","the","duplicated","calculation","of","diagonal","head","decision"]
docstr: Calculate forward propagation.
  
  Args:
      xs (Tensor): Batch of the padded sequences of character ids (B, Tmax).
      ilens (Tensor): Batch of lengths of each input sequence (B,).
      ys (Tensor):
          Batch of the padded sequence of target features (B, Lmax, odim).
      olens (Tensor): Batch of lengths of each output sequence (B,).
      spembs (Tensor, optional):
          Batch of speaker embedding vectors (B, spk_embed_dim).
  
  Returns:
      Tensor: Batch of durations (B, Tmax).
docstr_tok: ["Calculate","forward","propagation",".","Args",":","xs","(","Tensor",")",":","Batch","of","the","padded","sequences","of","character","ids","(","B",",","Tmax",")",".","ilens","(","Tensor",")",":","Batch","of","lengths","of","each","input","sequence","(","B",",",")",".","ys","(","Tensor",")",":","Batch","of","the","padded","sequence","of","target","features","(","B",",","Lmax",",","odim",")",".","olens","(","Tensor",")",":","Batch","of","lengths","of","each","output","sequence","(","B",",",")",".","spembs","(","Tensor",",","optional",")",":","Batch","of","speaker","embedding","vectors","(","B",",","spk_embed_dim",")",".","Returns",":","Tensor",":","Batch","of","durations","(","B",",","Tmax",")","."]
code: def forward(self, xs, ilens, ys, olens, spembs=None):
      """Calculate forward propagation.
  
      Args:
          xs (Tensor): Batch of the padded sequences of character ids (B, Tmax).
          ilens (Tensor): Batch of lengths of each input sequence (B,).
          ys (Tensor):
              Batch of the padded sequence of target features (B, Lmax, odim).
          olens (Tensor): Batch of lengths of each output sequence (B,).
          spembs (Tensor, optional):
              Batch of speaker embedding vectors (B, spk_embed_dim).
  
      Returns:
          Tensor: Batch of durations (B, Tmax).
  
      """
      if isinstance(self.teacher_model, Transformer):
          att_ws = self._calculate_encoder_decoder_attentions(
              xs, ilens, ys, olens, spembs=spembs
          )
          # TODO(kan-bayashi): fix this issue
          # this does not work in multi-gpu case. registered buffer is not saved.
          if int(self.diag_head_idx) == -1:
              self._init_diagonal_head(att_ws)
          att_ws = att_ws[:, self.diag_head_idx]
      else:
          # NOTE(kan-bayashi): Here we assume that the teacher is tacotron 2
          att_ws = self.teacher_model.calculate_all_attentions(
              xs, ilens, ys, spembs=spembs, keep_tensor=True
          )
      durations = [
          self._calculate_duration(att_w, ilen, olen)
          for att_w, ilen, olen in zip(att_ws, ilens, olens)
      ]
  
      return pad_list(durations, 0)
  
file_path: espnet/espnet/nets/pytorch_backend/fastspeech/duration_calculator.py
imports: import torch
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import Tacotron2
  from espnet.nets.pytorch_backend.e2e_tts_transformer import Transformer
  from espnet.nets.pytorch_backend.nets_utils import pad_list
label_desc: Use image node_id 2 for calling the DurationCalculator obj's underlying member method code with example usage: obj.forward(xs, ilens, ys, olens, spembs) and returns: pad_list