class_docstr: Transformer Decoder module for decoder-only architecture.
  
  Intended to be used with a PassThroughEncoder, which will pass the context to this decoder unchanged.
  
  For documentation on parameters that are taken directly from opt,
  see parlai/agents/transformer/transformer.py
docstr: Forward pass.
  
  :param LongTensor[batch,seqlen] input:
      The decoder inputs (partial or full decoded token IDs).
  :param encoder_state:
      Output from the encoder module forward pass.
  :param incr_state:
      The incremental state: a dictionary whose keys index the layers and whose
      values contain the incremental state for each layer.
docstr_tok: ["Forward","pass",".",":","param","LongTensor","[","batch",",","seqlen","]","input",":","The","decoder","inputs","(","partial","or","full","decoded","token","IDs",")",".",":","param","encoder_state",":","Output","from","the","encoder","module","forward","pass",".",":","param","incr_state",":","The","incremental","state",":","a","dictionary","whose","keys","index","the","layers","and","whose","values","contain","the","incremental","state","for","each","layer","."]
code: def forward(
      self,
      input: torch.Tensor,
      encoder_state: Tuple[torch.Tensor, ...],
      incr_state: Optional[DecoderIncrState] = None,
      **kwargs,
  ) -> Tuple[torch.Tensor, DecoderIncrState]:
      """
      Forward pass.
  
      :param LongTensor[batch,seqlen] input:
          The decoder inputs (partial or full decoded token IDs).
      :param encoder_state:
          Output from the encoder module forward pass.
      :param incr_state:
          The incremental state: a dictionary whose keys index the layers and whose
          values contain the incremental state for each layer.
      """
      context, *_ = encoder_state
  
      is_incr_decoding = incr_state is not None
  
      full_sequence = torch.cat([context, input], dim=-1)
      attention_mask = full_sequence != self.pad_idx
      position_ids = (
          attention_mask.cumsum(dim=-1, dtype=torch.int64) - 1
      ).clamp_(min=0)
      if not is_incr_decoding:
          # forced decoding: concatenate the context with the labels
          model_input = full_sequence
      else:
          # generating with continuation: get the last token input
          model_input = input[:, -1:]
          position_ids = position_ids[:, -1:]
  
      tensor = self.forward_embedding(
          model_input, position_ids, **kwargs
      )
  
      tensor = self.dropout(tensor)  # --dropout
  
      if incr_state is None:
          incr_state = {}
      tensor, new_incr_state = self.forward_layers(
          tensor, incr_state=incr_state, **kwargs
      )
  
      if self.variant == "prelayernorm":
          tensor = self.norm_embeddings(tensor)
  
      if not is_incr_decoding:
          # In case context has been prepended to the input, remove it from output.
          # Start token is prepended to input in TorchGeneratorModel.decode_forced,
          # so model_input is actually `context + [start_tkn] + label[:-1]`.
          # Since model predicts next token at each timestep, prediction starts at
          # the position where start_tkn was.
          tensor = tensor[:, context.size(1) :, :]
  
      return tensor, new_incr_state
  
imports: from __future__ import annotations
  from abc import ABC
  from typing import Dict, Optional, Tuple
  import numpy
  import torch
  import torch.nn
  from parlai.agents.transformer.modules import create_position_codes, get_n_positions_from_options, LAYER_NORM_EPS, MultiHeadAttention, TransformerFFN
  from parlai.agents.transformer.modules.modular import swappable
  from parlai.core.opt import Opt
  from parlai.core.params import default
  from parlai.core.torch_agent import DictionaryAgent
  from parlai.utils.misc import warn_once
  from parlai.utils.torch import PipelineHelper
  from parlai.utils.fsdp import fsdp_wrap
  from parlai.nn.checkpoint import checkpoint_wrapper
label_desc: Use image node_id 2 for calling the TransformerDecoderOnly obj's underlying member method code with example usage: obj.forward(input, encoder_state, incr_state) and returns: tensor,  new_incr_state