class_docstr: This class defines the `MobileViTv2 <https://arxiv.org/abs/2206.02680>`_ block
  
  Args:
      opts: command line arguments
      in_channels (int): :math:`C_{in}` from an expected input of size :math:`(N, C_{in}, H, W)`
      attn_unit_dim (int): Input dimension to the attention unit
      ffn_multiplier (int): Expand the input dimensions by this factor in FFN. Default is 2.
      n_attn_blocks (Optional[int]): Number of attention units. Default: 2
      attn_dropout (Optional[float]): Dropout in multi-head attention. Default: 0.0
      dropout (Optional[float]): Dropout rate. Default: 0.0
      ffn_dropout (Optional[float]): Dropout between FFN layers in transformer. Default: 0.0
      patch_h (Optional[int]): Patch height for unfolding operation. Default: 8
      patch_w (Optional[int]): Patch width for unfolding operation. Default: 8
      conv_ksize (Optional[int]): Kernel size to learn local representations in MobileViT block. Default: 3
      dilation (Optional[int]): Dilation rate in convolutions. Default: 1
      attn_norm_layer (Optional[str]): Normalization layer in the attention block. Default: layer_norm_2d
code: def __init__(
      self,
      opts,
      in_channels: int,
      attn_unit_dim: int,
      ffn_multiplier: Optional[
          Union[Sequence[Union[int, float]], int, float]
      ] = 2.0,
      n_attn_blocks: Optional[int] = 2,
      attn_dropout: Optional[float] = 0.0,
      dropout: Optional[float] = 0.0,
      ffn_dropout: Optional[float] = 0.0,
      patch_h: Optional[int] = 8,
      patch_w: Optional[int] = 8,
      conv_ksize: Optional[int] = 3,
      dilation: Optional[int] = 1,
      attn_norm_layer: Optional[str] = "layer_norm_2d",
      *args,
      **kwargs,
  ) -> None:
      cnn_out_dim = attn_unit_dim
  
      conv_3x3_in = ConvLayer2d(
          opts=opts,
          in_channels=in_channels,
          out_channels=in_channels,
          kernel_size=conv_ksize,
          stride=1,
          use_norm=True,
          use_act=True,
          dilation=dilation,
          groups=in_channels,
      )
      conv_1x1_in = ConvLayer2d(
          opts=opts,
          in_channels=in_channels,
          out_channels=cnn_out_dim,
          kernel_size=1,
          stride=1,
          use_norm=False,
          use_act=False,
      )
  
      super(MobileViTBlockv2, self).__init__()
      self.local_rep = nn.Sequential(conv_3x3_in, conv_1x1_in)
  
      self.global_rep, attn_unit_dim = self._build_attn_layer(
          opts=opts,
          d_model=attn_unit_dim,
          ffn_mult=ffn_multiplier,
          n_layers=n_attn_blocks,
          attn_dropout=attn_dropout,
          dropout=dropout,
          ffn_dropout=ffn_dropout,
          attn_norm_layer=attn_norm_layer,
      )
  
      self.conv_proj = ConvLayer2d(
          opts=opts,
          in_channels=cnn_out_dim,
          out_channels=in_channels,
          kernel_size=1,
          stride=1,
          use_norm=True,
          use_act=False,
      )
  
      self.patch_h = patch_h
      self.patch_w = patch_w
      self.patch_area = self.patch_w * self.patch_h
  
      self.cnn_in_dim = in_channels
      self.cnn_out_dim = cnn_out_dim
      self.transformer_in_dim = attn_unit_dim
      self.dropout = dropout
      self.attn_dropout = attn_dropout
      self.ffn_dropout = ffn_dropout
      self.n_blocks = n_attn_blocks
      self.conv_ksize = conv_ksize
      self.enable_coreml_compatible_fn = getattr(
          opts, "common.enable_coreml_compatible_module", False
      )
  
      if self.enable_coreml_compatible_fn:
          # we set persistent to false so that these weights are not part of model's state_dict
          self.register_buffer(
              name="unfolding_weights",
              tensor=self._compute_unfolding_weights(),
              persistent=False,
          )
  
imports: import math
  from typing import Dict, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  from torch import Tensor, nn
  from torch.nn import functional
  from cvnets.layers import ConvLayer2d, get_normalization_layer
  from cvnets.modules.base_module import BaseModule
  from cvnets.modules.transformer import LinearAttnFFN, TransformerEncoder
label_desc: Use image node_id 1 to create a new MobileViTBlockv2 object from inherited base classes: BaseModule with example: obj = MobileViTBlockv2(opts, in_channels, attn_unit_dim, ffn_multiplier, n_attn_blocks, attn_dropout, dropout, ffn_dropout, patch_h, patch_w, conv_ksize, dilation, attn_norm_layer)