class_docstr: Base class of Transfomer decoder module.
  
  Args:
      vocab_size: output dim
      encoder_output_size: dimension of attention
      attention_heads: the number of heads of multi head attention
      linear_units: the number of units of position-wise feed forward
      num_blocks: the number of decoder blocks
      dropout_rate: dropout rate
      self_attention_dropout_rate: dropout rate for attention
      input_layer: input layer type
      use_output_layer: whether to use output layer
      pos_enc_class: PositionalEncoding or ScaledPositionalEncoding
      normalize_before: whether to use layer_norm before the first block
      concat_after: whether to concat attention layer's input and output
          if True, additional linear will be applied.
          i.e. x -> x + linear(concat(x, att(x)))
          if False, no additional linear will be applied.
          i.e. x -> x + att(x)
class_docstr_tok: ["Base","class","of","Transfomer","decoder","module",".","Args",":","vocab_size",":","output","dim","encoder_output_size",":","dimension","of","attention","attention_heads",":","the","number","of","heads","of","multi","head","attention","linear_units",":","the","number","of","units","of","position-wise","feed","forward","num_blocks",":","the","number","of","decoder","blocks","dropout_rate",":","dropout","rate","self_attention_dropout_rate",":","dropout","rate","for","attention","input_layer",":","input","layer","type","use_output_layer",":","whether","to","use","output","layer","pos_enc_class",":","PositionalEncoding","or","ScaledPositionalEncoding","normalize_before",":","whether","to","use","layer_norm","before","the","first","block","concat_after",":","whether","to","concat","attention","layer","'s","input","and","output","if","True",",","additional","linear","will","be","applied",".","i.e",".","x","-",">","x","+","linear","(","concat","(","x",",","att","(","x",")",")",")","if","False",",","no","additional","linear","will","be","applied",".","i.e",".","x","-",">","x","+","att","(","x",")"]
docstr: Forward decoder.
  
  Args:
      hs_pad: encoded memory, float32  (batch, maxlen_in, feat)
      hlens: (batch)
      ys_in_pad:
          input token ids, int64 (batch, maxlen_out)
          if input_layer == "embed"
          input tensor (batch, maxlen_out, #mels) in the other cases
      ys_in_lens: (batch)
      return_hs: (bool) whether to return the last hidden output
                            before output layer
      return_all_hs: (bool) whether to return all the hidden intermediates
  Returns:
      (tuple): tuple containing:
  
      x: decoded token score before softmax (batch, maxlen_out, token)
          if use_output_layer is True,
      olens: (batch, )
docstr_tok: ["Forward","decoder",".","Args",":","hs_pad",":","encoded","memory",",","float32","(","batch",",","maxlen_in",",","feat",")","hlens",":","(","batch",")","ys_in_pad",":","input","token","ids",",","int64","(","batch",",","maxlen_out",")","if","input_layer","==","``","embed","''","input","tensor","(","batch",",","maxlen_out",",","#","mels",")","in","the","other","cases","ys_in_lens",":","(","batch",")","return_hs",":","(","bool",")","whether","to","return","the","last","hidden","output","before","output","layer","return_all_hs",":","(","bool",")","whether","to","return","all","the","hidden","intermediates","Returns",":","(","tuple",")",":","tuple","containing",":","x",":","decoded","token","score","before","softmax","(","batch",",","maxlen_out",",","token",")","if","use_output_layer","is","True",",","olens",":","(","batch",",",")"]
code: def forward(
      self,
      hs_pad: torch.Tensor,
      hlens: torch.Tensor,
      ys_in_pad: torch.Tensor,
      ys_in_lens: torch.Tensor,
      return_hs: bool = False,
      return_all_hs: bool = False,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Forward decoder.
  
      Args:
          hs_pad: encoded memory, float32  (batch, maxlen_in, feat)
          hlens: (batch)
          ys_in_pad:
              input token ids, int64 (batch, maxlen_out)
              if input_layer == "embed"
              input tensor (batch, maxlen_out, #mels) in the other cases
          ys_in_lens: (batch)
          return_hs: (bool) whether to return the last hidden output
                                before output layer
          return_all_hs: (bool) whether to return all the hidden intermediates
      Returns:
          (tuple): tuple containing:
  
          x: decoded token score before softmax (batch, maxlen_out, token)
              if use_output_layer is True,
          olens: (batch, )
      """
      tgt = ys_in_pad
      # tgt_mask: (B, 1, L)
      tgt_mask = (~make_pad_mask(ys_in_lens)[:, None, :]).to(tgt.device)
      # m: (1, L, L)
      m = subsequent_mask(
          tgt_mask.size(-1), device=tgt_mask.device
      ).unsqueeze(0)
      # tgt_mask: (B, L, L)
      tgt_mask = tgt_mask & m
  
      memory = hs_pad
      memory_mask = (~make_pad_mask(hlens, maxlen=memory.size(1)))[
          :, None, :
      ].to(memory.device)
      # Padding for Longformer
      if memory_mask.shape[-1] != memory.shape[1]:
          padlen = memory.shape[1] - memory_mask.shape[-1]
          memory_mask = torch.nn.functional.pad(
              memory_mask, (0, padlen), "constant", False
          )
  
      x = self.embed(tgt)
      intermediate_outs = []
      for layer_idx, decoder_layer in enumerate(self.decoders):
          x, tgt_mask, memory, memory_mask = decoder_layer(
              x, tgt_mask, memory, memory_mask
          )
          if return_all_hs:
              intermediate_outs.append(x)
      if self.normalize_before:
          x = self.after_norm(x)
      if return_hs:
          hidden = x
      if self.output_layer is not None:
          x = self.output_layer(x)
  
      olens = tgt_mask.sum(1)
      if return_hs:
          return (x, hidden), olens
      elif return_all_hs:
          return (x, intermediate_outs), olens
      return x, olens
  
imports: from typing import Any, List, Sequence, Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.decoder.abs_decoder import AbsDecoder
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.decoder_layer import DecoderLayer
  from espnet.nets.pytorch_backend.transformer.dynamic_conv import DynamicConvolution
  from espnet.nets.pytorch_backend.transformer.dynamic_conv2d import DynamicConvolution2D
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding
  from espnet.nets.pytorch_backend.transformer.layer_norm import LayerNorm
  from espnet.nets.pytorch_backend.transformer.lightconv import LightweightConvolution
  from espnet.nets.pytorch_backend.transformer.lightconv2d import LightweightConvolution2D
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
  from espnet.nets.pytorch_backend.transformer.positionwise_feed_forward import PositionwiseFeedForward
  from espnet.nets.pytorch_backend.transformer.repeat import repeat
  from espnet.nets.scorer_interface import BatchScorerInterface
label_desc: Use image node_id 2 for calling the BaseTransformerDecoder obj's underlying member method code with example usage: obj.forward(hs_pad, hlens, ys_in_pad, ys_in_lens, return_hs, return_all_hs) and returns: x,  olens, x,  hidden,  olens, x,  intermediate_outs,  olens