class_docstr: Implements one stage in Swin Transformer.
  
  Args:
      embed_dims (int): The feature dimension.
      num_heads (int): Parallel attention heads.
      feedforward_channels (int): The hidden dimension for FFNs.
      depth (int): The number of blocks in this stage.
      window_size (int, optional): The local window scale. Default: 7.
      qkv_bias (bool, optional): enable bias for qkv if True. Default: True.
      qk_scale (float | None, optional): Override default qk scale of
          head_dim ** -0.5 if set. Default: None.
      drop_rate (float, optional): Dropout rate. Default: 0.
      attn_drop_rate (float, optional): Attention dropout rate. Default: 0.
      drop_path_rate (float | list[float], optional): Stochastic depth
          rate. Default: 0.
      downsample (BaseModule | None, optional): The downsample operation
          module. Default: None.
      act_cfg (dict, optional): The config dict of activation function.
          Default: dict(type='GELU').
      norm_cfg (dict, optional): The config dict of normalization.
          Default: dict(type='LN').
      with_cp (bool, optional): Use checkpoint or not. Using checkpoint
          will save some memory while slowing down the training speed.
          Default: False.
      init_cfg (dict | list | None, optional): The init config.
          Default: None.
class_docstr_tok: ["Implements","one","stage","in","Swin","Transformer",".","Args",":","embed_dims","(","int",")",":","The","feature","dimension",".","num_heads","(","int",")",":","Parallel","attention","heads",".","feedforward_channels","(","int",")",":","The","hidden","dimension","for","FFNs",".","depth","(","int",")",":","The","number","of","blocks","in","this","stage",".","window_size","(","int",",","optional",")",":","The","local","window","scale",".","Default",":","7.","qkv_bias","(","bool",",","optional",")",":","enable","bias","for","qkv","if","True",".","Default",":","True",".","qk_scale","(","float","|","None",",","optional",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","Default",":","None",".","drop_rate","(","float",",","optional",")",":","Dropout","rate",".","Default",":","0.","attn_drop_rate","(","float",",","optional",")",":","Attention","dropout","rate",".","Default",":","0.","drop_path_rate","(","float","|","list","[","float","]",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.","downsample","(","BaseModule","|","None",",","optional",")",":","The","downsample","operation","module",".","Default",":","None",".","act_cfg","(","dict",",","optional",")",":","The","config","dict","of","activation","function",".","Default",":","dict","(","type='GELU","'",")",".","norm_cfg","(","dict",",","optional",")",":","The","config","dict","of","normalization",".","Default",":","dict","(","type='LN","'",")",".","with_cp","(","bool",",","optional",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed",".","Default",":","False",".","init_cfg","(","dict","|","list","|","None",",","optional",")",":","The","init","config",".","Default",":","None","."]
code: def __init__(
      self,
      embed_dims,
      num_heads,
      feedforward_channels,
      depth,
      window_size=7,
      qkv_bias=True,
      qk_scale=None,
      drop_rate=0.0,
      attn_drop_rate=0.0,
      drop_path_rate=0.0,
      downsample=None,
      act_cfg=dict(type="GELU"),
      norm_cfg=dict(type="LN"),
      with_cp=False,
      init_cfg=None,
  ):
      super().__init__(init_cfg=init_cfg)
  
      if isinstance(drop_path_rate, list):
          drop_path_rates = drop_path_rate
          assert len(drop_path_rates) == depth
      else:
          drop_path_rates = [
              deepcopy(drop_path_rate) for _ in range(depth)
          ]
  
      self.blocks = ModuleList()
      for i in range(depth):
          block = SwinBlock(
              embed_dims=embed_dims,
              num_heads=num_heads,
              feedforward_channels=feedforward_channels,
              window_size=window_size,
              shift=False if i % 2 == 0 else True,
              qkv_bias=qkv_bias,
              qk_scale=qk_scale,
              drop_rate=drop_rate,
              attn_drop_rate=attn_drop_rate,
              drop_path_rate=drop_path_rates[i],
              act_cfg=act_cfg,
              norm_cfg=norm_cfg,
              with_cp=with_cp,
              init_cfg=None,
          )
          self.blocks.append(block)
  
      self.downsample = downsample
  
imports: import warnings
  from collections import OrderedDict
  from copy import deepcopy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, build_dropout
  from mmengine.logging import MMLogger
  from mmengine.model import BaseModule, ModuleList
  from mmengine.model.weight_init import constant_init, trunc_normal_, trunc_normal_init
  from mmengine.runner.checkpoint import CheckpointLoader
  from mmengine.utils import to_2tuple
  from mmdet.registry import MODELS
  from ..layers import PatchEmbed, PatchMerging
label_desc: Use image node_id 1 to create a new SwinBlockSequence object from inherited base classes: BaseModule with example: obj = SwinBlockSequence(embed_dims, num_heads, feedforward_channels, depth, window_size, qkv_bias, qk_scale, drop_rate, attn_drop_rate, drop_path_rate, downsample, act_cfg, norm_cfg, with_cp, init_cfg)