code: def __init__(
      self,
      input_size: List[int],
      embed_dim: int,
      output_dim: int,
      num_heads: int,
      kernel_q: List[int],
      kernel_kv: List[int],
      stride_q: List[int],
      stride_kv: List[int],
      residual_pool: bool,
      residual_with_cls_embed: bool,
      rel_pos_embed: bool,
      dropout: float = 0.0,
      norm_layer: Callable[..., nn.Module] = nn.LayerNorm,
  ) -> None:
      super().__init__()
      self.embed_dim = embed_dim
      self.output_dim = output_dim
      self.num_heads = num_heads
      self.head_dim = output_dim // num_heads
      self.scaler = 1.0 / math.sqrt(self.head_dim)
      self.residual_pool = residual_pool
      self.residual_with_cls_embed = residual_with_cls_embed
  
      self.qkv = nn.Linear(embed_dim, 3 * output_dim)
      layers: List[nn.Module] = [nn.Linear(output_dim, output_dim)]
      if dropout > 0.0:
          layers.append(nn.Dropout(dropout, inplace=True))
      self.project = nn.Sequential(*layers)
  
      self.pool_q: Optional[nn.Module] = None
      if _prod(kernel_q) > 1 or _prod(stride_q) > 1:
          padding_q = [int(q // 2) for q in kernel_q]
          self.pool_q = Pool(
              nn.Conv3d(
                  self.head_dim,
                  self.head_dim,
                  kernel_q,  # type: ignore[arg-type]
                  stride=stride_q,  # type: ignore[arg-type]
                  padding=padding_q,  # type: ignore[arg-type]
                  groups=self.head_dim,
                  bias=False,
              ),
              norm_layer(self.head_dim),
          )
  
      self.pool_k: Optional[nn.Module] = None
      self.pool_v: Optional[nn.Module] = None
      if _prod(kernel_kv) > 1 or _prod(stride_kv) > 1:
          padding_kv = [int(kv // 2) for kv in kernel_kv]
          self.pool_k = Pool(
              nn.Conv3d(
                  self.head_dim,
                  self.head_dim,
                  kernel_kv,  # type: ignore[arg-type]
                  stride=stride_kv,  # type: ignore[arg-type]
                  padding=padding_kv,  # type: ignore[arg-type]
                  groups=self.head_dim,
                  bias=False,
              ),
              norm_layer(self.head_dim),
          )
          self.pool_v = Pool(
              nn.Conv3d(
                  self.head_dim,
                  self.head_dim,
                  kernel_kv,  # type: ignore[arg-type]
                  stride=stride_kv,  # type: ignore[arg-type]
                  padding=padding_kv,  # type: ignore[arg-type]
                  groups=self.head_dim,
                  bias=False,
              ),
              norm_layer(self.head_dim),
          )
  
      self.rel_pos_h: Optional[nn.Parameter] = None
      self.rel_pos_w: Optional[nn.Parameter] = None
      self.rel_pos_t: Optional[nn.Parameter] = None
      if rel_pos_embed:
          size = max(input_size[1:])
          q_size = size // stride_q[1] if len(stride_q) > 0 else size
          kv_size = size // stride_kv[1] if len(stride_kv) > 0 else size
          spatial_dim = 2 * max(q_size, kv_size) - 1
          temporal_dim = 2 * input_size[0] - 1
          self.rel_pos_h = nn.Parameter(
              torch.zeros(spatial_dim, self.head_dim)
          )
          self.rel_pos_w = nn.Parameter(
              torch.zeros(spatial_dim, self.head_dim)
          )
          self.rel_pos_t = nn.Parameter(
              torch.zeros(temporal_dim, self.head_dim)
          )
          nn.init.trunc_normal_(self.rel_pos_h, std=0.02)
          nn.init.trunc_normal_(self.rel_pos_w, std=0.02)
          nn.init.trunc_normal_(self.rel_pos_t, 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 MultiscaleAttention object from inherited base classes: nn with example: obj = MultiscaleAttention(input_size, embed_dim, output_dim, num_heads, kernel_q, kernel_kv, stride_q, stride_kv, residual_pool, residual_with_cls_embed, rel_pos_embed, dropout, norm_layer)