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: Instantiates all layers. Called only once during __init__.
  
  Additional setup common to all layers, such as checkpoint wrapping, can be done
  here.
docstr_tok: ["Instantiates","all","layers",".","Called","only","once","during","__init__",".","Additional","setup","common","to","all","layers",",","such","as","checkpoint","wrapping",",","can","be","done","here","."]
code: def build_layers(self) -> nn.ModuleList:
      """
      Instantiates all layers. Called only once during __init__.
  
      Additional setup common to all layers, such as checkpoint wrapping, can be done
      here.
      """
      layers = nn.ModuleList()
      for i in range(self.n_layers):
          layer = self.build_layer(index=i)
          if self.opt.get("checkpoint_activations"):
              layer = checkpoint_wrapper(layer)
          layers.append(fsdp_wrap(layer))  # type: ignore
      return 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 2 for calling the BaseTransformerDecoder obj's underlying member method code with example usage: obj.build_layers() and returns: layers