Vision Transformer (ViT)

Definition

The Vision Transformer (ViT) (Dosovitskiy et al., 2020; arXiv:2010.11929) applies a standard Transformer encoder directly to images by treating fixed-size image patches as the token sequence. No convolutions: chop the image into a grid, linearly embed each patch, add position embeddings, and run self-attention over the patches. The same scaled-dot-product attention op from language transfers unchanged — only the tokenizer (patchify + linear embed) is new.

Key math / How it works

Given an image and patch size , you get patches. Flatten each to and linearly embed with :

  • A learnable [CLS] token is prepended; after standard blocks its final state is the image representation for classification.
  • Position embeddings are required because attention is permutation-invariant — it must be told where each patch sits. (Contrast the 2D-RoPE / interpolated-absolute treatment in MoonViT.)
  • Each block is ordinary multi-head self-attention over the tokens, then an MLP.

The attention core costs

Patch count is a resolution knob with quadratic teeth. Halving patch size quadruples and 16בs the attention compute. Concretely, a image at gives patches; a image at gives patches before any compression.

Why it matters

In a language model, sequence length is set by the text. In a ViT, “sequence length” is set by resolution ÷ patch size — a design choice with quadratic cost. This is why native-/any-resolution encoders (navit-packing, moonvit) bolt on aggressive token compression, and why the visual token budget dominates the attention bill of a downstream VLM. ViT is the foundation of nearly every modern vision encoder and multimodal model.

Taught in

See also