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: dec hidden state corresponding to ys,
          used for searchable hidden ints
  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",":","dec","hidden","state","corresponding","to","ys",",","used","for","searchable","hidden","ints","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,
      speech: torch.Tensor = None,
      speech_lens: torch.Tensor = None,
      return_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: dec hidden state corresponding to ys,
              used for searchable hidden ints
      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)
  
      if speech is not None:
          speech_mask = (
              ~make_pad_mask(speech_lens, maxlen=speech.size(1))
          )[:, None, :].to(speech.device)
      else:
          speech_mask = None
  
      x = self.embed(tgt)
      if self.use_speech_attn:
          (
              x,
              tgt_mask,
              memory,
              memory_mask,
              _,
              speech,
              speech_mask,
          ) = self.decoders(
              x,
              tgt_mask,
              memory,
              memory_mask,
              None,
              speech,
              speech_mask,
          )
      else:
          x, tgt_mask, memory, memory_mask = self.decoders(
              x, tgt_mask, memory, memory_mask
          )
      if self.normalize_before:
          x = self.after_norm(x)
          if return_hs:
              hs_asr = x
      if self.output_layer is not None:
          x = self.output_layer(x)
  
      olens = tgt_mask.sum(1)
  
      if return_hs:
          return x, olens, hs_asr
  
      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 TransformerMDDecoder obj's underlying member method code with example usage: obj.forward(hs_pad, hlens, ys_in_pad, ys_in_lens, speech, speech_lens, return_hs) and returns: x,  olens, x,  olens,  hs_asr