code: def __init__(
      self,
      num_layers=6,
      recurrent=False,
      units=512,
      mem_units=None,
      hidden_size=2048,
      use_qkv_bias=True,
      num_heads=8,
      max_shift=None,
      activation_dropout=0.0,
      dropout=0.1,
      attention_dropout=0.1,
      gated_proj: bool = False,
      layer_norm_eps=1e-5,
      data_norm=False,
      pre_norm=False,
      activation="relu",
      layout="NT",
  ):
      super().__init__()
      self._units = units
      self._mem_units = mem_units
      self.num_layers = num_layers
      self.recurrent = recurrent
      self.max_shift = max_shift
      self._data_norm = data_norm
      self._pre_norm = pre_norm
      self._layout = layout
      assert layout in ["TN", "NT"], (
          "Invalid layout received = {}. "
          'Only "TN" and "NT" are accepted!'.format(layout)
      )
      self.dropout_layer = nn.Dropout(dropout)
      if self._data_norm:
          self.ln_data = nn.LayerNorm(units, eps=layer_norm_eps)
      if self._pre_norm:
          self.ln_final = nn.LayerNorm(units, eps=layer_norm_eps)
      # Construct the intermediate layers
      self.layers = nn.ModuleList()
      real_num_layers = 1 if recurrent else num_layers
      for i in range(real_num_layers):
          self.layers.append(
              TransformerDecoderLayer(
                  units=units,
                  mem_units=mem_units,
                  hidden_size=hidden_size,
                  num_heads=num_heads,
                  activation_dropout=activation_dropout,
                  use_qkv_bias=use_qkv_bias,
                  dropout=dropout,
                  gated_proj=gated_proj,
                  attention_dropout=attention_dropout,
                  layer_norm_eps=layer_norm_eps,
                  activation=activation,
                  pre_norm=pre_norm,
                  layout=layout,
              )
          )
  
imports: from typing import Union, Optional, List
  from torch import nn
  import torch
  from ..layers import PositionwiseFFN
  from ..attention_cell import MultiHeadAttentionCell, gen_mem_attn_mask, gen_self_attn_mask
  from ..utils import to_torch_dtype
label_desc: Use image node_id 1 to create a new TransformerDecoder object from inherited base classes: nn with example: obj = TransformerDecoder(num_layers, recurrent, units, mem_units, hidden_size, use_qkv_bias, num_heads, max_shift, activation_dropout, dropout, attention_dropout, gated_proj, layer_norm_eps, data_norm, pre_norm, activation, layout)