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 __init__(
      self,
      embed_dims,
      num_heads,
      feedforward_channels,
      window_size=7,
      shift=False,
      qkv_bias=True,
      qk_scale=None,
      drop_rate=0.0,
      attn_drop_rate=0.0,
      drop_path_rate=0.0,
      act_cfg=dict(type="GELU"),
      norm_cfg=dict(type="LN"),
      with_cp=False,
      init_cfg=None,
  ):
      super(SwinBlock, self).__init__()
  
      self.init_cfg = init_cfg
      self.with_cp = with_cp
  
      self.norm1 = build_norm_layer(norm_cfg, embed_dims)[1]
      self.attn = ShiftWindowMSA(
          embed_dims=embed_dims,
          num_heads=num_heads,
          window_size=window_size,
          shift_size=window_size // 2 if shift else 0,
          qkv_bias=qkv_bias,
          qk_scale=qk_scale,
          attn_drop_rate=attn_drop_rate,
          proj_drop_rate=drop_rate,
          dropout_layer=dict(type="DropPath", drop_prob=drop_path_rate),
          init_cfg=None,
      )
  
      self.norm2 = build_norm_layer(norm_cfg, embed_dims)[1]
      self.ffn = FFN(
          embed_dims=embed_dims,
          feedforward_channels=feedforward_channels,
          num_fcs=2,
          ffn_drop=drop_rate,
          dropout_layer=dict(type="DropPath", drop_prob=drop_path_rate),
          act_cfg=act_cfg,
          add_identity=True,
          init_cfg=None,
      )
  
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 1 to create a new SwinBlock object from inherited base classes: BaseModule with example: obj = SwinBlock(embed_dims, num_heads, feedforward_channels, window_size, shift, qkv_bias, qk_scale, drop_rate, attn_drop_rate, drop_path_rate, act_cfg, norm_cfg, with_cp, init_cfg)