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 forward(self, x):
      def _inner_forward(x):
          out = x + self.drop_path(self.attn(self.norm1(x)))
          out = out + self.drop_path(self.mlp(self.norm2(out)))
          return out
  
      if self.with_cp and x.requires_grad:
          out = cp.checkpoint(_inner_forward, x)
      else:
          out = _inner_forward(x)
  
      return out
  
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 2 for calling the Block obj's underlying member method code with example usage: obj.forward(x) and returns: out, out