docstr: MViT main class.
  
  Args:
      spatial_size (tuple of ints): The spacial size of the input as ``(H, W)``.
      temporal_size (int): The temporal size ``T`` of the input.
      block_setting (sequence of MSBlockConfig): The Network structure.
      residual_pool (bool): If True, use MViTv2 pooling residual connection.
      residual_with_cls_embed (bool): If True, the addition on the residual connection will include
          the class embedding.
      rel_pos_embed (bool): If True, use MViTv2's relative positional embeddings.
      proj_after_attn (bool): If True, apply the projection after the attention.
      dropout (float): Dropout rate. Default: 0.0.
      attention_dropout (float): Attention dropout rate. Default: 0.0.
      stochastic_depth_prob: (float): Stochastic depth rate. Default: 0.0.
      num_classes (int): The number of classes.
      block (callable, optional): Module specifying the layer which consists of the attention and mlp.
      norm_layer (callable, optional): Module specifying the normalization layer to use.
      patch_embed_kernel (tuple of ints): The kernel of the convolution that patchifies the input.
      patch_embed_stride (tuple of ints): The stride of the convolution that patchifies the input.
      patch_embed_padding (tuple of ints): The padding of the convolution that patchifies the input.
docstr_tok: ["MViT","main","class",".","Args",":","spatial_size","(","tuple","of","ints",")",":","The","spacial","size","of","the","input","as","``","(","H",",","W",")","``",".","temporal_size","(","int",")",":","The","temporal","size","``","T","``","of","the","input",".","block_setting","(","sequence","of","MSBlockConfig",")",":","The","Network","structure",".","residual_pool","(","bool",")",":","If","True",",","use","MViTv2","pooling","residual","connection",".","residual_with_cls_embed","(","bool",")",":","If","True",",","the","addition","on","the","residual","connection","will","include","the","class","embedding",".","rel_pos_embed","(","bool",")",":","If","True",",","use","MViTv2","'s","relative","positional","embeddings",".","proj_after_attn","(","bool",")",":","If","True",",","apply","the","projection","after","the","attention",".","dropout","(","float",")",":","Dropout","rate",".","Default",":","0.0.","attention_dropout","(","float",")",":","Attention","dropout","rate",".","Default",":","0.0.","stochastic_depth_prob",":","(","float",")",":","Stochastic","depth","rate",".","Default",":","0.0.","num_classes","(","int",")",":","The","number","of","classes",".","block","(","callable",",","optional",")",":","Module","specifying","the","layer","which","consists","of","the","attention","and","mlp",".","norm_layer","(","callable",",","optional",")",":","Module","specifying","the","normalization","layer","to","use",".","patch_embed_kernel","(","tuple","of","ints",")",":","The","kernel","of","the","convolution","that","patchifies","the","input",".","patch_embed_stride","(","tuple","of","ints",")",":","The","stride","of","the","convolution","that","patchifies","the","input",".","patch_embed_padding","(","tuple","of","ints",")",":","The","padding","of","the","convolution","that","patchifies","the","input","."]
code: def __init__(
      self,
      spatial_size: Tuple[int, int],
      temporal_size: int,
      block_setting: Sequence[MSBlockConfig],
      residual_pool: bool,
      residual_with_cls_embed: bool,
      rel_pos_embed: bool,
      proj_after_attn: bool,
      dropout: float = 0.5,
      attention_dropout: float = 0.0,
      stochastic_depth_prob: float = 0.0,
      num_classes: int = 400,
      block: Optional[Callable[..., nn.Module]] = None,
      norm_layer: Optional[Callable[..., nn.Module]] = None,
      patch_embed_kernel: Tuple[int, int, int] = (3, 7, 7),
      patch_embed_stride: Tuple[int, int, int] = (2, 4, 4),
      patch_embed_padding: Tuple[int, int, int] = (1, 3, 3),
  ) -> None:
      """
      MViT main class.
  
      Args:
          spatial_size (tuple of ints): The spacial size of the input as ``(H, W)``.
          temporal_size (int): The temporal size ``T`` of the input.
          block_setting (sequence of MSBlockConfig): The Network structure.
          residual_pool (bool): If True, use MViTv2 pooling residual connection.
          residual_with_cls_embed (bool): If True, the addition on the residual connection will include
              the class embedding.
          rel_pos_embed (bool): If True, use MViTv2's relative positional embeddings.
          proj_after_attn (bool): If True, apply the projection after the attention.
          dropout (float): Dropout rate. Default: 0.0.
          attention_dropout (float): Attention dropout rate. Default: 0.0.
          stochastic_depth_prob: (float): Stochastic depth rate. Default: 0.0.
          num_classes (int): The number of classes.
          block (callable, optional): Module specifying the layer which consists of the attention and mlp.
          norm_layer (callable, optional): Module specifying the normalization layer to use.
          patch_embed_kernel (tuple of ints): The kernel of the convolution that patchifies the input.
          patch_embed_stride (tuple of ints): The stride of the convolution that patchifies the input.
          patch_embed_padding (tuple of ints): The padding of the convolution that patchifies the input.
      """
      super().__init__()
      # This implementation employs a different parameterization scheme than the one used at PyTorch Video:
      # https://github.com/facebookresearch/pytorchvideo/blob/718d0a4/pytorchvideo/models/vision_transformers.py
      # We remove any experimental configuration that didn't make it to the final variants of the models. To represent
      # the configuration of the architecture we use the simplified form suggested at Table 1 of the paper.
      _log_api_usage_once(self)
      total_stage_blocks = len(block_setting)
      if total_stage_blocks == 0:
          raise ValueError(
              "The configuration parameter can't be empty."
          )
  
      if block is None:
          block = MultiscaleBlock
  
      if norm_layer is None:
          norm_layer = partial(nn.LayerNorm, eps=1e-6)
  
      # Patch Embedding module
      self.conv_proj = nn.Conv3d(
          in_channels=3,
          out_channels=block_setting[0].input_channels,
          kernel_size=patch_embed_kernel,
          stride=patch_embed_stride,
          padding=patch_embed_padding,
      )
  
      input_size = [
          size // stride
          for size, stride in zip(
              (temporal_size,) + spatial_size, self.conv_proj.stride
          )
      ]
  
      # Spatio-Temporal Class Positional Encoding
      self.pos_encoding = PositionalEncoding(
          embed_size=block_setting[0].input_channels,
          spatial_size=(input_size[1], input_size[2]),
          temporal_size=input_size[0],
          rel_pos_embed=rel_pos_embed,
      )
  
      # Encoder module
      self.blocks = nn.ModuleList()
      for stage_block_id, cnf in enumerate(block_setting):
          # adjust stochastic depth probability based on the depth of the stage block
          sd_prob = (
              stochastic_depth_prob
              * stage_block_id
              / (total_stage_blocks - 1.0)
          )
  
          self.blocks.append(
              block(
                  input_size=input_size,
                  cnf=cnf,
                  residual_pool=residual_pool,
                  residual_with_cls_embed=residual_with_cls_embed,
                  rel_pos_embed=rel_pos_embed,
                  proj_after_attn=proj_after_attn,
                  dropout=attention_dropout,
                  stochastic_depth_prob=sd_prob,
                  norm_layer=norm_layer,
              )
          )
  
          if len(cnf.stride_q) > 0:
              input_size = [
                  size // stride
                  for size, stride in zip(input_size, cnf.stride_q)
              ]
      self.norm = norm_layer(block_setting[-1].output_channels)
  
      # Classifier module
      self.head = nn.Sequential(
          nn.Dropout(dropout, inplace=True),
          nn.Linear(block_setting[-1].output_channels, num_classes),
      )
  
      for m in self.modules():
          if isinstance(m, nn.Linear):
              nn.init.trunc_normal_(m.weight, std=0.02)
              if isinstance(m, nn.Linear) and m.bias is not None:
                  nn.init.constant_(m.bias, 0.0)
          elif isinstance(m, nn.LayerNorm):
              if m.weight is not None:
                  nn.init.constant_(m.weight, 1.0)
              if m.bias is not None:
                  nn.init.constant_(m.bias, 0.0)
          elif isinstance(m, PositionalEncoding):
              for weights in m.parameters():
                  nn.init.trunc_normal_(weights, std=0.02)
  
imports: import math
  from dataclasses import dataclass
  from functools import partial
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple
  import torch
  import torch.fx
  import torch.nn
  from ...ops import MLP, StochasticDepth
  from ...transforms._presets import VideoClassification
  from ...utils import _log_api_usage_once
  from .._api import register_model, Weights, WeightsEnum
  from .._meta import _KINETICS400_CATEGORIES
  from .._utils import _ovewrite_named_param, handle_legacy_interface
label_desc: Use image node_id 1 to create a new MViT object from inherited base classes: nn with example: obj = MViT(spatial_size, temporal_size, block_setting, residual_pool, residual_with_cls_embed, rel_pos_embed, proj_after_attn, dropout, attention_dropout, stochastic_depth_prob, num_classes, block, norm_layer, patch_embed_kernel, patch_embed_stride, patch_embed_padding)