class_docstr: Implements encoder block with residual connection.
  
  Args:
      dim (int): The feature dimension.
      num_heads (int): Number of parallel attention heads.
      mlp_ratio (int): Ratio of mlp hidden dim to embedding dim.
      qk_scale (float): Override default qk scale of head_dim ** -0.5 if set.
      drop (float): Drop rate for mlp output weights. Default: 0.
      attn_drop (float): Drop rate for attention output weights.
          Default: 0.
      proj_drop (float): Drop rate for attn layer output weights.
          Default: 0.
      drop_path (float): Drop rate for paths of model.
          Default: 0.
      act_cfg (dict): Config dict for activation layer.
          Default: dict(type='GELU').
      norm_cfg (dict): Config dict for normalization layer.
          Default: dict(type='LN', requires_grad=True).
      with_cp (bool): Use checkpoint or not. Using checkpoint will save some
          memory while slowing down the training speed. Default: False.
class_docstr_tok: ["Implements","encoder","block","with","residual","connection",".","Args",":","dim","(","int",")",":","The","feature","dimension",".","num_heads","(","int",")",":","Number","of","parallel","attention","heads",".","mlp_ratio","(","int",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","qk_scale","(","float",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","drop","(","float",")",":","Drop","rate","for","mlp","output","weights",".","Default",":","0.","attn_drop","(","float",")",":","Drop","rate","for","attention","output","weights",".","Default",":","0.","proj_drop","(","float",")",":","Drop","rate","for","attn","layer","output","weights",".","Default",":","0.","drop_path","(","float",")",":","Drop","rate","for","paths","of","model",".","Default",":","0.","act_cfg","(","dict",")",":","Config","dict","for","activation","layer",".","Default",":","dict","(","type='GELU","'",")",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Default",":","dict","(","type='LN","'",",","requires_grad=True",")",".","with_cp","(","bool",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed",".","Default",":","False","."]
code: def __init__(
      self,
      dim,
      num_heads,
      mlp_ratio=4,
      qkv_bias=False,
      qk_scale=None,
      drop=0.0,
      attn_drop=0.0,
      proj_drop=0.0,
      drop_path=0.0,
      act_cfg=dict(type="GELU"),
      norm_cfg=dict(type="LN", eps=1e-6),
      with_cp=False,
  ):
      super(Block, self).__init__()
      self.with_cp = with_cp
      _, self.norm1 = build_norm_layer(norm_cfg, dim)
      self.attn = Attention(
          dim, num_heads, qkv_bias, qk_scale, attn_drop, proj_drop
      )
      self.drop_path = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
      _, self.norm2 = build_norm_layer(norm_cfg, dim)
      mlp_hidden_dim = int(dim * mlp_ratio)
      self.mlp = Mlp(
          in_features=dim,
          hidden_features=mlp_hidden_dim,
          act_cfg=act_cfg,
          drop=drop,
      )
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from annotator.uniformer.mmcv.cnn import Conv2d, Linear, build_activation_layer, build_norm_layer, constant_init, kaiming_init, normal_init
  from annotator.uniformer.mmcv.runner import _load_checkpoint
  from annotator.uniformer.mmcv.utils.parrots_wrapper import _BatchNorm
  from annotator.uniformer.mmseg.utils import get_root_logger
  from ..builder import BACKBONES
  from ..utils import DropPath, trunc_normal_
label_desc: Use image node_id 1 to create a new Block object from inherited base classes: nn with example: obj = Block(dim, num_heads, mlp_ratio, qkv_bias, qk_scale, drop, attn_drop, proj_drop, drop_path, act_cfg, norm_cfg, with_cp)