class_docstr: Windows Block.
  Args:
      dim (int): Number of input channels.
      num_heads (int): Number of attention heads.
      window_size (int): Window size.
      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
      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: ["Windows","Block",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","int",")",":","Window","size",".","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","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 __init__(
      self,
      dim,
      num_heads,
      window_size=7,
      mlp_ratio=4.0,
      qkv_bias=True,
      drop_path=0.0,
      act_layer=nn.GELU,
      norm_layer=nn.LayerNorm,
      ffn=True,
      cpe_act=False,
  ):
      super().__init__()
      self.dim = dim
      self.ffn = ffn
      self.num_heads = num_heads
      self.window_size = to_2tuple(window_size)
      self.mlp_ratio = mlp_ratio
  
      self.cpe1 = ConvPosEnc(dim=dim, k=3, act=cpe_act)
      self.norm1 = norm_layer(dim)
      self.attn = WindowAttention(
          dim,
          self.window_size,
          num_heads=num_heads,
          qkv_bias=qkv_bias,
      )
      self.drop_path1 = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
  
      self.cpe2 = ConvPosEnc(dim=dim, k=3, act=cpe_act)
      if self.ffn:
          self.norm2 = norm_layer(dim)
          mlp_hidden_dim = int(dim * mlp_ratio)
          self.mlp = Mlp(
              in_features=dim,
              hidden_features=mlp_hidden_dim,
              act_layer=act_layer,
          )
          self.drop_path2 = (
              DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
          )
      else:
          self.norm2 = None
          self.mlp = None
          self.drop_path1 = None
  
imports: from functools import partial
  from typing import Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import DropPath, to_2tuple, trunc_normal_, Mlp, LayerNorm2d, get_norm_layer, use_fused_attn
  from timm.layers import NormMlpClassifierHead, ClassifierHead
  from ._builder import build_model_with_cfg
  from ._features_fx import register_notrace_function
  from ._manipulate import checkpoint_seq
  from ._registry import generate_default_cfgs, register_model
label_desc: Use image node_id 1 to create a new SpatialBlock object from inherited base classes: nn with example: obj = SpatialBlock(dim, num_heads, window_size, mlp_ratio, qkv_bias, drop_path, act_layer, norm_layer, ffn, cpe_act)