code: def __init__(
      self,
      *,
      img_size: int,
      patch_size: int,
      in_channels: int,
      latent_channels: int = 384,
      to_patches_type: str = "vanilla",
      to_patches_config: Optional[Dict[str, Any]] = None,
      num_layers: int = 12,
      dropout: float = 0.0,
      drop_path_rate: float = 0.0,
      norm_type: Optional[str] = "layer",
      norm_kwargs: Optional[Dict[str, Any]] = None,
      embedding_norm: Optional[torch.nn.Module] = None,
      residual_after_norm: bool = False,
      feedforward_dim_ratio: float = 4.0,
      attention_kwargs: Optional[Dict[str, Any]] = None,
      feedforward_kwargs: Optional[Dict[str, Any]] = None,
      use_positional_encoding: bool = True,
      norm_after_head: bool = False,
  ):
      super().__init__(
          img_size=img_size,
          patch_size=patch_size,
          in_channels=in_channels,
          latent_channels=latent_channels,
          to_patches_type=to_patches_type,
          to_patches_config=to_patches_config,
      )
      if attention_kwargs is None:
          attention_kwargs = {}
      attention_kwargs.setdefault("bias", True)
      attention_kwargs.setdefault("num_heads", latent_channels // 64)
      self.encoder = MixedStackedEncoder(
          latent_channels,
          self.num_patches,
          token_mixing_type="attention",
          token_mixing_config=attention_kwargs,
          channel_mixing_config=feedforward_kwargs,
          num_layers=num_layers,
          dropout=dropout,
          drop_path_rate=drop_path_rate,
          norm_type=norm_type,
          norm_kwargs=norm_kwargs,
          embedding_norm=embedding_norm,
          residual_after_norm=residual_after_norm,
          latent_dim_ratio=feedforward_dim_ratio,
          head_pooler=None,
          use_head_token=False,
          use_positional_encoding=use_positional_encoding,
          is_vision_positional_encoding=True,
          norm_after_head=norm_after_head,
      )
  
file_path: carefree-learn/cflearn/models/cv/encoder/transformer.py
imports: import math
  import torch
  from torch import Tensor
  from typing import Any
  from typing import Dict
  from typing import List
  from typing import Optional
  from cftool.types import tensor_dict_type
  from .schema import Encoder1DFromPatches
  from .schema import Encoder2DFromPatches
  from ....constants import LATENT_KEY
  from ....modules.blocks import MixedStackedEncoder
label_desc: Use image node_id 1 to create a new ViTEncoder2D object from inherited base classes: Encoder2DFromPatches with example: obj = ViTEncoder2D()