class_docstr: Visual Transformer with Prompt. This class add prompts to a visual
  transformer to implement the Method Learning to Prompt (L2P)
  
  Implementation based on VisionTransformer from timm library
class_docstr_tok: ["Visual","Transformer","with","Prompt",".","This","class","add","prompts","to","a","visual","transformer","to","implement","the","Method","Learning","to","Prompt","(","L2P",")","Implementation","based","on","VisionTransformer","from","timm","library"]
docstr: Args:
      img_size (int, tuple): input image size
      patch_size (int, tuple): patch size
      in_chans (int): number of input channels
      num_classes (int): number of classes for classification head
      global_pool (str): type of global pooling for final sequence
      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
      init_values: (float): layer-scale init values
      class_token (bool): use class token
      fc_norm (Optional[bool]): pre-fc norm after pool
      drop_rate (float): dropout rate
      attn_drop_rate (float): attention dropout rate
      drop_path_rate (float): stochastic depth rate
      weight_init (str): weight init scheme
      embed_layer (nn.Module): patch embedding layer
      norm_layer: (nn.Module): normalization layer
      act_layer: (nn.Module): MLP activation layer
      block_fn: (nn.Module): transformer block
      prompt_pool (bool): use prompt pool or not
docstr_tok: ["Args",":","img_size","(","int",",","tuple",")",":","input","image","size","patch_size","(","int",",","tuple",")",":","patch","size","in_chans","(","int",")",":","number","of","input","channels","num_classes","(","int",")",":","number","of","classes","for","classification","head","global_pool","(","str",")",":","type","of","global","pooling","for","final","sequence","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","init_values",":","(","float",")",":","layer-scale","init","values","class_token","(","bool",")",":","use","class","token","fc_norm","(","Optional","[","bool","]",")",":","pre-fc","norm","after","pool","drop_rate","(","float",")",":","dropout","rate","attn_drop_rate","(","float",")",":","attention","dropout","rate","drop_path_rate","(","float",")",":","stochastic","depth","rate","weight_init","(","str",")",":","weight","init","scheme","embed_layer","(","nn.Module",")",":","patch","embedding","layer","norm_layer",":","(","nn.Module",")",":","normalization","layer","act_layer",":","(","nn.Module",")",":","MLP","activation","layer","block_fn",":","(","nn.Module",")",":","transformer","block","prompt_pool","(","bool",")",":","use","prompt","pool","or","not"]
code: def __init__(
      self,
      img_size=224,
      patch_size=16,
      in_chans=3,
      num_classes=1000,
      global_pool="token",
      embed_dim=768,
      depth=12,
      num_heads=12,
      mlp_ratio=4.0,
      qkv_bias=True,
      init_values=None,
      class_token=True,
      no_embed_class=False,
      pre_norm=False,
      fc_norm=None,
      drop_rate=0.0,
      attn_drop_rate=0.0,
      drop_path_rate=0.0,
      weight_init="",
      embed_layer=PatchEmbed,
      norm_layer=None,
      act_layer=None,
      block_fn=Block,
      prompt_length=None,
      embedding_key="cls",
      prompt_init="uniform",
      prompt_pool=False,
      prompt_key=False,
      pool_size=None,
      top_k=None,
      batchwise_prompt=False,
      prompt_key_init="uniform",
      head_type="token",
      use_prompt_mask=False,
  ):
      """
      Args:
          img_size (int, tuple): input image size
          patch_size (int, tuple): patch size
          in_chans (int): number of input channels
          num_classes (int): number of classes for classification head
          global_pool (str): type of global pooling for final sequence
          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
          init_values: (float): layer-scale init values
          class_token (bool): use class token
          fc_norm (Optional[bool]): pre-fc norm after pool
          drop_rate (float): dropout rate
          attn_drop_rate (float): attention dropout rate
          drop_path_rate (float): stochastic depth rate
          weight_init (str): weight init scheme
          embed_layer (nn.Module): patch embedding layer
          norm_layer: (nn.Module): normalization layer
          act_layer: (nn.Module): MLP activation layer
          block_fn: (nn.Module): transformer block
          prompt_pool (bool): use prompt pool or not
      """
      super().__init__(
          img_size=img_size,
          patch_size=patch_size,
          in_chans=in_chans,
          num_classes=num_classes,
          global_pool=global_pool,
          embed_dim=embed_dim,
          depth=depth,
          num_heads=num_heads,
          mlp_ratio=mlp_ratio,
          qkv_bias=qkv_bias,
          init_values=init_values,
          class_token=class_token,
          no_embed_class=no_embed_class,
          pre_norm=pre_norm,
          fc_norm=fc_norm,
          drop_rate=drop_rate,
          attn_drop_rate=attn_drop_rate,
          drop_path_rate=drop_path_rate,
          weight_init=weight_init,
          embed_layer=embed_layer,
          norm_layer=norm_layer,
          act_layer=act_layer,
          block_fn=block_fn,
      )
  
      self.class_token = class_token
      num_patches = self.patch_embed.num_patches
  
      if no_embed_class:
          embed_len = num_patches
      else:
          embed_len = num_patches + self.num_prefix_tokens
  
      if (
          prompt_length is not None
          and pool_size is not None
          and prompt_pool
      ):
          embed_len += prompt_length * top_k
      self.pos_embed = nn.Parameter(
          torch.randn(1, embed_len, embed_dim) * 0.02
      )
      self.pos_drop = nn.Dropout(p=drop_rate)
  
      self.prompt_pool = prompt_pool
      self.head_type = head_type
      self.use_prompt_mask = use_prompt_mask
  
      if (
          prompt_length is not None
          and pool_size is not None
          and prompt_pool
      ):
          self.prompt = Prompt(
              length=prompt_length,
              embed_dim=embed_dim,
              embedding_key=embedding_key,
              prompt_init=prompt_init,
              prompt_pool=prompt_pool,
              prompt_key=prompt_key,
              pool_size=pool_size,
              top_k=top_k,
              batchwise_prompt=batchwise_prompt,
              prompt_key_init=prompt_key_init,
          )
  
      if num_classes > 0:
          self.head = nn.Linear(self.embed_dim, num_classes)
      else:
          self.head = nn.Identity()
  
      if weight_init != "skip":
          self.init_weights(weight_init)
  
file_path: avalanche/avalanche/models/timm_vit.py
imports: import math
  import re
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from avalanche.models import Prompt
label_desc: Use image node_id 1 to create a new ViTWithPrompt object from inherited base classes: VisionTransformer with example: obj = ViTWithPrompt(img_size, patch_size, in_chans, num_classes, global_pool, embed_dim, depth, num_heads, mlp_ratio, qkv_bias, init_values, class_token, no_embed_class, pre_norm, fc_norm, drop_rate, attn_drop_rate, drop_path_rate, weight_init, embed_layer, norm_layer, act_layer, block_fn, prompt_length, embedding_key, prompt_init, prompt_pool, prompt_key, pool_size, top_k, batchwise_prompt, prompt_key_init, head_type, use_prompt_mask)