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: Forward logic is similar to MultiScaleBlock with Q-pooling.
docstr_tok: ["Forward","logic","is","similar","to","MultiScaleBlock","with","Q-pooling","."]
code: def forward(
      self,
      x,
  ):
      """
      Forward logic is similar to MultiScaleBlock with Q-pooling.
      """
      x = self.pre_q_fuse(x)
  
      # fork tensor for residual connections
      x_res = x
  
      # This uses conv to pool the residual hidden features
      # but done before pooling only if not pool_first
      if self.is_proj and not self.pool_first:
          x_res = self.res_proj(x_res)
  
      if self.res_conv:
          # Pooling the hidden features with the same conv as Q
          N, L, C = x_res.shape
  
          # This handling is the same as that of q in MultiScaleAttention
          if self.mode == "conv_unshared":
              fold_dim = 1
          else:
              fold_dim = self.F.attn.num_heads
  
          # Output is (B, N, L, C)
          x_res = x_res.reshape(N, L, fold_dim, C // fold_dim).permute(
              0, 2, 1, 3
          )
  
          x_res, _ = attention_pool(
              x_res,
              self.F.attn.pool_q,
              # thw_shape = self.attention.attn.thw,
              thw_shape=self.F.thw,
              has_cls_embed=self.has_cls_embed,
              norm=self.F.attn.norm_q
              if hasattr(self.F.attn, "norm_q")
              else None,
          )
          x_res = x_res.permute(0, 2, 1, 3).reshape(
              N, x_res.shape[2], C
          )
  
      else:
          # Pooling the hidden features with max op
          x_res, _ = attention_pool(
              x_res,
              self.pool_skip,
              thw_shape=self.F.attn.thw,
              has_cls_embed=self.has_cls_embed,
          )
  
      # If pool_first then project to higher dim now
      if self.is_proj and self.pool_first:
          x_res = self.res_proj(x_res)
  
      x = self.F(x)
      x = x_res + x
      x = x + self.G(x)
  
      x = drop_path(
          x, drop_prob=self.drop_path_rate, training=self.training
      )
  
      return x
  
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 2 for calling the StageTransitionBlock obj's underlying member method code with example usage: obj.forward(x) and returns: x