code: def __init__(
      self,
      d_model,
      attn=None,
      nhead=8,
      dim_feedforward=2048,
      dropout=0.1,
      activation="relu",
      attn_dropout=None,
      act_dropout=None,
      normalize_before=False,
  ):
      super(TransformerEncoderLayer, self).__init__()
      attn_dropout = dropout if attn_dropout is None else attn_dropout
      act_dropout = dropout if act_dropout is None else act_dropout
      self.normalize_before = normalize_before
      self.embed_dims = d_model
  
      if attn is None:
          self.self_attn = MultiHeadAttention(
              d_model, nhead, attn_dropout
          )
      else:
          self.self_attn = attn
      # Implementation of Feedforward model
      self.linear1 = nn.Linear(d_model, dim_feedforward)
      self.dropout = nn.Dropout(act_dropout, mode="upscale_in_train")
      self.linear2 = nn.Linear(dim_feedforward, d_model)
  
      self.norm1 = nn.LayerNorm(d_model)
      self.norm2 = nn.LayerNorm(d_model)
      self.dropout1 = nn.Dropout(dropout, mode="upscale_in_train")
      self.dropout2 = nn.Dropout(dropout, mode="upscale_in_train")
      self.activation = getattr(F, activation)
      self._reset_parameters()
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle import ParamAttr
  from ppdet.core.workspace import register
  from ..layers import MultiHeadAttention, _convert_attention_mask
  from .utils import _get_clones
  from ..initializer import linear_init_, normal_, constant_, xavier_uniform_
label_desc: Use image node_id 1 to create a new TransformerEncoderLayer object from inherited base classes: nn with example: obj = TransformerEncoderLayer(d_model, attn, nhead, dim_feedforward, dropout, activation, attn_dropout, act_dropout, normalize_before)