class_docstr: TinyViT model, as described in https://arxiv.org/abs/2207.10666
  
  Args:
      img_size: Size of input image.
      in_chans: Number of input image's channels.
      num_classes: Number of output classes.
      embed_dims: List of embedding dimensions.
      depths: List of block count for each downsampling stage
      num_heads: List of attention heads used in self-attention for each downsampling stage.
      window_sizes: List of self-attention's window size for each downsampling stage.
      mlp_ratio: Ratio of MLP dimension to embedding dimension in self-attention.
      drop_rate: Dropout rate.
      drop_path_rate: Stochastic depth rate.
      use_checkpoint: Whether to use activation checkpointing to trade compute for memory.
      mbconv_expand_ratio: Expansion ratio used in MBConv block.
      local_conv_size: Kernel size of convolution used in TinyViTBlock
      activation: activation function.
      mobile_same: Whether to use modifications for MobileSAM.
class_docstr_tok: ["TinyViT","model",",","as","described","in","https",":","\/\/arxiv.org\/abs\/2207.10666","Args",":","img_size",":","Size","of","input","image",".","in_chans",":","Number","of","input","image","'s","channels",".","num_classes",":","Number","of","output","classes",".","embed_dims",":","List","of","embedding","dimensions",".","depths",":","List","of","block","count","for","each","downsampling","stage","num_heads",":","List","of","attention","heads","used","in","self-attention","for","each","downsampling","stage",".","window_sizes",":","List","of","self-attention","'s","window","size","for","each","downsampling","stage",".","mlp_ratio",":","Ratio","of","MLP","dimension","to","embedding","dimension","in","self-attention",".","drop_rate",":","Dropout","rate",".","drop_path_rate",":","Stochastic","depth","rate",".","use_checkpoint",":","Whether","to","use","activation","checkpointing","to","trade","compute","for","memory",".","mbconv_expand_ratio",":","Expansion","ratio","used","in","MBConv","block",".","local_conv_size",":","Kernel","size","of","convolution","used","in","TinyViTBlock","activation",":","activation","function",".","mobile_same",":","Whether","to","use","modifications","for","MobileSAM","."]
docstr: Create a TinyViT model from pre-defined variants.
  
  Args:
      variant: TinyViT variant. Possible values: ``'5m'``, ``'11m'``, ``'21m'``.
      pretrained: whether to use pre-trained weights. Possible values: ``False``, ``True``, ``'in22k'``,
          ``'in1k'``. For TinyViT-21M (``variant='21m'``), ``'in1k_384'``, ``'in1k_512'`` are also available.
      **kwargs: other keyword arguments that will be passed to :class:`TinyViT`.
  
  .. note::
      When ``img_size`` is different from the pre-trained size, bicubic interpolation will be performed on
      attention biases. When using ``pretrained=True``, ImageNet-1k checkpoint (``'in1k'``) is used.
      For feature extraction or fine-tuning, ImageNet-22k checkpoint (``'in22k'``) is preferred.
code: def from_config(
      variant: str, pretrained: bool | str = False, **kwargs: Any
  ) -> TinyViT:
      """Create a TinyViT model from pre-defined variants.
  
      Args:
          variant: TinyViT variant. Possible values: ``'5m'``, ``'11m'``, ``'21m'``.
          pretrained: whether to use pre-trained weights. Possible values: ``False``, ``True``, ``'in22k'``,
              ``'in1k'``. For TinyViT-21M (``variant='21m'``), ``'in1k_384'``, ``'in1k_512'`` are also available.
          **kwargs: other keyword arguments that will be passed to :class:`TinyViT`.
  
      .. note::
          When ``img_size`` is different from the pre-trained size, bicubic interpolation will be performed on
          attention biases. When using ``pretrained=True``, ImageNet-1k checkpoint (``'in1k'``) is used.
          For feature extraction or fine-tuning, ImageNet-22k checkpoint (``'in22k'``) is preferred.
      """
      KORNIA_CHECK(
          variant in ("5m", "11m", "21m"),
          "Only variant 5m, 11m, and 21m are supported",
      )
      return {
          "5m": _tiny_vit_5m,
          "11m": _tiny_vit_11m,
          "21m": _tiny_vit_21m,
      }[variant](pretrained, **kwargs)
  
imports: from __future__ import annotations
  import itertools
  import warnings
  from typing import Any, Optional
  import torch
  import torch.nn.functional
  from torch import nn
  from torch.utils import checkpoint
  from kornia.contrib.models.common import DropPath, LayerNorm2d, window_partition, window_unpartition
  from kornia.core import Module, Tensor
  from kornia.core.check import KORNIA_CHECK
label_desc: Use image node_id 3 for calling the TinyViT obj's underlying member method code with example usage: obj.from_config(variant, pretrained) and returns: dict