class_docstr: Implements one encoder layer in DETR transformer.
  
  Args:
      embed_dims (int): The feature dimension. Same as `FFN`.
      num_heads (int): Parallel attention heads.
      feedforward_channels (int): The hidden dimension for FFNs.
      dropout (float): Probability of an element to be zeroed. Default 0.0.
      order (tuple[str]): The order for encoder layer. Valid examples are
          ('selfattn', 'norm', 'ffn', 'norm') and ('norm', 'selfattn',
          'norm', 'ffn'). Default ('selfattn', 'norm', 'ffn', 'norm').
      act_cfg (dict): The activation config for FFNs. Defalut ReLU.
      norm_cfg (dict): Config dict for normalization layer. Default
          layer normalization.
      num_fcs (int): The number of fully-connected layers for FFNs.
          Default 2.
class_docstr_tok: ["Implements","one","encoder","layer","in","DETR","transformer",".","Args",":","embed_dims","(","int",")",":","The","feature","dimension",".","Same","as","`","FFN","`",".","num_heads","(","int",")",":","Parallel","attention","heads",".","feedforward_channels","(","int",")",":","The","hidden","dimension","for","FFNs",".","dropout","(","float",")",":","Probability","of","an","element","to","be","zeroed",".","Default","0.0.","order","(","tuple","[","str","]",")",":","The","order","for","encoder","layer",".","Valid","examples","are","(","'selfattn","'",",","'norm","'",",","'ffn","'",",","'norm","'",")","and","(","'norm","'",",","'selfattn","'",",","'norm","'",",","'ffn","'",")",".","Default","(","'selfattn","'",",","'norm","'",",","'ffn","'",",","'norm","'",")",".","act_cfg","(","dict",")",":","The","activation","config","for","FFNs",".","Defalut","ReLU",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Default","layer","normalization",".","num_fcs","(","int",")",":","The","number","of","fully-connected","layers","for","FFNs",".","Default","2","."]
docstr: Forward function for `TransformerEncoderLayer`.
  
  Args:
      x (Tensor): The input query with shape [num_key, bs,
          embed_dims]. Same in `MultiheadAttention.forward`.
      pos (Tensor): The positional encoding for query. Default None.
          Same as `query_pos` in `MultiheadAttention.forward`.
      attn_mask (Tensor): ByteTensor mask with shape [num_key,
          num_key]. Same in `MultiheadAttention.forward`. Default None.
      key_padding_mask (Tensor): ByteTensor with shape [bs, num_key].
          Same in `MultiheadAttention.forward`. Default None.
  
  Returns:
      Tensor: forwarded results with shape [num_key, bs, embed_dims].
docstr_tok: ["Forward","function","for","`","TransformerEncoderLayer","`",".","Args",":","x","(","Tensor",")",":","The","input","query","with","shape","[","num_key",",","bs",",","embed_dims","]",".","Same","in","`","MultiheadAttention.forward","`",".","pos","(","Tensor",")",":","The","positional","encoding","for","query",".","Default","None",".","Same","as","`","query_pos","`","in","`","MultiheadAttention.forward","`",".","attn_mask","(","Tensor",")",":","ByteTensor","mask","with","shape","[","num_key",",","num_key","]",".","Same","in","`","MultiheadAttention.forward","`",".","Default","None",".","key_padding_mask","(","Tensor",")",":","ByteTensor","with","shape","[","bs",",","num_key","]",".","Same","in","`","MultiheadAttention.forward","`",".","Default","None",".","Returns",":","Tensor",":","forwarded","results","with","shape","[","num_key",",","bs",",","embed_dims","]","."]
code: def forward(self, x, pos=None, attn_mask=None, key_padding_mask=None):
      """Forward function for `TransformerEncoderLayer`.
  
      Args:
          x (Tensor): The input query with shape [num_key, bs,
              embed_dims]. Same in `MultiheadAttention.forward`.
          pos (Tensor): The positional encoding for query. Default None.
              Same as `query_pos` in `MultiheadAttention.forward`.
          attn_mask (Tensor): ByteTensor mask with shape [num_key,
              num_key]. Same in `MultiheadAttention.forward`. Default None.
          key_padding_mask (Tensor): ByteTensor with shape [bs, num_key].
              Same in `MultiheadAttention.forward`. Default None.
  
      Returns:
          Tensor: forwarded results with shape [num_key, bs, embed_dims].
      """
      norm_cnt = 0
      inp_residual = x
      for layer in self.order:
          if layer == "selfattn":
              # self attention
              query = key = value = x
              x = self.self_attn(
                  query,
                  key,
                  value,
                  inp_residual if self.pre_norm else None,
                  query_pos=pos,
                  key_pos=pos,
                  attn_mask=attn_mask,
                  key_padding_mask=key_padding_mask,
              )
              inp_residual = x
          elif layer == "norm":
              x = self.norms[norm_cnt](x)
              norm_cnt += 1
          elif layer == "ffn":
              x = self.ffn(x, inp_residual if self.pre_norm else None)
      return x
  
imports: import torch
  import torch.nn
  from mmcv.cnn import Linear, build_activation_layer, build_norm_layer, xavier_init
  from .builder import TRANSFORMER
label_desc: Use image node_id 2 for calling the TransformerEncoderLayer obj's underlying member method code with example usage: obj.forward(x, pos, attn_mask, key_padding_mask) and returns: x