class_docstr: Decoder layer block.
  
  In the original paper each operation (multi-head attention, encoder
  attention or FFN) is postprocessed with: `dropout -> add residual ->
  layernorm`. In the tensor2tensor code they suggest that learning is more
  robust when preprocessing each layer with layernorm and postprocessing with:
  `dropout -> add residual`. We default to the approach in the paper, but the
  tensor2tensor approach can be enabled by setting
  *args.decoder_normalize_before* to ``True``.
  
  Args:
      args (argparse.Namespace): parsed command-line arguments
      no_encoder_attn (bool, optional): whether to attend to encoder outputs
          (default: False).
class_docstr_tok: ["Decoder","layer","block",".","In","the","original","paper","each","operation","(","multi-head","attention",",","encoder","attention","or","FFN",")","is","postprocessed","with",":","`","dropout","-",">","add","residual","-",">","layernorm","`",".","In","the","tensor2tensor","code","they","suggest","that","learning","is","more","robust","when","preprocessing","each","layer","with","layernorm","and","postprocessing","with",":","`","dropout","-",">","add","residual","`",".","We","default","to","the","approach","in","the","paper",",","but","the","tensor2tensor","approach","can","be","enabled","by","setting","*","args.decoder_normalize_before","*","to","``","True","``",".","Args",":","args","(","argparse.Namespace",")",":","parsed","command-line","arguments","no_encoder_attn","(","bool",",","optional",")",":","whether","to","attend","to","encoder","outputs","(","default",":","False",")","."]
code: def __init__(
      self,
      args,
      no_encoder_attn=False,
      add_bias_kv=False,
      add_zero_attn=False,
  ):
      super().__init__()
      self.embed_dim = args.decoder_embed_dim
      self.self_attn = MultiheadAttention(
          embed_dim=self.embed_dim,
          num_heads=args.decoder_attention_heads,
          dropout=args.attention_dropout,
          add_bias_kv=add_bias_kv,
          add_zero_attn=add_zero_attn,
          self_attention=True,
      )
      self.dropout = args.dropout
      self.activation_fn = utils.get_activation_fn(
          activation=getattr(args, "activation_fn", "relu")
      )
      self.activation_dropout = getattr(args, "activation_dropout", 0)
      if self.activation_dropout == 0:
          # for backwards compatibility with models that use args.relu_dropout
          self.activation_dropout = getattr(args, "relu_dropout", 0)
      self.normalize_before = args.decoder_normalize_before
  
      # use layerNorm rather than FusedLayerNorm for exporting.
      # char_inputs can be used to determint this.
      # TODO  remove this once we update apex with the fix
      export = getattr(args, "char_inputs", False)
      self.self_attn_layer_norm = LayerNorm(
          self.embed_dim, export=export
      )
  
      if no_encoder_attn:
          self.encoder_attn = None
          self.encoder_attn_layer_norm = None
      else:
          self.encoder_attn = MultiheadAttention(
              self.embed_dim,
              args.decoder_attention_heads,
              kdim=getattr(args, "encoder_embed_dim", None),
              vdim=getattr(args, "encoder_embed_dim", None),
              dropout=args.attention_dropout,
              encoder_decoder_attention=True,
          )
          self.encoder_attn_layer_norm = LayerNorm(
              self.embed_dim, export=export
          )
  
      self.fc1 = Linear(self.embed_dim, args.decoder_ffn_embed_dim)
      self.fc2 = Linear(args.decoder_ffn_embed_dim, self.embed_dim)
  
      self.final_layer_norm = LayerNorm(self.embed_dim, export=export)
      self.need_attn = True
  
      self.onnx_trace = False
  
imports: import math
  from collections import namedtuple
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import options, utils
  from fairseq.modules import AdaptiveSoftmax, LayerNorm, MultiheadAttention, PositionalEmbedding
label_desc: Use image node_id 1 to create a new TransformerDecoderLayer object from inherited base classes: nn with example: obj = TransformerDecoderLayer(args, no_encoder_attn, add_bias_kv, add_zero_attn)