class_docstr: Swin Transformer Block.
  Args:
      dim (int): Number of input channels.
      input_resolution (tuple[int]): Input resulotion.
      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","resulotion",".","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 create_attn_mask(self, H, W):
      # calculate attention mask for SW-MSA
  
      Hp = int(np.ceil(H / self.window_size)) * self.window_size
      Wp = int(np.ceil(W / self.window_size)) * self.window_size
      img_mask = torch.zeros((1, Hp, Wp, 1))  # 1 Hp Wp 1
      h_slices = (
          slice(0, -self.window_size),
          slice(-self.window_size, -self.shift_size),
          slice(-self.shift_size, None),
      )
      w_slices = (
          slice(0, -self.window_size),
          slice(-self.window_size, -self.shift_size),
          slice(-self.shift_size, None),
      )
      cnt = 0
      for h in h_slices:
          for w in w_slices:
              img_mask[:, h, w, :] = cnt
              cnt += 1
  
      mask_windows = window_partition(
          img_mask, self.window_size
      )  # nW, window_size, window_size, 1
      mask_windows = mask_windows.view(
          -1, self.window_size * self.window_size
      )
      attn_mask = mask_windows.unsqueeze(1) - mask_windows.unsqueeze(2)
      attn_mask = attn_mask.masked_fill(
          attn_mask != 0, float(-100.0)
      ).masked_fill(attn_mask == 0, float(0.0))
  
      return attn_mask
  
imports: import os
  import logging
  import torch
  import torch.nn
  import torch.nn.functional
  from functools import partial
  import torch.distributed
  from torch.nn.init import trunc_normal_
  from megatron.model.transformer import DropPath
  from megatron import get_args
  from megatron.model import LayerNorm
  import numpy
  from math import sqrt
label_desc: Use image node_id 2 for calling the SwinTransformerBlock obj's underlying member method code with example usage: obj.create_attn_mask(H, W) and returns: attn_mask