class_docstr: Transformer model from `"Attention Is All You Need" (Vaswani, et al, 2017)
  <https://arxiv.org/abs/1706.03762>`_.
class_docstr_tok: ["Transformer","model","from","`","``","Attention","Is","All","You","Need","''","(","Vaswani",",","et","al",",","2017",")","<","https",":","\/\/arxiv.org\/abs\/1706.03762",">","`","_","."]
docstr: Add model-specific arguments to the parser.
code: def add_args(parser):
      """Add model-specific arguments to the parser."""
      parser.add_argument(
          "--dropout",
          type=float,
          metavar="D",
          help="dropout probability",
      )
      parser.add_argument(
          "--attention-dropout",
          type=float,
          metavar="D",
          help="dropout probability for attention weights",
      )
      parser.add_argument(
          "--relu-dropout",
          type=float,
          metavar="D",
          help="dropout probability after ReLU in FFN",
      )
      parser.add_argument(
          "--encoder-embed-path",
          type=str,
          metavar="STR",
          help="path to pre-trained encoder embedding",
      )
      parser.add_argument(
          "--encoder-embed-dim",
          type=int,
          metavar="N",
          help="encoder embedding dimension",
      )
      parser.add_argument(
          "--encoder-ffn-embed-dim",
          type=int,
          metavar="N",
          help="encoder embedding dimension for FFN",
      )
      parser.add_argument(
          "--encoder-layers",
          type=int,
          metavar="N",
          help="num encoder layers",
      )
      parser.add_argument(
          "--encoder-attention-heads",
          type=int,
          metavar="N",
          help="num encoder attention heads",
      )
      parser.add_argument(
          "--encoder-normalize-before",
          action="store_true",
          help="apply layernorm before each encoder block",
      )
      parser.add_argument(
          "--encoder-learned-pos",
          action="store_true",
          help="use learned positional embeddings in the encoder",
      )
      parser.add_argument(
          "--decoder-embed-path",
          type=str,
          metavar="STR",
          help="path to pre-trained decoder embedding",
      )
      parser.add_argument(
          "--decoder-embed-dim",
          type=int,
          metavar="N",
          help="decoder embedding dimension",
      )
      parser.add_argument(
          "--decoder-ffn-embed-dim",
          type=int,
          metavar="N",
          help="decoder embedding dimension for FFN",
      )
      parser.add_argument(
          "--decoder-layers",
          type=int,
          metavar="N",
          help="num decoder layers",
      )
      parser.add_argument(
          "--decoder-attention-heads",
          type=int,
          metavar="N",
          help="num decoder attention heads",
      )
      parser.add_argument(
          "--decoder-learned-pos",
          action="store_true",
          help="use learned positional embeddings in the decoder",
      )
      parser.add_argument(
          "--decoder-normalize-before",
          action="store_true",
          help="apply layernorm before each decoder block",
      )
      parser.add_argument(
          "--share-decoder-input-output-embed",
          action="store_true",
          help="share decoder input and output embeddings",
      )
      parser.add_argument(
          "--share-all-embeddings",
          action="store_true",
          help="share encoder, decoder and output embeddings"
          " (requires shared dictionary and embed dim)",
      )
      parser.add_argument(
          "--adaptive-softmax-cutoff",
          metavar="EXPR",
          help="comma separated list of adaptive softmax cutoff points. "
          "Must be used with adaptive_loss criterion",
      ),
      parser.add_argument(
          "--adaptive-softmax-dropout",
          type=float,
          metavar="D",
          help="sets adaptive softmax dropout for the tail projections",
      )
      # AAN only
      parser.add_argument(
          "--decoder-attn-window-size",
          default=0,
          type=int,
          help="attention window size of the decoder (default: 0 (unlimited))",
      )
      parser.add_argument(
          "--no-decoder-aan-ffn",
          default=False,
          action="store_true",
          help="no FFN in the AAN block",
      )
      parser.add_argument(
          "--no-decoder-aan-gating",
          default=False,
          action="store_true",
          help="no Gating in the AAN block",
      )
      parser.add_argument(
          "--decoder-aan-ffn-use-embed-dim",
          default=False,
          action="store_true",
          help="""using decoder_embed_dim instead of decoder_ffn_embed_dim \
              as the hidden size of the FFN in AAN""",
      )
      parser.add_argument(
          "--decoder-aan-more-dropouts",
          type=lambda x: set(x.split(",")),
          help="""places to add more dropout in AAN, accepting multiple values in \
              [residual/after_avg/after_aan] separated by commas""",
      )
      parser.add_argument(
          "--decoder-out-embed-dim",
          default=None,
          type=int,
          metavar="N",
          help="decoder output embedding dimension (bottleneck layer before"
          "output layer if specified.)",
      )
  
      # Args for vocab reduction
      vocab_reduction.add_args(parser)
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import options, utils
  from fairseq.models import FairseqEncoderDecoderModel, FairseqIncrementalDecoder, register_model, register_model_architecture, transformer
  from fairseq.modules import AdaptiveSoftmax, LearnedPositionalEmbedding, MultiheadAttention, SinusoidalPositionalEmbedding
  from pytorch_translate import transformer, vocab_reduction
  from pytorch_translate.average_attention import AverageAttention, AverageWindowAttention
  from pytorch_translate.utils import torch_find
label_desc: Use image node_id 2 for calling the TransformerAANModel obj's underlying member method code with example usage: obj.add_args(parser) without return types