class_docstr: Rewrite fairseq.modules.TransformerDecoderLayer to avoid forwarding
  model multiple times and be compatible with checkpoint_activations.
  
  The input is expected to be a list of tensors from different channels,
  each is forwarded to the same model (shared attention weights).
  
  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: ["Rewrite","fairseq.modules.TransformerDecoderLayer","to","avoid","forwarding","model","multiple","times","and","be","compatible","with","checkpoint_activations",".","The","input","is","expected","to","be","a","list","of","tensors","from","different","channels",",","each","is","forwarded","to","the","same","model","(","shared","attention","weights",")",".","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 build_encoder_attention(self, embed_dim, args):
      return MultiheadAttention(
          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,
          q_noise=self.quant_noise,
          qn_block_size=self.quant_noise_block_size,
      )
  
imports: from typing import Dict, List, Tuple, Optional
  import torch
  import torch.nn
  from fairseq import utils
  from fairseq.modules import LayerNorm, MultiheadAttention
  from fairseq.modules.fairseq_dropout import FairseqDropout
  from fairseq.modules.quant_noise import quant_noise
  from torch import Tensor
label_desc: Use image node_id 5 for calling the StandardTransformerDecoderLayer obj's underlying member method code with example usage: obj.build_encoder_attention(embed_dim, args) and returns: MultiheadAttention