class_docstr: "
  Args:
      embed_dims (int): The feature dimension.
      num_heads (int): Parallel attention heads.
      feedforward_channels (int): The hidden dimension for FFNs.
      window_size (int, optional): The local window scale. Default: 7.
      shift (bool, optional): whether to shift window or not. Default False.
      qkv_bias (bool, optional): enable bias for qkv if True. Default: True.
      qk_scale (float | None, optional): Override default qk scale of
          head_dim ** -0.5 if set. Default: None.
      drop_rate (float, optional): Dropout rate. Default: 0.
      attn_drop_rate (float, optional): Attention dropout rate. Default: 0.
      drop_path_rate (float, optional): Stochastic depth rate. Default: 0.
      act_cfg (dict, optional): The config dict of activation function.
          Default: dict(type='GELU').
      norm_cfg (dict, optional): The config dict of normalization.
          Default: dict(type='LN').
      with_cp (bool, optional): Use checkpoint or not. Using checkpoint
          will save some memory while slowing down the training speed.
          Default: False.
      init_cfg (dict | list | None, optional): The init config.
          Default: None.
class_docstr_tok: ["``","Args",":","embed_dims","(","int",")",":","The","feature","dimension",".","num_heads","(","int",")",":","Parallel","attention","heads",".","feedforward_channels","(","int",")",":","The","hidden","dimension","for","FFNs",".","window_size","(","int",",","optional",")",":","The","local","window","scale",".","Default",":","7.","shift","(","bool",",","optional",")",":","whether","to","shift","window","or","not",".","Default","False",".","qkv_bias","(","bool",",","optional",")",":","enable","bias","for","qkv","if","True",".","Default",":","True",".","qk_scale","(","float","|","None",",","optional",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","Default",":","None",".","drop_rate","(","float",",","optional",")",":","Dropout","rate",".","Default",":","0.","attn_drop_rate","(","float",",","optional",")",":","Attention","dropout","rate",".","Default",":","0.","drop_path_rate","(","float",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.","act_cfg","(","dict",",","optional",")",":","The","config","dict","of","activation","function",".","Default",":","dict","(","type='GELU","'",")",".","norm_cfg","(","dict",",","optional",")",":","The","config","dict","of","normalization",".","Default",":","dict","(","type='LN","'",")",".","with_cp","(","bool",",","optional",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed",".","Default",":","False",".","init_cfg","(","dict","|","list","|","None",",","optional",")",":","The","init","config",".","Default",":","None","."]
code: def forward(self, x, hw_shape):
      def _inner_forward(x):
          identity = x
          x = self.norm1(x)
          x = self.attn(x, hw_shape)
  
          x = x + identity
  
          identity = x
          x = self.norm2(x)
          x = self.ffn(x, identity=identity)
  
          return x
  
      if self.with_cp and x.requires_grad:
          x = cp.checkpoint(_inner_forward, x)
      else:
          x = _inner_forward(x)
  
      return x
  
imports: import warnings
  from collections import OrderedDict
  from copy import deepcopy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, build_dropout
  from mmengine.logging import MMLogger
  from mmengine.model import BaseModule, ModuleList
  from mmengine.model.weight_init import constant_init, trunc_normal_, trunc_normal_init
  from mmengine.runner.checkpoint import CheckpointLoader
  from mmengine.utils import to_2tuple
  from mmdet.registry import MODELS
  from ..layers import PatchEmbed, PatchMerging
label_desc: Use image node_id 2 for calling the SwinBlock obj's underlying member method code with example usage: obj.forward(x, hw_shape) and returns: x, x