class_docstr: Swin Transformer Block.
  
  Args:
      dim (int): Number of input channels.
      input_resolution (tuple[int]): Input resolution.
      num_heads (int): Number of attention heads.
      window_size (int): Window size.
      shift_size (int): Shift size for SW-MSA.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
      qkv_bias (bool, optional): If True, add a learnable bias to query, key, value. Default: True
      qk_scale (float | None, optional): Override default qk scale of head_dim ** -0.5 if set.
      drop (float, optional): Dropout rate. Default: 0.0
      attn_drop (float, optional): Attention dropout rate. Default: 0.0
      drop_path (float, optional): Stochastic depth rate. Default: 0.0
      act_layer (nn.Module, optional): Activation layer. Default: nn.GELU
      norm_layer (nn.Module, optional): Normalization layer.  Default: nn.LayerNorm
class_docstr_tok: ["Swin","Transformer","Block",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","input_resolution","(","tuple","[","int","]",")",":","Input","resolution",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","int",")",":","Window","size",".","shift_size","(","int",")",":","Shift","size","for","SW-MSA",".","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","qkv_bias","(","bool",",","optional",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","float","|","None",",","optional",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","drop","(","float",",","optional",")",":","Dropout","rate",".","Default",":","0.0","attn_drop","(","float",",","optional",")",":","Attention","dropout","rate",".","Default",":","0.0","drop_path","(","float",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.0","act_layer","(","nn.Module",",","optional",")",":","Activation","layer",".","Default",":","nn.GELU","norm_layer","(","nn.Module",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm"]
code: def forward(self, x, x_size):
      H, W = x_size
      B, L, C = x.shape
      # assert L == H * W, "input feature has wrong size"
  
      shortcut = x
      x = self.norm1(x)
      x = x.view(B, H, W, C)
  
      # cyclic shift
      if self.shift_size > 0:
          shifted_x = torch.roll(
              x,
              shifts=(-self.shift_size, -self.shift_size),
              dims=(1, 2),
          )
      else:
          shifted_x = x
  
      # partition windows
      x_windows = window_partition(
          shifted_x, self.window_size
      )  # nW*B, window_size, window_size, C
      x_windows = x_windows.view(
          -1, self.window_size * self.window_size, C
      )  # nW*B, window_size*window_size, C
  
      # W-MSA/SW-MSA (to be compatible for testing on images whose shapes are the multiple of window size
      if self.input_resolution == x_size:
          attn_windows = self.attn(
              x_windows, mask=self.attn_mask
          )  # nW*B, window_size*window_size, C
      else:
          attn_windows = self.attn(
              x_windows, mask=self.calculate_mask(x_size).to(x.device)
          )
  
      # merge windows
      attn_windows = attn_windows.view(
          -1, self.window_size, self.window_size, C
      )
      shifted_x = window_reverse(
          attn_windows, self.window_size, H, W
      )  # B H' W' C
  
      # reverse cyclic shift
      if self.shift_size > 0:
          x = torch.roll(
              shifted_x,
              shifts=(self.shift_size, self.shift_size),
              dims=(1, 2),
          )
      else:
          x = shifted_x
      x = x.view(B, H * W, C)
  
      # FFN
      x = shortcut + self.drop_path(x)
      x = x + self.drop_path(self.mlp(self.norm2(x)))
  
      return x
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from timm.models.layers import DropPath, to_2tuple, trunc_normal_
label_desc: Use image node_id 3 for calling the SwinTransformerBlock obj's underlying member method code with example usage: obj.forward(x, x_size) and returns: x