Inferensys

Glossary

Vision Transformer (ViT)

A model that applies a pure transformer architecture directly to sequences of image patches for image classification and feature extraction.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
COMPUTER VISION ARCHITECTURE

What is Vision Transformer (ViT)?

A Vision Transformer (ViT) is a neural network architecture that applies a pure transformer model directly to sequences of image patches for image classification and feature extraction, treating an image as a sequence of visual tokens analogous to words in NLP.

The Vision Transformer (ViT) operates by first dividing an input image into a grid of fixed-size patches, which are then linearly embedded into a sequence of vectors. A learnable [CLS] token is prepended to this sequence, and standard positional embeddings are added to retain spatial information. This sequence is subsequently processed by a standard transformer encoder, which applies multi-headed self-attention to model global relationships between all patches simultaneously.

Unlike convolutional neural networks (CNNs), ViT contains no explicit inductive biases for locality or translation equivariance, relying instead on the self-attention mechanism to learn spatial hierarchies from data. When pre-trained on sufficiently large datasets like JFT-300M and then fine-tuned, ViT achieves state-of-the-art performance on image recognition benchmarks, demonstrating that a pure attention-based architecture can effectively replace convolution for computer vision tasks.

PURE TRANSFORMER FOR VISION

Key Architectural Features of ViT

The Vision Transformer (ViT) departs from convolutional inductive biases, applying a standard Transformer encoder directly to sequences of image patches. This architecture achieves state-of-the-art performance on image classification benchmarks when pre-trained on sufficiently large datasets.

01

Patch Embedding and Linear Projection

The input image is divided into a grid of fixed-size, non-overlapping patches (e.g., 16x16 pixels). Each patch is flattened into a 1D vector and linearly projected to a constant latent vector size, creating a sequence of 'visual tokens' analogous to word embeddings in NLP. A learnable [CLS] token is prepended to this sequence, and 1D positional embeddings are added to retain spatial information.

02

Standard Transformer Encoder

The sequence of patch embeddings is processed by a standard Transformer encoder, identical to the architecture proposed in 'Attention Is All You Need'. This stack consists of alternating layers of:

  • Multi-Head Self-Attention (MSA): Allows every patch to attend to every other patch globally from the very first layer.
  • MLP Block: A two-layer feed-forward network with GELU activation. Layer Normalization is applied before each block (pre-norm), and residual connections are used throughout.
03

Global Self-Attention Mechanism

Unlike CNNs that build receptive fields locally and hierarchically, ViT employs global self-attention from the outset. This allows the model to immediately model long-range dependencies between distant image regions. The attention mechanism computes weighted sums of values based on the similarity between queries and keys, enabling the model to integrate information across the entire image in a single layer.

04

Classification Head via [CLS] Token

A learnable [CLS] token embedding is prepended to the input sequence. The final hidden state corresponding to this token serves as the aggregate image representation. This state is passed through a simple MLP classification head to produce the final class prediction. This design mirrors BERT's approach, where the [CLS] token acts as a summary of the entire input sequence.

05

Hybrid Architecture Variant

The input sequence can be formed from feature maps produced by a standard CNN instead of raw image patches. In this hybrid model, the CNN backbone extracts spatial features, and the resulting feature map is flattened into a sequence for the Transformer. This combines the local feature extraction strength of convolutions with the global reasoning of self-attention.

06

Inductive Bias and Scaling Properties

ViT has significantly less image-specific inductive bias than CNNs. Only the patch extraction and positional embeddings inject locality and spatial structure. Consequently, ViT does not inherently understand translation equivariance or locality and must learn these from data. This makes ViT highly data-hungry, requiring pre-training on massive datasets like JFT-300M to outperform CNNs, but it scales more effectively with model and data size.

VISION TRANSFORMER (VIT) FAQ

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the Vision Transformer architecture, its mechanisms, and its role in modern computer vision.

A Vision Transformer (ViT) is a neural network architecture that applies a pure transformer model directly to sequences of image patches for image classification. Unlike convolutional neural networks (CNNs), ViT discards convolution entirely. The process begins by splitting an input image into fixed-size, non-overlapping patches (e.g., 16x16 pixels). Each patch is linearly projected into a flat vector, creating a sequence of patch embeddings. A learnable [class] token is prepended to this sequence, and standard positional embeddings are added to retain spatial information. This sequence is then fed into a standard transformer encoder, which uses multi-headed self-attention to model global relationships between all patches simultaneously. The final representation of the [class] token is passed to a classification head. This mechanism allows ViT to capture long-range dependencies across the entire image from the very first layer, a key differentiator from the local receptive fields of CNNs.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.