class_docstr: Multilingual decoder.
class_docstr_tok: ["Multilingual","decoder","."]
code: def forward(
      self,
      input_tokens,
      encoder_out,
      incremental_state=None,
      possible_translation_tokens=None,
  ):
      if input_tokens.size(1) <= 1:
          # This happens in the first time step of beam search. We return
          # flat scores, and wait for the real work in the next time step
          bsz = input_tokens.size(0)
          return (
              utils.maybe_cuda(
                  torch.zeros(bsz, 1, self.max_vocab_size)
              ),
              utils.maybe_cuda(
                  torch.zeros(bsz, 1, encoder_out[0].size(0))
              ),
              None,
          )
      # Vocab reduction not implemented
      assert possible_translation_tokens is None
      # Fetch language IDs and remove them from input_tokens
      # Token sequences start with <GO-token> <lang-id> ...
      lang_ids = (
          input_tokens[:, 1]
          - pytorch_translate_data.MULTILING_DIALECT_ID_OFFSET
      )
      if input_tokens.size(1) > 2:
          input_tokens = torch.cat(
              [input_tokens[:, :1], input_tokens[:, 2:]], dim=1
          )
      else:
          input_tokens = input_tokens[:, :1]
  
      bsz, seq_len = input_tokens.size()[:2]
      if incremental_state is None:
          incremental_state = {
              lang_id: None for lang_id in range(len(self.decoders))
          }
      else:
          seq_len = 1
      # Create tensors for collecting encoder outputs
      # +1 for language ID
      all_logits = utils.maybe_cuda(
          torch.zeros(bsz, seq_len + 1, self.max_vocab_size)
      )
      all_attn_scores = utils.maybe_cuda(
          torch.zeros(bsz, seq_len, encoder_out[0].size(0))
      )
      self.last_bsz = bsz
      self.last_lang_bszs = []
      for lang_id, decoder in enumerate(self.decoders):
          if decoder is None:
              continue
          if lang_id not in incremental_state:
              incremental_state[lang_id] = {}
          indices = torch.nonzero(lang_ids == lang_id)
          lang_bsz = indices.size(0)
          self.last_lang_bszs.append(lang_bsz)
          if lang_bsz == 0:  # Language not in this batch
              for p in decoder.parameters():
                  p.grad = torch.zeros_like(p.data)
              continue
          indices = indices.squeeze(1)
          max_source_length = torch.max(encoder_out[3][indices])
          lang_encoder_out = (
              encoder_out[0][:max_source_length, indices, :],
              encoder_out[1][:, indices, :],
              encoder_out[2][:, indices, :],
              encoder_out[3][indices],
              encoder_out[4][indices, :max_source_length],
              encoder_out[5][:max_source_length, indices, :],
          )
  
          lang_logits, lang_attn_scores, _ = decoder(
              input_tokens[indices],
              lang_encoder_out,
              incremental_state[lang_id],
          )
          all_attn_scores[
              indices, :, :max_source_length
          ] = lang_attn_scores
          all_logits[indices, 1:, : lang_logits.size(2)] = lang_logits
      incremental_state["lang_ids"] = lang_ids
      return all_logits, all_attn_scores, None
  
imports: import torch
  import torch.nn
  from fairseq.models import FairseqEncoder, FairseqIncrementalDecoder
  from pytorch_translate import utils
  from pytorch_translate.data import data
label_desc: Use image node_id 2 for calling the MultilingualDecoder obj's underlying member method code with example usage: obj.forward(input_tokens, encoder_out, incremental_state, possible_translation_tokens) and returns: all_logits,  all_attn_scores,  None, utils,  utils,  None