class_docstr: Implements one encoder layer in PVT.
  
  Args:
      embed_dims (int): The feature dimension.
      num_heads (int): Parallel attention heads.
      feedforward_channels (int): The hidden dimension for FFNs.
      drop_rate (float): Probability of an element to be zeroed.
          after the feed forward layer. Default: 0.0.
      attn_drop_rate (float): The drop out rate for attention layer.
          Default: 0.0.
      drop_path_rate (float): stochastic depth rate. Default: 0.0.
      qkv_bias (bool): enable bias for qkv if True.
          Default: True.
      act_cfg (dict): The activation config for FFNs.
          Default: dict(type='GELU').
      norm_cfg (dict): Config dict for normalization layer.
          Default: dict(type='LN').
      sr_ratio (int): The ratio of spatial reduction of Spatial Reduction
          Attention of PVT. Default: 1.
      use_conv_ffn (bool): If True, use Convolutional FFN to replace FFN.
          Default: False.
      init_cfg (dict, optional): Initialization config dict.
          Default: None.
class_docstr_tok: ["Implements","one","encoder","layer","in","PVT",".","Args",":","embed_dims","(","int",")",":","The","feature","dimension",".","num_heads","(","int",")",":","Parallel","attention","heads",".","feedforward_channels","(","int",")",":","The","hidden","dimension","for","FFNs",".","drop_rate","(","float",")",":","Probability","of","an","element","to","be","zeroed",".","after","the","feed","forward","layer",".","Default",":","0.0.","attn_drop_rate","(","float",")",":","The","drop","out","rate","for","attention","layer",".","Default",":","0.0.","drop_path_rate","(","float",")",":","stochastic","depth","rate",".","Default",":","0.0.","qkv_bias","(","bool",")",":","enable","bias","for","qkv","if","True",".","Default",":","True",".","act_cfg","(","dict",")",":","The","activation","config","for","FFNs",".","Default",":","dict","(","type='GELU","'",")",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Default",":","dict","(","type='LN","'",")",".","sr_ratio","(","int",")",":","The","ratio","of","spatial","reduction","of","Spatial","Reduction","Attention","of","PVT",".","Default",":","1.","use_conv_ffn","(","bool",")",":","If","True",",","use","Convolutional","FFN","to","replace","FFN",".","Default",":","False",".","init_cfg","(","dict",",","optional",")",":","Initialization","config","dict",".","Default",":","None","."]
code: def __init__(
      self,
      embed_dims,
      num_heads,
      feedforward_channels,
      drop_rate=0.0,
      attn_drop_rate=0.0,
      drop_path_rate=0.0,
      qkv_bias=True,
      act_cfg=dict(type="GELU"),
      norm_cfg=dict(type="LN"),
      sr_ratio=1,
      use_conv_ffn=False,
      init_cfg=None,
  ):
      super(PVTEncoderLayer, self).__init__(init_cfg=init_cfg)
  
      # The ret[0] of build_norm_layer is norm name.
      self.norm1 = build_norm_layer(norm_cfg, embed_dims)[1]
  
      self.attn = SpatialReductionAttention(
          embed_dims=embed_dims,
          num_heads=num_heads,
          attn_drop=attn_drop_rate,
          proj_drop=drop_rate,
          dropout_layer=dict(type="DropPath", drop_prob=drop_path_rate),
          qkv_bias=qkv_bias,
          norm_cfg=norm_cfg,
          sr_ratio=sr_ratio,
      )
  
      # The ret[0] of build_norm_layer is norm name.
      self.norm2 = build_norm_layer(norm_cfg, embed_dims)[1]
  
      self.ffn = MixFFN(
          embed_dims=embed_dims,
          feedforward_channels=feedforward_channels,
          ffn_drop=drop_rate,
          dropout_layer=dict(type="DropPath", drop_prob=drop_path_rate),
          use_conv=use_conv_ffn,
          act_cfg=act_cfg,
      )
  
imports: import math
  import warnings
  from collections import OrderedDict
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d, build_activation_layer, build_norm_layer
  from mmcv.cnn.bricks.drop import build_dropout
  from mmcv.cnn.bricks.transformer import MultiheadAttention
  from mmengine.logging import MMLogger
  from mmengine.model import BaseModule, ModuleList, Sequential, constant_init, normal_init, trunc_normal_init
  from mmengine.model.weight_init import trunc_normal_
  from mmengine.runner.checkpoint import CheckpointLoader, load_state_dict
  from torch.nn.modules.utils import _pair
  from mmdet.registry import MODELS
  from ..layers import PatchEmbed, nchw_to_nlc, nlc_to_nchw
label_desc: Use image node_id 1 to create a new PVTEncoderLayer object from inherited base classes: BaseModule with example: obj = PVTEncoderLayer(embed_dims, num_heads, feedforward_channels, drop_rate, attn_drop_rate, drop_path_rate, qkv_bias, act_cfg, norm_cfg, sr_ratio, use_conv_ffn, init_cfg)