class_docstr: Blocks for changing the feature dimensions in MViT (using Q-pooling).
  See Section 3.3.1 in paper for details.
class_docstr_tok: ["Blocks","for","changing","the","feature","dimensions","in","MViT","(","using","Q-pooling",")",".","See","Section","3.3.1","in","paper","for","details","."]
docstr: Uses the same structure of F and G functions as Reversible Block except
  without using reversible forward (and backward) pass.
docstr_tok: ["Uses","the","same","structure","of","F","and","G","functions","as","Reversible","Block","except","without","using","reversible","forward","(","and","backward",")","pass","."]
code: def __init__(
      self,
      dim,
      input_size,
      dim_out,
      num_heads,
      mlp_ratio,
      qkv_bias,
      drop_path,
      kernel_q,
      kernel_kv,
      stride_q,
      stride_kv,
      cfg,
      norm_layer=nn.LayerNorm,
      pre_q_fusion=None,
      layer_id=0,
  ):
      """
      Uses the same structure of F and G functions as Reversible Block except
      without using reversible forward (and backward) pass.
      """
      super().__init__()
  
      self.drop_path_rate = drop_path
  
      embed_dim = dim
  
      self.F = AttentionSubBlock(
          dim=embed_dim,
          input_size=input_size,
          num_heads=num_heads,
          cfg=cfg,
          dim_out=dim_out,
          kernel_q=kernel_q,
          kernel_kv=kernel_kv,
          stride_q=stride_q,
          stride_kv=stride_kv,
          norm_layer=norm_layer,
      )
  
      self.G = MLPSubblock(
          dim=dim_out,
          mlp_ratio=mlp_ratio,
          norm_layer=norm_layer,
      )
  
      self.layer_id = layer_id
  
      self.is_proj = False
      self.has_cls_embed = cfg.MVIT.CLS_EMBED_ON
  
      self.is_conv = False
      self.pool_first = cfg.MVIT.POOL_FIRST
      self.mode = cfg.MVIT.MODE
      self.pre_q_fuse = TwoStreamFusion(pre_q_fusion, dim=dim)
  
      if cfg.MVIT.REV.RES_PATH == "max":
          self.res_conv = False
          self.pool_skip = nn.MaxPool3d(
              # self.attention.attn.pool_q.kernel_size,
              [
                  s + 1 if s > 1 else s
                  for s in self.F.attn.pool_q.stride
              ],
              self.F.attn.pool_q.stride,
              [int(k // 2) for k in self.F.attn.pool_q.stride],
              # self.attention.attn.pool_q.padding,
              ceil_mode=False,
          )
  
      elif cfg.MVIT.REV.RES_PATH == "conv":
          self.res_conv = True
      else:
          raise NotImplementedError
  
      # Add a linear projection in residual branch
      if embed_dim != dim_out:
          self.is_proj = True
          self.res_proj = nn.Linear(embed_dim, dim_out, bias=True)
  
imports: import sys
  from functools import partial
  import torch
  from torch import nn
  from torch.autograd import Function
  from slowfast.models.attention import MultiScaleAttention, attention_pool
  from slowfast.models.common import Mlp, TwoStreamFusion, drop_path
  from slowfast.models.utils import round_width
label_desc: Use image node_id 1 to create a new StageTransitionBlock object from inherited base classes: nn with example: obj = StageTransitionBlock(dim, input_size, dim_out, num_heads, mlp_ratio, qkv_bias, drop_path, kernel_q, kernel_kv, stride_q, stride_kv, cfg, norm_layer, pre_q_fusion, layer_id)