class_docstr: Implements functionality common to all transformer decoder variants. Not intended to
  be instantiated directly.
  
  For a (Vaswani 2017) style encoder-decoder transformer, use ``TransformerDecoder``. For a GPT-style decoder-only transformer, use ``TransformerDecoderOnly``.
  
  Subclasses are required to implement ``forward``. In your ``forward`` implementation, you can call ``forward_embedding`` to get embeddings for the input tokens and ``forward_layers`` to pass those embeddings sequentially through each layer.
  
  Subclasses can optionally override ``__init__``, ``build_layer``, and
  ``build_layers`` to customize subcomponents. In particular, ``build_layer`` can be used to instantiate heterogeneous layers (e.g. every other layer being a different type).
code: def __init__(
      self,
      opt: Opt,
      embedding: nn.Embedding,
      dictionary: DictionaryAgent,
      n_positions: Optional[int] = None,
      **kwargs,
  ):
      super().__init__()
      self.opt = opt
      self.pad_idx = dictionary[dictionary.null_token]
      self.start_idx = dictionary[dictionary.start_token]
      self.end_idx = dictionary[dictionary.end_token]
  
      self.embedding_size = opt["embedding_size"]
      self.ffn_size = opt["ffn_size"]
      self.n_layers = (
          opt["n_decoder_layers"]
          if opt.get("n_decoder_layers", -1) > 0
          else opt["n_layers"]
      )
      self.n_heads = opt["n_heads"]
      self.dim = self.embedding_size
      self.activation = opt.get("activation", "relu")
      self.variant = opt.get("variant", "aiayn")
  
      self.embeddings_scale = opt.get("embeddings_scale", True)
      self.dropout = nn.Dropout(p=opt.get("dropout", 0.0))  # --dropout
  
      self.n_positions = default(
          n_positions, get_n_positions_from_options(opt)
      )
      self.out_dim = self.embedding_size
      assert (
          self.embedding_size % self.n_heads == 0
      ), "Transformer embedding size must be a multiple of n_heads"
  
      self.embeddings = embedding
  
      if (
          self.variant == "xlm"
          or self.variant == "prelayernorm"
          or self.variant == "bart"
      ):
          self.norm_embeddings = torch.nn.LayerNorm(
              self.dim, eps=LAYER_NORM_EPS
          )
          if self.variant == "xlm":
              warn_once(
                  "DEPRECATED: XLM should only be used for backwards compatibility, "
                  "as it involves a less-stable layernorm operation."
              )
      elif self.variant == "aiayn":
          pass
      else:
          raise ValueError(
              "Can't handle --variant {}".format(self.variant)
          )
  
      # create the positional embeddings
      self.position_embeddings = nn.Embedding(
          self.n_positions, self.embedding_size
      )
      if not opt.get("learn_positional_embeddings", False):
          create_position_codes(
              self.n_positions,
              self.embedding_size,
              out=self.position_embeddings.weight,
          )
      else:
          nn.init.normal_(
              self.position_embeddings.weight,
              0,
              self.embedding_size**-0.5,
          )
  
      # build the model
      self.layers = self.build_layers()
  
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 1 to create a new BaseTransformerDecoder object from inherited base classes: nn, ABC with example: obj = BaseTransformerDecoder(opt, embedding, dictionary, n_positions)