class_docstr: Basic Swin Transformer layer in one stage based on: "Liu et al.,
  Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
  <https://arxiv.org/abs/2103.14030>"
  https://github.com/microsoft/Swin-Transformer
docstr: Args:
      dim: number of feature channels.
      depth: number of layers in each stage.
      num_heads: number of attention heads.
      window_size: local window size.
      drop_path: stochastic depth rate.
      mlp_ratio: ratio of mlp hidden dim to embedding dim.
      qkv_bias: add a learnable bias to query, key, value.
      drop: dropout rate.
      attn_drop: attention dropout rate.
      norm_layer: normalization layer.
      downsample: an optional downsampling layer at the end of the layer.
      use_checkpoint: use gradient checkpointing for reduced memory usage.
docstr_tok: ["Args",":","dim",":","number","of","feature","channels",".","depth",":","number","of","layers","in","each","stage",".","num_heads",":","number","of","attention","heads",".","window_size",":","local","window","size",".","drop_path",":","stochastic","depth","rate",".","mlp_ratio",":","ratio","of","mlp","hidden","dim","to","embedding","dim",".","qkv_bias",":","add","a","learnable","bias","to","query",",","key",",","value",".","drop",":","dropout","rate",".","attn_drop",":","attention","dropout","rate",".","norm_layer",":","normalization","layer",".","downsample",":","an","optional","downsampling","layer","at","the","end","of","the","layer",".","use_checkpoint",":","use","gradient","checkpointing","for","reduced","memory","usage","."]
code: def __init__(
      self,
      dim: int,
      depth: int,
      num_heads: int,
      window_size: Sequence[int],
      drop_path: list,
      mlp_ratio: float = 4.0,
      qkv_bias: bool = False,
      drop: float = 0.0,
      attn_drop: float = 0.0,
      norm_layer: type[LayerNorm] = nn.LayerNorm,
      downsample: nn.Module | None = None,
      use_checkpoint: bool = False,
  ) -> None:
      """
      Args:
          dim: number of feature channels.
          depth: number of layers in each stage.
          num_heads: number of attention heads.
          window_size: local window size.
          drop_path: stochastic depth rate.
          mlp_ratio: ratio of mlp hidden dim to embedding dim.
          qkv_bias: add a learnable bias to query, key, value.
          drop: dropout rate.
          attn_drop: attention dropout rate.
          norm_layer: normalization layer.
          downsample: an optional downsampling layer at the end of the layer.
          use_checkpoint: use gradient checkpointing for reduced memory usage.
      """
  
      super().__init__()
      self.window_size = window_size
      self.shift_size = tuple(i // 2 for i in window_size)
      self.no_shift = tuple(0 for i in window_size)
      self.depth = depth
      self.use_checkpoint = use_checkpoint
      self.blocks = nn.ModuleList(
          [
              SwinTransformerBlock(
                  dim=dim,
                  num_heads=num_heads,
                  window_size=self.window_size,
                  shift_size=self.no_shift
                  if (i % 2 == 0)
                  else self.shift_size,
                  mlp_ratio=mlp_ratio,
                  qkv_bias=qkv_bias,
                  drop=drop,
                  attn_drop=attn_drop,
                  drop_path=drop_path[i]
                  if isinstance(drop_path, list)
                  else drop_path,
                  norm_layer=norm_layer,
                  use_checkpoint=use_checkpoint,
              )
              for i in range(depth)
          ]
      )
      self.downsample = downsample
      if callable(self.downsample):
          self.downsample = downsample(
              dim=dim,
              norm_layer=norm_layer,
              spatial_dims=len(self.window_size),
          )
  
imports: from __future__ import annotations
  import itertools
  from collections.abc import Sequence
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch.nn import LayerNorm
  from typing_extensions import Final
  from monai.networks.blocks import MLPBlock
  from monai.networks.blocks import PatchEmbed, UnetOutBlock, UnetrBasicBlock, UnetrUpBlock
  from monai.networks.layers import DropPath, trunc_normal_
  from monai.utils import ensure_tuple_rep, look_up_option, optional_import
  from monai.utils.deprecate_utils import deprecated_arg
label_desc: Use image node_id 1 to create a new BasicLayer object from inherited base classes: nn with example: obj = BasicLayer(dim, depth, num_heads, window_size, drop_path, mlp_ratio, qkv_bias, drop, attn_drop, norm_layer, downsample, use_checkpoint)