code: def __init__(
      self,
      dim,
      dim_out,
      num_heads,
      feat_size,
      mlp_ratio=4.0,
      qkv_bias=True,
      drop_path=0.0,
      norm_layer=nn.LayerNorm,
      kernel_q=(1, 1),
      kernel_kv=(1, 1),
      stride_q=(1, 1),
      stride_kv=(1, 1),
      mode="conv",
      has_cls_token=True,
      expand_attn=False,
      pool_first=False,
      rel_pos_type="spatial",
      residual_pooling=True,
  ):
      super().__init__()
      proj_needed = dim != dim_out
      self.dim = dim
      self.dim_out = dim_out
      self.has_cls_token = has_cls_token
  
      self.norm1 = norm_layer(dim)
  
      self.shortcut_proj_attn = (
          nn.Linear(dim, dim_out)
          if proj_needed and expand_attn
          else None
      )
      if stride_q and prod(stride_q) > 1:
          kernel_skip = [s + 1 if s > 1 else s for s in stride_q]
          stride_skip = stride_q
          padding_skip = [int(skip // 2) for skip in kernel_skip]
          self.shortcut_pool_attn = nn.MaxPool2d(
              kernel_skip, stride_skip, padding_skip
          )
      else:
          self.shortcut_pool_attn = None
  
      att_dim = dim_out if expand_attn else dim
      attn_layer = (
          MultiScaleAttentionPoolFirst
          if pool_first
          else MultiScaleAttention
      )
      self.attn = attn_layer(
          dim,
          att_dim,
          num_heads=num_heads,
          feat_size=feat_size,
          qkv_bias=qkv_bias,
          kernel_q=kernel_q,
          kernel_kv=kernel_kv,
          stride_q=stride_q,
          stride_kv=stride_kv,
          norm_layer=norm_layer,
          has_cls_token=has_cls_token,
          mode=mode,
          rel_pos_type=rel_pos_type,
          residual_pooling=residual_pooling,
      )
      self.drop_path1 = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
  
      self.norm2 = norm_layer(att_dim)
      mlp_dim_out = dim_out
      self.shortcut_proj_mlp = (
          nn.Linear(dim, dim_out)
          if proj_needed and not expand_attn
          else None
      )
      self.mlp = Mlp(
          in_features=att_dim,
          hidden_features=int(att_dim * mlp_ratio),
          out_features=mlp_dim_out,
      )
      self.drop_path2 = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
  
imports: import operator
  from collections import OrderedDict
  from dataclasses import dataclass
  from functools import partial, reduce
  from typing import Union, List, Tuple, Optional
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import Mlp, DropPath, trunc_normal_tf_, get_norm_layer, to_2tuple
  from ._builder import build_model_with_cfg
  from ._features_fx import register_notrace_function
  from ._registry import register_model, register_model_deprecations, generate_default_cfgs
label_desc: Use image node_id 1 to create a new MultiScaleBlock object from inherited base classes: nn with example: obj = MultiScaleBlock(dim, dim_out, num_heads, feat_size, mlp_ratio, qkv_bias, drop_path, norm_layer, kernel_q, kernel_kv, stride_q, stride_kv, mode, has_cls_token, expand_attn, pool_first, rel_pos_type, residual_pooling)