class_docstr: Implements a Transformer Encoder Layer used in BERT/XLM style pre-trained
  models.
docstr: LayerNorm is applied either before or after the self-attention/ffn
  modules similar to the original Transformer implementation.
docstr_tok: ["LayerNorm","is","applied","either","before","or","after","the","self-attention\/ffn","modules","similar","to","the","original","Transformer","implementation","."]
code: def forward(
      self,
      x: torch.Tensor,
      self_attn_mask: Optional[torch.Tensor] = None,
      self_attn_padding_mask: Optional[torch.Tensor] = None,
  ):
      """
      LayerNorm is applied either before or after the self-attention/ffn
      modules similar to the original Transformer implementation.
      """
      residual = x
      x, attn = self.self_attn(
          query=x,
          key=x,
          value=x,
          key_padding_mask=self_attn_padding_mask,
          need_weights=False,
          attn_mask=self_attn_mask,
      )
      x = self.dropout_module(x)
      x = residual + x
      x = self.self_attn_layer_norm(x)
  
      residual = x
      x = self.activation_fn(self.fc1(x))
      x = self.activation_dropout_module(x)
      x = self.fc2(x)
      x = self.dropout_module(x)
      x = residual + x
      x = self.final_layer_norm(x)
      return x, attn
  
file_path: fairseq/fairseq/modules/transformer_sentence_encoder_layer.py
imports: from typing import Callable, 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
label_desc: Use image node_id 5 for calling the TransformerSentenceEncoderLayer obj's underlying member method code with example usage: obj.forward(x, _attn_mask, _attn_padding_mask) and returns: x,  attn