docstr: Args:
      img_size (int, tuple): input image size
      patch_size (int, tuple): patch size
      in_chans (int): number of input channels
      embed_dim (int): embedding dimension
      depth (int): depth of transformer
      num_heads (int): number of attention heads
      mlp_ratio (int): ratio of mlp hidden dim to embedding dim
      qkv_bias (bool): enable bias for qkv if True
      proj_bias (bool): enable bias for proj in attn if True
      ffn_bias (bool): enable bias for ffn if True
      drop_path_rate (float): stochastic depth rate
      drop_path_uniform (bool): apply uniform drop rate across blocks
      weight_init (str): weight init scheme
      init_values (float): layer-scale init values
      embed_layer (nn.Module): patch embedding layer
      act_layer (nn.Module): MLP activation layer
      block_fn (nn.Module): transformer block class
      ffn_layer (str): "mlp", "swiglu", "swiglufused" or "identity"
      block_chunks: (int) split block sequence into block_chunks units for FSDP wrap
      num_register_tokens: (int) number of extra cls tokens (so-called "registers")
      interpolate_antialias: (str) flag to apply anti-aliasing when interpolating positional embeddings
      interpolate_offset: (float) work-around offset to apply when interpolating positional embeddings
docstr_tok: ["Args",":","img_size","(","int",",","tuple",")",":","input","image","size","patch_size","(","int",",","tuple",")",":","patch","size","in_chans","(","int",")",":","number","of","input","channels","embed_dim","(","int",")",":","embedding","dimension","depth","(","int",")",":","depth","of","transformer","num_heads","(","int",")",":","number","of","attention","heads","mlp_ratio","(","int",")",":","ratio","of","mlp","hidden","dim","to","embedding","dim","qkv_bias","(","bool",")",":","enable","bias","for","qkv","if","True","proj_bias","(","bool",")",":","enable","bias","for","proj","in","attn","if","True","ffn_bias","(","bool",")",":","enable","bias","for","ffn","if","True","drop_path_rate","(","float",")",":","stochastic","depth","rate","drop_path_uniform","(","bool",")",":","apply","uniform","drop","rate","across","blocks","weight_init","(","str",")",":","weight","init","scheme","init_values","(","float",")",":","layer-scale","init","values","embed_layer","(","nn.Module",")",":","patch","embedding","layer","act_layer","(","nn.Module",")",":","MLP","activation","layer","block_fn","(","nn.Module",")",":","transformer","block","class","ffn_layer","(","str",")",":","``","mlp","''",",","``","swiglu","''",",","``","swiglufused","''","or","``","identity","''","block_chunks",":","(","int",")","split","block","sequence","into","block_chunks","units","for","FSDP","wrap","num_register_tokens",":","(","int",")","number","of","extra","cls","tokens","(","so-called","``","registers","''",")","interpolate_antialias",":","(","str",")","flag","to","apply","anti-aliasing","when","interpolating","positional","embeddings","interpolate_offset",":","(","float",")","work-around","offset","to","apply","when","interpolating","positional","embeddings"]
code: def __init__(
      self,
      img_size=224,
      patch_size=16,
      in_chans=3,
      embed_dim=768,
      depth=12,
      num_heads=12,
      mlp_ratio=4.0,
      qkv_bias=True,
      ffn_bias=True,
      proj_bias=True,
      drop_path_rate=0.0,
      drop_path_uniform=False,
      init_values=None,  # for layerscale: None or 0 => no layerscale
      embed_layer=PatchEmbed,
      act_layer=nn.GELU,
      block_fn=Block,
      ffn_layer="mlp",
      block_chunks=1,
      num_register_tokens=0,
      interpolate_antialias=False,
      interpolate_offset=0.1,
  ):
      """
      Args:
          img_size (int, tuple): input image size
          patch_size (int, tuple): patch size
          in_chans (int): number of input channels
          embed_dim (int): embedding dimension
          depth (int): depth of transformer
          num_heads (int): number of attention heads
          mlp_ratio (int): ratio of mlp hidden dim to embedding dim
          qkv_bias (bool): enable bias for qkv if True
          proj_bias (bool): enable bias for proj in attn if True
          ffn_bias (bool): enable bias for ffn if True
          drop_path_rate (float): stochastic depth rate
          drop_path_uniform (bool): apply uniform drop rate across blocks
          weight_init (str): weight init scheme
          init_values (float): layer-scale init values
          embed_layer (nn.Module): patch embedding layer
          act_layer (nn.Module): MLP activation layer
          block_fn (nn.Module): transformer block class
          ffn_layer (str): "mlp", "swiglu", "swiglufused" or "identity"
          block_chunks: (int) split block sequence into block_chunks units for FSDP wrap
          num_register_tokens: (int) number of extra cls tokens (so-called "registers")
          interpolate_antialias: (str) flag to apply anti-aliasing when interpolating positional embeddings
          interpolate_offset: (float) work-around offset to apply when interpolating positional embeddings
      """
      super().__init__()
      norm_layer = partial(nn.LayerNorm, eps=1e-6)
  
      self.num_features = (
          self.embed_dim
      ) = embed_dim  # num_features for consistency with other models
      self.num_tokens = 1
      self.n_blocks = depth
      self.num_heads = num_heads
      self.patch_size = patch_size
      self.num_register_tokens = num_register_tokens
      self.interpolate_antialias = interpolate_antialias
      self.interpolate_offset = interpolate_offset
  
      self.patch_embed = embed_layer(
          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.pos_embed = nn.Parameter(
          torch.zeros(1, num_patches + self.num_tokens, embed_dim)
      )
      assert num_register_tokens >= 0
      self.register_tokens = (
          nn.Parameter(torch.zeros(1, num_register_tokens, embed_dim))
          if num_register_tokens
          else None
      )
  
      if drop_path_uniform is True:
          dpr = [drop_path_rate] * depth
      else:
          dpr = [
              x.item() for x in torch.linspace(0, drop_path_rate, depth)
          ]  # stochastic depth decay rule
  
      if ffn_layer == "mlp":
          logger.info("using MLP layer as FFN")
          ffn_layer = Mlp
      elif ffn_layer == "swiglufused" or ffn_layer == "swiglu":
          logger.info("using SwiGLU layer as FFN")
          ffn_layer = SwiGLUFFNFused
      elif ffn_layer == "identity":
          logger.info("using Identity layer as FFN")
  
          def f(*args, **kwargs):
              return nn.Identity()
  
          ffn_layer = f
      else:
          raise NotImplementedError
  
      blocks_list = [
          block_fn(
              dim=embed_dim,
              num_heads=num_heads,
              mlp_ratio=mlp_ratio,
              qkv_bias=qkv_bias,
              proj_bias=proj_bias,
              ffn_bias=ffn_bias,
              drop_path=dpr[i],
              norm_layer=norm_layer,
              act_layer=act_layer,
              ffn_layer=ffn_layer,
              init_values=init_values,
          )
          for i in range(depth)
      ]
      if block_chunks > 0:
          self.chunked_blocks = True
          chunked_blocks = []
          chunksize = depth // block_chunks
          for i in range(0, depth, chunksize):
              # this is to keep the block index consistent if we chunk the block list
              chunked_blocks.append(
                  [nn.Identity()] * i + blocks_list[i : i + chunksize]
              )
          self.blocks = nn.ModuleList(
              [BlockChunk(p) for p in chunked_blocks]
          )
      else:
          self.chunked_blocks = False
          self.blocks = nn.ModuleList(blocks_list)
  
      self.norm = norm_layer(embed_dim)
      self.head = nn.Identity()
  
      self.mask_token = nn.Parameter(torch.zeros(1, embed_dim))
  
      self.init_weights()
  
imports: from functools import partial
  import math
  import logging
  from typing import Sequence, Tuple, Union, Callable
  import torch
  import torch.nn
  import torch.utils.checkpoint
  from torch.nn.init import trunc_normal_
  from dinov2.layers import Mlp, PatchEmbed, SwiGLUFFNFused, MemEffAttention, NestedTensorBlock
label_desc: Use image node_id 1 to create a new DinoVisionTransformer object from inherited base classes: nn with example: obj = DinoVisionTransformer(img_size, patch_size, in_chans, embed_dim, depth, num_heads, mlp_ratio, qkv_bias, ffn_bias, proj_bias, drop_path_rate, drop_path_uniform, init_values, embed_layer, act_layer, block_fn, ffn_layer, block_chunks, num_register_tokens, interpolate_antialias, interpolate_offset)