class_docstr: Implementation of metaformer block with MHSA as token mixer.
  For more details on Metaformer structure, please refer to:
  `MetaFormer Is Actually What You Need for Vision <https://arxiv.org/pdf/2111.11418.pdf>`_
  
  Args:
      opts: Command line arguments.
      dim: Number of embedding dimensions.
      mlp_ratio: MLP expansion ratio. Default: 4.0
      drop: Dropout rate. Default: 0.0
      drop_path: Drop path rate. Default: 0.0
      use_layer_scale: Flag to turn on layer scale. Default: ``True``
      layer_scale_init_value: Layer scale value at initialization. Default: 1e-5
class_docstr_tok: ["Implementation","of","metaformer","block","with","MHSA","as","token","mixer",".","For","more","details","on","Metaformer","structure",",","please","refer","to",":","`","MetaFormer","Is","Actually","What","You","Need","for","Vision","<","https",":","\/\/arxiv.org\/pdf\/2111.11418.pdf",">","`","_","Args",":","opts",":","Command","line","arguments",".","dim",":","Number","of","embedding","dimensions",".","mlp_ratio",":","MLP","expansion","ratio",".","Default",":","4.0","drop",":","Dropout","rate",".","Default",":","0.0","drop_path",":","Drop","path","rate",".","Default",":","0.0","use_layer_scale",":","Flag","to","turn","on","layer","scale",".","Default",":","``","True","``","layer_scale_init_value",":","Layer","scale","value","at","initialization",".","Default",":","1e-5"]
code: def __init__(
      self,
      opts: argparse.Namespace,
      dim: int,
      mlp_ratio: float = 4.0,
      drop: float = 0.0,
      drop_path: float = 0.0,
      use_layer_scale: bool = True,
      layer_scale_init_value: float = 1e-5,
  ):
      super().__init__()
      self.norm = BatchNorm2d(num_features=dim)
      self.head_dim = 32
      num_heads = dim // self.head_dim
      self.token_mixer = MultiHeadAttention(
          embed_dim=dim, num_heads=num_heads, bias=False
      )
  
      assert (
          mlp_ratio > 0
      ), "MLP ratio should be greater than 0, found: {}".format(
          mlp_ratio
      )
      hidden_dim = int(dim * mlp_ratio)
      self.convffn = ConvFFN(
          opts, in_channels=dim, hidden_channels=hidden_dim, drop=drop
      )
  
      self.drop_path = (
          StochasticDepth(drop_path, mode="row")
          if drop_path > 0.0
          else nn.Identity()
      )
      self.use_layer_scale = use_layer_scale
      if use_layer_scale:
          self.layer_scale_1 = nn.Parameter(
              layer_scale_init_value * torch.ones((dim, 1, 1)),
          )
          self.layer_scale_2 = nn.Parameter(
              layer_scale_init_value * torch.ones((dim, 1, 1)),
          )
  
imports: import argparse
  from typing import Optional, Tuple, Union
  import torch
  import torch.nn
  from cvnets.layers import ConvLayer2d, MultiHeadAttention, StochasticDepth
  from cvnets.layers.normalization.batch_norm import BatchNorm2d
  from cvnets.modules import BaseModule
  from cvnets.modules.mobileone_block import MobileOneBlock, RepLKBlock
label_desc: Use image node_id 1 to create a new AttentionBlock object from inherited base classes: BaseModule with example: obj = AttentionBlock(opts, dim, mlp_ratio, drop, drop_path, use_layer_scale, layer_scale_init_value)