class_docstr: Implements a single Transformer encoder layer.
class_docstr_tok: ["Implements","a","single","Transformer","encoder","layer","."]
code: def __init__(
      self,
      opt: Opt,
      n_heads: int = None,
      embedding_size: int = None,
      ffn_size: int = None,
      attention_dropout: float = 0.0,
      relu_dropout: float = 0.0,
      dropout: float = 0.0,
      activation: str = "relu",
      variant: Optional[str] = None,
      **kwargs,
  ):
      super().__init__()
  
      n_heads = default(n_heads, opt["n_heads"])
      embedding_size = default(embedding_size, opt["embedding_size"])
      ffn_size = default(ffn_size, opt["ffn_size"])
  
      self.opt = opt
      self.dim = embedding_size
      self.ffn_dim = ffn_size
      self.activation = activation
      self.variant = variant
      self.attention = self.swappables.self_attention(  # type: ignore
          opt=self.opt,
          n_heads=n_heads,
          dim=embedding_size,
          dropout=attention_dropout,  # --attention-dropout
      )
      self.norm1 = torch.nn.LayerNorm(
          embedding_size, eps=LAYER_NORM_EPS
      )
      self.ffn = self.swappables.feedforward(  # type: ignore
          opt=self.opt,
          dim=embedding_size,
          dim_hidden=ffn_size,
          relu_dropout=relu_dropout,
          activation=self.activation,
      )
      self.norm2 = torch.nn.LayerNorm(
          embedding_size, eps=LAYER_NORM_EPS
      )
      self.dropout = nn.Dropout(p=dropout)
  
imports: from __future__ import annotations
  from typing import Tuple, Optional, Union
  import numpy
  import torch
  import torch.nn
  from parlai.agents.transformer.modules import create_position_codes, get_n_positions_from_options, LAYER_NORM_EPS, MultiHeadAttention, TransformerFFN
  from parlai.agents.transformer.modules.modular import swappable
  from parlai.core.opt import Opt
  from parlai.core.params import default
  from parlai.utils.misc import warn_once
  from parlai.utils.torch import PipelineHelper
  from parlai.utils.fsdp import fsdp_wrap
  from parlai.nn.checkpoint import checkpoint_wrapper
label_desc: Use image node_id 1 to create a new TransformerEncoderLayer object from inherited base classes: nn with example: obj = TransformerEncoderLayer(opt, n_heads, embedding_size, ffn_size, attention_dropout, relu_dropout, dropout, activation, variant)