class_docstr: VC Transformer module.
  
  This is a module of the Voice Transformer Network
  (a.k.a. VTN or Transformer-VC) described in
  `Voice Transformer Network: Sequence-to-Sequence
  Voice Conversion Using Transformer with
  Text-to-Speech Pretraining`_,
  which convert the sequence of acoustic features
  into the sequence of acoustic features.
  
  .. _`Voice Transformer Network: Sequence-to-Sequence
      Voice Conversion Using Transformer with
      Text-to-Speech Pretraining`:
      https://arxiv.org/pdf/1912.06813.pdf
class_docstr_tok: ["VC","Transformer","module",".","This","is","a","module","of","the","Voice","Transformer","Network","(","a.k.a",".","VTN","or","Transformer-VC",")","described","in","`","Voice","Transformer","Network",":","Sequence-to-Sequence","Voice","Conversion","Using","Transformer","with","Text-to-Speech","Pretraining","`","_",",","which","convert","the","sequence","of","acoustic","features","into","the","sequence","of","acoustic","features",".","..","_","`","Voice","Transformer","Network",":","Sequence-to-Sequence","Voice","Conversion","Using","Transformer","with","Text-to-Speech","Pretraining","`",":","https",":","\/\/arxiv.org\/pdf\/1912.06813.pdf"]
docstr: Calculate all of the attention weights.
  
  Args:
      xs (Tensor): Batch of padded acoustic features (B, Tmax, idim).
      ilens (LongTensor): Batch of lengths of each input batch (B,).
      ys (Tensor): Batch of padded target features (B, Lmax, odim).
      olens (LongTensor): Batch of the lengths of each target (B,).
      spembs (Tensor, optional): Batch of speaker embedding vectors
          (B, spk_embed_dim).
      skip_output (bool, optional): Whether to skip calculate the final output.
      keep_tensor (bool, optional): Whether to keep original tensor.
  
  Returns:
      dict: Dict of attention weights and outputs.
docstr_tok: ["Calculate","all","of","the","attention","weights",".","Args",":","xs","(","Tensor",")",":","Batch","of","padded","acoustic","features","(","B",",","Tmax",",","idim",")",".","ilens","(","LongTensor",")",":","Batch","of","lengths","of","each","input","batch","(","B",",",")",".","ys","(","Tensor",")",":","Batch","of","padded","target","features","(","B",",","Lmax",",","odim",")",".","olens","(","LongTensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","spembs","(","Tensor",",","optional",")",":","Batch","of","speaker","embedding","vectors","(","B",",","spk_embed_dim",")",".","skip_output","(","bool",",","optional",")",":","Whether","to","skip","calculate","the","final","output",".","keep_tensor","(","bool",",","optional",")",":","Whether","to","keep","original","tensor",".","Returns",":","dict",":","Dict","of","attention","weights","and","outputs","."]
code: def calculate_all_attentions(
      self,
      xs,
      ilens,
      ys,
      olens,
      spembs=None,
      skip_output=False,
      keep_tensor=False,
      *args,
      **kwargs,
  ):
      """Calculate all of the attention weights.
  
      Args:
          xs (Tensor): Batch of padded acoustic features (B, Tmax, idim).
          ilens (LongTensor): Batch of lengths of each input batch (B,).
          ys (Tensor): Batch of padded target features (B, Lmax, odim).
          olens (LongTensor): Batch of the lengths of each target (B,).
          spembs (Tensor, optional): Batch of speaker embedding vectors
              (B, spk_embed_dim).
          skip_output (bool, optional): Whether to skip calculate the final output.
          keep_tensor (bool, optional): Whether to keep original tensor.
  
      Returns:
          dict: Dict of attention weights and outputs.
  
      """
      with torch.no_grad():
          # thin out input frames for reduction factor
          # (B, Lmax, idim) ->  (B, Lmax // r, idim * r)
          if self.encoder_reduction_factor > 1:
              B, Lmax, idim = xs.shape
              if Lmax % self.encoder_reduction_factor != 0:
                  xs = xs[
                      :, : -(Lmax % self.encoder_reduction_factor), :
                  ]
              xs_ds = xs.contiguous().view(
                  B,
                  int(Lmax / self.encoder_reduction_factor),
                  idim * self.encoder_reduction_factor,
              )
              ilens_ds = ilens.new(
                  [
                      ilen // self.encoder_reduction_factor
                      for ilen in ilens
                  ]
              )
          else:
              xs_ds, ilens_ds = xs, ilens
  
          # forward encoder
          x_masks = self._source_mask(ilens_ds).to(xs.device)
          hs, hs_masks = self.encoder(xs_ds, x_masks)
  
          # integrate speaker embedding
          if self.spk_embed_dim is not None:
              hs = self._integrate_with_spk_embed(hs, spembs)
  
          # thin out frames for reduction factor
          # (B, Lmax, odim) ->  (B, Lmax//r, odim)
          if self.reduction_factor > 1:
              ys_in = ys[
                  :, self.reduction_factor - 1 :: self.reduction_factor
              ]
              olens_in = olens.new(
                  [olen // self.reduction_factor for olen in olens]
              )
          else:
              ys_in, olens_in = ys, olens
  
          # add first zero frame and remove last frame for auto-regressive
          ys_in = self._add_first_frame_and_remove_last_frame(ys_in)
  
          # forward decoder
          y_masks = self._target_mask(olens_in).to(xs.device)
          zs, _ = self.decoder(ys_in, y_masks, hs, hs_masks)
  
          # calculate final outputs
          if not skip_output:
              before_outs = self.feat_out(zs).view(
                  zs.size(0), -1, self.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)
  
      # modifiy mod part of output lengths due to reduction factor > 1
      if self.reduction_factor > 1:
          olens = olens.new(
              [olen - olen % self.reduction_factor for olen in olens]
          )
  
      # store into dict
      att_ws_dict = dict()
      if keep_tensor:
          for name, m in self.named_modules():
              if isinstance(m, MultiHeadedAttention):
                  att_ws_dict[name] = m.attn
          if not skip_output:
              att_ws_dict["before_postnet_fbank"] = before_outs
              att_ws_dict["after_postnet_fbank"] = after_outs
      else:
          for name, m in self.named_modules():
              if isinstance(m, MultiHeadedAttention):
                  attn = m.attn.cpu().numpy()
                  if "encoder" in name:
                      attn = [
                          a[:, :l, :l]
                          for a, l in zip(attn, ilens.tolist())
                      ]
                  elif "decoder" in name:
                      if "src" in name:
                          attn = [
                              a[:, :ol, :il]
                              for a, il, ol in zip(
                                  attn,
                                  ilens.tolist(),
                                  olens_in.tolist(),
                              )
                          ]
                      elif "self" in name:
                          attn = [
                              a[:, :l, :l]
                              for a, l in zip(attn, olens_in.tolist())
                          ]
                      else:
                          logging.warning(
                              "unknown attention module: " + name
                          )
                  else:
                      logging.warning(
                          "unknown attention module: " + name
                      )
                  att_ws_dict[name] = attn
          if not skip_output:
              before_outs = before_outs.cpu().numpy()
              after_outs = after_outs.cpu().numpy()
              att_ws_dict["before_postnet_fbank"] = [
                  m[:l].T for m, l in zip(before_outs, olens.tolist())
              ]
              att_ws_dict["after_postnet_fbank"] = [
                  m[:l].T for m, l in zip(after_outs, olens.tolist())
              ]
  
      return att_ws_dict
  
imports: import logging
  import torch
  import torch.nn.functional
  from espnet.nets.pytorch_backend.e2e_asr_transformer import subsequent_mask
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import Tacotron2Loss
  from espnet.nets.pytorch_backend.e2e_tts_transformer import TTSPlot
  from espnet.nets.pytorch_backend.e2e_tts_transformer import GuidedMultiHeadAttentionLoss
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  from espnet.nets.pytorch_backend.tacotron2.decoder import Prenet
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.decoder import Decoder
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.initializer import initialize
  from espnet.nets.tts_interface import TTSInterface
  from espnet.utils.cli_utils import strtobool
  from espnet.utils.fill_missing_args import fill_missing_args
label_desc: Use image node_id 8 for calling the Transformer obj's underlying member method code with example usage: obj.calculate_all_attentions(xs, ilens, ys, olens, spembs, skip_output, keep_tensor) and returns: att_ws_dict