code: def __init__(
      self,
      in_channels: int,
      latent_dims: List[int],
      *,
      num_heads_list: List[int],
      feedforward_dim_ratios: List[float],
      num_layers_list: List[int],
      reduction_ratios: List[int],
      dropout: float = 0.0,
      drop_path_rate: float = 0.1,
      norm_type: Optional[str] = "layer",
      **attention_kwargs: Any,
  ):
      super().__init__()
      # patch embeddings
      patch_embeds = []
      patch_in_channels = in_channels
      for i, (patch_size, stride) in enumerate(
          zip([7, 3, 3, 3], [4, 2, 2, 2])
      ):
          latent_dim = latent_dims[i]
          to_patches_config = {
              "img_size": 0,
              "patch_size": patch_size,
              "in_channels": patch_in_channels,
              "latent_dim": latent_dim,
              "stride": stride,
          }
          patch_embeds.append(
              ImgToPatches.make("overlap", to_patches_config)
          )
          patch_in_channels = latent_dim
      # transformer encoders
      total_num_layers = sum(num_layers_list)
      dpr = [
          x.item()
          for x in torch.linspace(0, drop_path_rate, total_num_layers)
      ]
      cursor = 0
      encoders = []
      attention_kwargs.setdefault("bias", True)
      for i, (latent_dim, num_heads) in enumerate(
          zip(latent_dims, num_heads_list)
      ):
          ff_ratio = feedforward_dim_ratios[i]
          num_layers = num_layers_list[i]
          ak = shallow_copy_dict(attention_kwargs)
          ak["num_heads"] = num_heads
          ak["reduction_ratio"] = reduction_ratios[i]
          encoders.append(
              MixedStackedEncoder(
                  latent_dim,
                  0,
                  token_mixing_type="attention",
                  token_mixing_config=ak,
                  channel_mixing_type="mix_ff",
                  num_layers=num_layers,
                  dropout=dropout,
                  dpr_list=dpr[cursor : cursor + num_layers],
                  norm_type=norm_type,
                  latent_dim_ratio=ff_ratio,
                  use_head_token=False,
                  head_pooler=None,
                  use_positional_encoding=False,
              )
          )
          cursor += num_layers
      # stages
      for i, (patch_embed, encoder) in enumerate(
          zip(patch_embeds, encoders)
      ):
          setattr(
              self, f"stage{i + 1}", MixViTBlock(patch_embed, encoder)
          )
  
file_path: carefree-learn/cflearn/models/cv/encoder/backbone/models/transformer.py
imports: import torch
  from torch import nn
  from typing import Any
  from typing import List
  from typing import Optional
  from cftool.misc import shallow_copy_dict
  from ..register import register_backbone
  from ......modules.blocks import ImgToPatches
  from ......modules.blocks import MixedStackedEncoder
label_desc: Use image node_id 1 to create a new MixViT object from inherited base classes: nn with example: obj = MixViT(in_channels, latent_dims)