class_docstr: Based on https://arxiv.org/abs/1805.00631
class_docstr_tok: ["Based","on","https",":","\/\/arxiv.org\/abs\/1805.00631"]
code: def __init__(self, args):
      super().__init__()
      self.embed_dim = args.decoder_embed_dim
      self.cross_self_attention = getattr(
          args, "cross_self_attention", False
      )
  
      self.avg_attn = AverageAttention(
          self.embed_dim, dropout=args.attention_dropout
      )
  
      # differently than original paper, we use a single gate
      self.aan_gating_fc = fairseq_transformer.Linear(
          self.embed_dim * 2, self.embed_dim
      )
  
      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.avg_attn_layer_norm = LayerNorm(
          self.embed_dim, export=export
      )
  
      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 = fairseq_transformer.Linear(
          self.embed_dim, args.decoder_ffn_embed_dim
      )
      self.fc2 = fairseq_transformer.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
  import random
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import options, utils
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, FairseqIncrementalDecoder, register_model, register_model_architecture, transformer
  from fairseq.modules import AdaptiveSoftmax, LayerNorm, MultiheadAttention, SinusoidalPositionalEmbedding
  from pytorch_translate import utils, vocab_reduction
  from pytorch_translate.average_attention import AverageAttention
  from pytorch_translate.common_layers import TransformerEmbedding, TransformerEncoderGivenEmbeddings, TransformerTokenEmbedding, VariableTracker
  from pytorch_translate.semi_supervised import SemiSupervisedModel
  from pytorch_translate.utils import torch_find
label_desc: Use image node_id 1 to create a new AANDecoderLayer object from inherited base classes: nn with example: obj = AANDecoderLayer(args)