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).
docstr: Embed tokens prior to feeding into transformer.
  
  :param LongTensor[batch, seqlen] input:
      The target input IDs
  :param LongTensor[batch, seqlen] positions:
      Positions for input IDs. If None, computes defaults.
  :param LongTensor[batch, seqlen] segments:
      Segment IDs for extra embedding features. If None, not used.
  
  :return (tensor, mask):
      embedded input and mask
docstr_tok: ["Embed","tokens","prior","to","feeding","into","transformer",".",":","param","LongTensor","[","batch",",","seqlen","]","input",":","The","target","input","IDs",":","param","LongTensor","[","batch",",","seqlen","]","positions",":","Positions","for","input","IDs",".","If","None",",","computes","defaults",".",":","param","LongTensor","[","batch",",","seqlen","]","segments",":","Segment","IDs","for","extra","embedding","features",".","If","None",",","not","used",".",":","return","(","tensor",",","mask",")",":","embedded","input","and","mask"]
code: def forward_embedding(
      self,
      input: torch.LongTensor,
      positions: Optional[torch.LongTensor] = None,
      segments: Optional[torch.LongTensor] = None,
      **kwargs,
  ):
      """
      Embed tokens prior to feeding into transformer.
  
      :param LongTensor[batch, seqlen] input:
          The target input IDs
      :param LongTensor[batch, seqlen] positions:
          Positions for input IDs. If None, computes defaults.
      :param LongTensor[batch, seqlen] segments:
          Segment IDs for extra embedding features. If None, not used.
  
      :return (tensor, mask):
          embedded input and mask
      """
      tensor = self.embeddings(input)
      if self.embeddings_scale:
          tensor = tensor * np.sqrt(self.dim)
      if self.variant == "xlm":
          tensor = self.norm_embeddings(tensor)
      if positions.max().item() > self.n_positions:
          warn_once(
              "You are inputting a sequence of {x} length, but only have "
              "--n-positions {y}. Set --truncate or increase --n-positions".format(
                  x=positions.max().item(), y=self.n_positions
              )
          )
      tensor = tensor + self.position_embeddings(positions).expand_as(
          tensor
      )
      if self.variant == "bart":
          tensor = self.norm_embeddings(tensor)
  
      return tensor
  
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 5 for calling the BaseTransformerDecoder obj's underlying member method code with example usage: obj.forward_embedding(input, positions, segments) and returns: tensor