class_docstr: Vision Transformer with support for patch or hybrid CNN input stage
      
class_docstr_tok: ["Vision","Transformer","with","support","for","patch","or","hybrid","CNN","input","stage"]
code: def __init__(
      self,
      img_size: Union[int, Tuple[int, int]] = 224,
      patch_size: Union[int, Tuple[int, int]] = 16,
      in_chans: int = 3,
      num_classes: int = 1000,
      global_pool: str = "avg",
      embed_dim: int = 768,
      depth: int = 12,
      num_heads: int = 12,
      qkv_bias: bool = True,
      mlp_ratio: float = 4.0,
      swiglu_mlp: bool = False,
      scale_mlp: bool = False,
      drop_rate: float = 0.0,
      pos_drop_rate: float = 0.0,
      proj_drop_rate: float = 0.0,
      attn_drop_rate: float = 0.0,
      drop_path_rate: float = 0.0,
      norm_layer: Callable = LayerNorm,
      init_values: Optional[float] = None,
      use_abs_pos_emb: bool = True,
      use_rel_pos_bias: bool = False,
      use_shared_rel_pos_bias: bool = False,
      head_init_scale: float = 0.001,
  ):
      super().__init__()
      self.num_classes = num_classes
      self.global_pool = global_pool
      self.num_features = (
          self.embed_dim
      ) = embed_dim  # num_features for consistency with other models
      self.num_prefix_tokens = 1
      self.grad_checkpointing = False
  
      self.patch_embed = PatchEmbed(
          img_size=img_size,
          patch_size=patch_size,
          in_chans=in_chans,
          embed_dim=embed_dim,
      )
      num_patches = self.patch_embed.num_patches
  
      self.cls_token = nn.Parameter(torch.zeros(1, 1, embed_dim))
      # self.mask_token = nn.Parameter(torch.zeros(1, 1, embed_dim))
      self.pos_embed = (
          nn.Parameter(torch.zeros(1, num_patches + 1, embed_dim))
          if use_abs_pos_emb
          else None
      )
      self.pos_drop = nn.Dropout(p=pos_drop_rate)
  
      if use_shared_rel_pos_bias:
          self.rel_pos_bias = RelativePositionBias(
              window_size=self.patch_embed.grid_size,
              num_heads=num_heads,
          )
      else:
          self.rel_pos_bias = None
  
      dpr = [
          x.item() for x in torch.linspace(0, drop_path_rate, depth)
      ]  # stochastic depth decay rule
      self.blocks = nn.ModuleList(
          [
              Block(
                  dim=embed_dim,
                  num_heads=num_heads,
                  qkv_bias=qkv_bias,
                  mlp_ratio=mlp_ratio,
                  scale_mlp=scale_mlp,
                  swiglu_mlp=swiglu_mlp,
                  proj_drop=proj_drop_rate,
                  attn_drop=attn_drop_rate,
                  drop_path=dpr[i],
                  norm_layer=norm_layer,
                  init_values=init_values,
                  window_size=self.patch_embed.grid_size
                  if use_rel_pos_bias
                  else None,
              )
              for i in range(depth)
          ]
      )
  
      use_fc_norm = self.global_pool == "avg"
      self.norm = (
          nn.Identity() if use_fc_norm else norm_layer(embed_dim)
      )
      self.fc_norm = (
          norm_layer(embed_dim) if use_fc_norm else nn.Identity()
      )
      self.head_drop = nn.Dropout(drop_rate)
      self.head = (
          nn.Linear(embed_dim, num_classes)
          if num_classes > 0
          else nn.Identity()
      )
  
      self.apply(self._init_weights)
      if self.pos_embed is not None:
          trunc_normal_(self.pos_embed, std=0.02)
      trunc_normal_(self.cls_token, std=0.02)
  
      self.fix_init_weight()
      if isinstance(self.head, nn.Linear):
          trunc_normal_(self.head.weight, std=0.02)
          self.head.weight.data.mul_(head_init_scale)
          self.head.bias.data.mul_(head_init_scale)
  
imports: import math
  from typing import Callable, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.utils.checkpoint import checkpoint
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import PatchEmbed, Mlp, SwiGLU, LayerNorm, DropPath, trunc_normal_, use_fused_attn
  from timm.layers import resample_patch_embed, resample_abs_pos_embed, resize_rel_pos_bias_table
  from ._builder import build_model_with_cfg
  from ._registry import generate_default_cfgs, register_model
  from .vision_transformer import checkpoint_filter_fn
label_desc: Use image node_id 1 to create a new Beit object from inherited base classes: nn with example: obj = Beit(img_size, patch_size, in_chans, num_classes, global_pool, embed_dim, depth, num_heads, qkv_bias, mlp_ratio, swiglu_mlp, scale_mlp, drop_rate, pos_drop_rate, proj_drop_rate, attn_drop_rate, drop_path_rate, norm_layer, init_values, use_abs_pos_emb, use_rel_pos_bias, use_shared_rel_pos_bias, head_init_scale)