class_docstr: Shifted Window Multihead Self-Attention Module.
  
  Args:
      embed_dims (int): Number of input channels.
      num_heads (int): Number of attention heads.
      window_size (int): The height and width of the window.
      shift_size (int, optional): The shift step of each window towards
          right-bottom. If zero, act as regular window-msa. Defaults to 0.
      qkv_bias (bool, optional): If True, add a learnable bias to q, k, v.
          Default: True
      qk_scale (float | None, optional): Override default qk scale of
          head_dim ** -0.5 if set. Defaults: None.
      attn_drop_rate (float, optional): Dropout ratio of attention weight.
          Defaults: 0.
      proj_drop_rate (float, optional): Dropout ratio of output.
          Defaults: 0.
      dropout_layer (dict, optional): The dropout_layer used before output.
          Defaults: dict(type='DropPath', drop_prob=0.).
      init_cfg (dict, optional): The extra config for initialization.
          Default: None.
class_docstr_tok: ["Shifted","Window","Multihead","Self-Attention","Module",".","Args",":","embed_dims","(","int",")",":","Number","of","input","channels",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","int",")",":","The","height","and","width","of","the","window",".","shift_size","(","int",",","optional",")",":","The","shift","step","of","each","window","towards","right-bottom",".","If","zero",",","act","as","regular","window-msa",".","Defaults","to","0.","qkv_bias","(","bool",",","optional",")",":","If","True",",","add","a","learnable","bias","to","q",",","k",",","v.","Default",":","True","qk_scale","(","float","|","None",",","optional",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","Defaults",":","None",".","attn_drop_rate","(","float",",","optional",")",":","Dropout","ratio","of","attention","weight",".","Defaults",":","0.","proj_drop_rate","(","float",",","optional",")",":","Dropout","ratio","of","output",".","Defaults",":","0.","dropout_layer","(","dict",",","optional",")",":","The","dropout_layer","used","before","output",".","Defaults",":","dict","(","type='DropPath","'",",","drop_prob=0.",")",".","init_cfg","(","dict",",","optional",")",":","The","extra","config","for","initialization",".","Default",":","None","."]
docstr: Args:
      x: (B, H, W, C)
  Returns:
      windows: (num_windows*B, window_size, window_size, C)
code: def window_partition(self, x):
      """
      Args:
          x: (B, H, W, C)
      Returns:
          windows: (num_windows*B, window_size, window_size, C)
      """
      B, H, W, C = x.shape
      window_size = self.window_size
      x = x.view(
          B,
          H // window_size,
          window_size,
          W // window_size,
          window_size,
          C,
      )
      windows = x.permute(0, 1, 3, 2, 4, 5).contiguous()
      windows = windows.view(-1, window_size, window_size, C)
      return windows
  
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 4 for calling the ShiftWindowMSA obj's underlying member method code with example usage: obj.window_partition(x) and returns: windows