Models / vit-base-patch16-224

ViT-Base/16 224

Google's Vision Transformer for ImageNet-1k classification: 16-pixel patches of a 224-pixel image, 12 layers of width 768.

86.6M parametersvitApache-2.0image-classificationvisionencoder-only

The forward entry with one level of blocks expanded. Every edge carries the tensor type the compiler inferred at that point, in the model's own generics.

ViT-Base/16 224: forwardViT-Base/16 224: forward

Entries ​

EntrySignature
forwardforward<B: Dim>(image: Tensor[B, Channels, Height, Width; T]) -> Tensor[B, Classes; T]

Generics ​

The root block's generics as this checkpoint binds them.

Height224
Width224
Channels3
Patch16
D768
Heads12
Inner3072
Layers12
Classes1000
Tf32

Blocks ​

Every block of the program with its members and functions, as linnet inspect prints them.

Attention ​

text
vit::Attention<D: Dim, Heads: Dim, T: Float>
  sub query: Linear<D, D, T>
  sub key: Linear<D, D, T>
  sub value: Linear<D, D, T>
  sub out: Linear<D, D, T>
  pub fn forward<B: Dim, N: Dim>(x: Tensor[B, N, D; T]) -> Tensor[B, N, D; T]

EncoderLayer ​

text
vit::EncoderLayer<D: Dim, Heads: Dim, Inner: Dim, T: Float>
  sub norm_before: LayerNorm<D, T>
  sub attention: Attention<D, Heads, T>
  sub norm_after: LayerNorm<D, T>
  sub up: Linear<D, Inner, T>
  sub down: Linear<Inner, D, T>
  pub fn forward<B: Dim, N: Dim>(x: Tensor[B, N, D; T]) -> Tensor[B, N, D; T]

LayerNorm ​

text
vit::LayerNorm<D: Dim, T: Float>
  param weight: Tensor[D; T]
  param bias: Tensor[D; T]
  pub fn forward<*S: Shape>(x: Tensor[*S, D; T]) -> Tensor[*S, D; T]

Linear ​

text
std.nn.linear::Linear<In: Dim, Out: Dim, T: Float = bf16>
  param weight: Tensor[Out, In; T]
  param bias: Tensor[Out; T]?
  pub fn forward<*S: Shape>(x: Tensor[*S, In; T]) -> Tensor[*S, Out; T]

Model ​

text
vit::Model<Height: Dim, Width: Dim, Channels: Dim, Patch: Dim, D: Dim, Heads: Dim, Inner: Dim, Layers: Dim, Classes: Dim, T: Float = f32>
  param patch_weight: Tensor[D, Channels, Patch, Patch; T]
  param patch_bias: Tensor[D; T]
  param class_token: Tensor[1, 1, D; T]
  param positions: Tensor[1, 1 + (Height / Patch) * (Width / Patch), D; T]
  sub layers: [EncoderLayer<D, Heads, Inner, T>; Layers]
  sub norm: LayerNorm<D, T>
  sub head: Linear<D, Classes, T>
  pub entry forward<B: Dim>(image: Tensor[B, Channels, Height, Width; T]) -> Tensor[B, Classes; T]
  fn embed<B: Dim>(image: Tensor[B, Channels, Height, Width; T]) -> Tensor[B, (Height / Patch) * (Width / Patch), D; T]

RmsNorm ​

text
std.nn.norm::RmsNorm<H: Dim, T: Float = bf16>
  param weight: Tensor[H; T]
  pub fn forward<*S: Shape>(x: Tensor[*S, H; T]) -> Tensor[*S, H; T]