class_docstr: Window based multi-head self attention (W-MSA) module with relative position bias.
  It supports both of shifted and non-shifted window.
  
  Args:
      dim (int): Number of input channels.
      window_size (tuple[int]): The height and width of the window.
      num_heads (int): Number of attention heads.
      qkv_bias (bool, optional):  If True, add a learnable bias to query, key, value. Default: True
      qk_scale (float | None, optional): Override default query and key scale of head_dim ** -0.5 if set. Default None
      attn_drop (float, optional): Dropout ratio of attention weight. Default: 0.0
      proj_drop (float, optional): Dropout ratio of output. Default: 0.0
class_docstr_tok: ["Window","based","multi-head","self","attention","(","W-MSA",")","module","with","relative","position","bias",".","It","supports","both","of","shifted","and","non-shifted","window",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","window_size","(","tuple","[","int","]",")",":","The","height","and","width","of","the","window",".","num_heads","(","int",")",":","Number","of","attention","heads",".","qkv_bias","(","bool",",","optional",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","float","|","None",",","optional",")",":","Override","default","query","and","key","scale","of","head_dim","*","*","-0.5","if","set",".","Default","None","attn_drop","(","float",",","optional",")",":","Dropout","ratio","of","attention","weight",".","Default",":","0.0","proj_drop","(","float",",","optional",")",":","Dropout","ratio","of","output",".","Default",":","0.0"]
docstr: Args:
      x: input features with shape of (num_windows*B, N, C)
      mask: (0/-inf) mask with shape of (num_windows, Wh*Ww, Wh*Ww) or None
docstr_tok: ["Args",":","x",":","input","features","with","shape","of","(","num_windows","*","B",",","N",",","C",")","mask",":","(","0\/-inf",")","mask","with","shape","of","(","num_windows",",","Wh","*","Ww",",","Wh","*","Ww",")","or","None"]
code: def forward(self, x, mask=None):
      """
      Args:
          x: input features with shape of (num_windows*B, N, C)
          mask: (0/-inf) mask with shape of (num_windows, Wh*Ww, Wh*Ww) or None
      """
      B_, N, C = x.shape
      qkv = (
          self.qkv(x)
          .reshape([B_, N, 3, self.num_heads, C // self.num_heads])
          .transpose([2, 0, 3, 1, 4])
      )
      q, k, v = qkv[0], qkv[1], qkv[2]
  
      q = q * self.scale
      attn = paddle.mm(q, k.transpose([0, 1, 3, 2]))
  
      if self.training or not hasattr(self, "relative_position_bias"):
          index = self.relative_position_index.reshape([-1])
  
          relative_position_bias = paddle.index_select(
              self.relative_position_bias_table, index
          )
          relative_position_bias = relative_position_bias.reshape(
              [
                  self.window_size[0] * self.window_size[1],
                  self.window_size[0] * self.window_size[1],
                  -1,
              ]
          )  # Wh*Ww,Wh*Ww,nH
  
          relative_position_bias = relative_position_bias.transpose(
              [2, 0, 1]
          )  # nH, Wh*Ww, Wh*Ww
          attn = attn + relative_position_bias.unsqueeze(0)
      else:
          attn = attn + self.relative_position_bias
  
      if mask is not None:
          nW = mask.shape[0]
          attn = attn.reshape(
              [B_ // nW, nW, self.num_heads, N, N]
          ) + mask.unsqueeze(1).unsqueeze(0)
          attn = attn.reshape([-1, self.num_heads, N, N])
          attn = self.softmax(attn)
      else:
          attn = self.softmax(attn)
  
      attn = self.attn_drop(attn)
  
      x = paddle.mm(attn, v).transpose([0, 2, 1, 3]).reshape([B_, N, C])
      x = self.proj(x)
      x = self.proj_drop(x)
      return x
  
imports: import numpy
  import paddle
  import paddle.nn
  from medicalseg.cvlibs import manager, param_init
  from medicalseg.utils import load_pretrained_model
  from medicalseg.models.backbones.transformer_utils import DropPath, to_2tuple
label_desc: Use image node_id 3 for calling the WindowAttention obj's underlying member method code with example usage: obj.forward(x, mask) and returns: x