In one line: Split images into 16x16 patches and feed them to a vanilla Transformer; pre-trained on 300M JFT images, ViT-H/14 beats BiT-L on every benchmark and edges Noisy Student on ImageNet (88.55 vs 88.5) with about 4x less pre-training compute, while CNNs still win on smaller pre-training sets: at scale, data outweighs convolutional inductive bias.
Verdict: Believe the architecture and the direction: a plain Transformer on patches, pre-trained on enough data, matches or beats the 2020 CNNs, and every later vision tower is built this way. Treat "data trumps inductive bias" and the compute savings as tied to the 2020 training recipes: better recipes later trained ViTs well on ImageNet alone, and CNNs trained at the same scale match them. How much of this to believe
Cut the image into 16 × 16 patches, turn each patch into a token with one linear map, add a learned position and a class token, and run an unmodified Transformer encoder: with none of a CNN's built-in locality it loses on 1.3M training images and wins on 303M, at a quarter of the best CNN's pre-training compute.
An image becomes a sentence of patch tokens, and the class is read off one extra token. The paper's Figure 1 in 3D, run by this page's trained toy ViT (Run a ViT) on one 28 × 28 image (4 × 4 px patches, 49 tokens); drag it to turn it.
After the paper's Figure 1, redrawn (the arXiv paper is not CC BY, so no copy of the original). Token 0 is the learned class token; 1 to 49 are the patch tokens, numbered by position. Every bar is the shipped toy model's own number. ViT-B/16 does the same to a 224 × 224 image: 196 patches of 16 × 16 × 3 = 768 numbers, 197 tokens of width 768, 12 layers. Every step is Eq. 1 to 4 in Method; the same pipeline at CLIP B/32's real shapes is drawn on Vision encoders, which owns patch embeddings.
You need the Transformer encoder (The Transformer from zero); this page adds only what is different for images. Vision towers as they are built today are taught on Vision encoders: ViT, CLIP and SigLIP.
New terms. Patch embedding: one shared matrix E that maps a flattened patch to a token. Class token: a learned extra token whose output is the image representation. Inductive bias: an assumption built into the architecture (a CNN's locality) rather than learned. JFT-300M: Google's private set of 303M labelled images. BiT: Big Transfer, the ResNet baseline. Few-shot linear accuracy: a closed-form linear probe on frozen features. TPUv3-core-days: compute as cores times days.
By 2020 the Transformer was the default architecture in NLP, usually pre-trained on a large corpus and then fine-tuned, with models past 100B parameters and no sign of saturating (§1). Vision was still ruled by convolutional networks: ResNet-like models held the state of the art in large-scale image recognition (§1).
Earlier attempts to bring self-attention to images either kept the CNN skeleton and added or swapped in attention blocks, or replaced convolutions with specialised attention patterns (local neighbourhoods, sparse approximations, blocks, one axis at a time) that "require complex engineering to be implemented efficiently on hardware accelerators" and so had not been scaled (§2). Plain global attention over pixels is quadratic in the pixel count: a 224 × 224 image is 50,176 pixels, about 2.5 billion pairs per layer and head.
The question: can a plain, unmodified Transformer, with almost no image-specific inductive bias, compete with the best CNNs, and under what conditions?
(224 / 16)² = 14 × 14 = 196 patches; the paper adds one learnable class token, so 197 positions (§3.1). Attention pairs per layer and head fall from 50,176² ≈ 2.5 × 10⁹ to 197² ≈ 39,000, a factor of about 65,000. Smaller patches cost more: sequence length goes as 1/P², and attention pairs as 1/P⁴ (§4.1).
Try: move the patch size and the resolution. The grid is to scale; the counts are exact.
Patch sizes are the paper's (14, 16, 32) plus three smaller ones for comparison (1 is pixel attention, 2 is the size Cordonnier et al. used, §2, and 8); resolutions are pre-training (224), fine-tuning (384) and the Table 2 fine-tuning resolutions for ViT-L/16 (512) and ViT-H/14 (518), §4.1. When the side is not a multiple of P, the remainder is dropped, as a stride-P convolution would.
Turn the image into a sequence of tokens and run a completely standard Transformer encoder on it. "In model design we follow the original Transformer as closely as possible", so that scalable NLP architectures and their efficient implementations can be used almost out of the box (§3). Image patches are treated the same way as words: split the image into fixed-size patches, embed each linearly, add position embeddings, prepend a learnable classification token, and feed the sequence to the encoder (Figure 1). The model is trained to classify images, supervised.
The bet is about data, not architecture. Without the CNN's built-in assumptions the authors expect, and find, worse results on mid-sized datasets such as ImageNet; with 14M to 300M images "large scale training trumps inductive bias" (§1).
An image x ∈ ℝH×W×C becomes N = HW/P² flattened P × P patches of P²·C numbers each; N is the sequence length, and P is 16 or 32 (14 for ViT-H). One trainable linear projection E maps each patch to the model width D, constant through all layers: the patch embeddings (§3.1, §4.1).
Figure 1 at the top runs these four equations on the toy image, step by step.
CNNs build three assumptions into every layer: locality, two-dimensional neighbourhood structure and translation equivariance. In ViT only the MLP layers are local and translation-equivariant (they act on each token separately); self-attention is global from layer one (§3.1).
The image's 2D structure enters at exactly two points: cutting it into patches, and adjusting the position embeddings to a new resolution at fine-tuning. The position embeddings start with no information about where patches are, so every spatial relation is learned from scratch (§3.1, §3.2): the network must learn from examples what a CNN is handed for free.
The stage runs one image of this page's toy task through the trained toy ViT, with the class token's real attention at each layer, then through the toy ResNet, whose view grows one small square at a time (both models are described in Run a ViT). Same 28 × 28 image, the toy models' real sizes.
ViT: 4 × 4 patches (49 tokens plus the class token), D = 32, 4 layers, 4 heads; the bars are the class token's attention averaged over heads, from the shipped weights. ResNet: a BiT-style network (GroupNorm) with a stride-2 3 × 3 stem and three residual blocks; the square is the theoretical receptive field of one output position, computed from kernel sizes and strides. Multiply-adds are counted by formula.
Pre-train on large data, then remove the pre-trained head and attach a zero-initialised D × K layer for the K downstream classes (§3.2). Fine-tuning at a higher resolution than pre-training helps; keep the patch size fixed, so the sequence gets longer (ViT-L/16 goes from 196 patches at 224 px to 576 at 384 and 1,024 at 512), and 2D-interpolate the pre-trained position embeddings to the new grid according to their location in the original image. This is now standard practice; how today's libraries resize the table is on Vision encoders.
In the appendix, the whole two-layer head is replaced on transfer, which "we found to be a little more robust than simply re-initializing the very last layer" (App. B.1.1).
ViT uses standard learnable 1D position embeddings, one vector per position in raster order (§3.1). The ablation on ViT-B/16 (Table 8) compared no position information (a bag of patches), 1D, 2D (separate X and Y halves) and relative embeddings (an attention bias from the query-key offset), added at the stem or at every layer. No positions costs 2.82 points of 5-shot accuracy; every other variant lands within 0.33 points of the rest, because at patch level the grid is small (14 × 14, not 224 × 224) and any encoding learns it easily (App. D.4). The learned 1D embeddings recover the 2D grid on their own: nearby patches, and patches in the same row or column, get similar embeddings, sometimes with a sinusoidal pattern on larger grids, and the exact pattern depends on the hyperparameters (Figure 7, centre, Figure 10).
A few points: 61.4% against 64.2% 5-shot (Table 8). Patches still carry a lot of information on their own: a bag of patches still knows which textures and parts are present. On this page's toy task the same ablation, trained the same way on 64,000 images, gets of held-out images right against with position embeddings.
Try: this is the toy ViT's own learned table, one tile per patch (7 × 7 grid); each tile shows that patch's cosine similarity to every other patch. Click a tile to enlarge it. Switch to the model trained on 2,000 images to compare.
Cosine similarity of the 49 patch position embeddings of the shipped weights (6-bit quantised; the float weights give the same grid score to within 0.002, pos_check.py). "Grid score" is the correlation, over all patch pairs, between embedding similarity and minus the distance between the two patches on the grid: 1 would mean similarity falls exactly with distance.
Three pre-training sets of growing size, ImageNet (1.3M images), ImageNet-21k (14M) and JFT-300M (303M); BiT ResNets as baselines, trained with the same Adam recipe as the ViTs; fine-tuning with SGD at 384 px; results as fine-tuning accuracy or few-shot linear accuracy, compute in TPUv3-core-days (§4.1).
The largest models, pre-trained on JFT-300M, are compared with the two best CNN results of the time (§4.2): BiT-L (Big Transfer, a ResNet152x4 also pre-trained on JFT-300M) and Noisy Student (an EfficientNet-L2 trained semi-supervised on ImageNet plus unlabelled JFT-300M), then state of the art on ImageNet and on the other datasets respectively. Accuracies are means and standard deviations over three fine-tuning runs (Table 2).
Every Table 2 column, with the gaps in units of the runs' standard deviation, is in the tables tab.
Bars: ViT-H/14 (JFT-300M) minus BiT-L; rings: ViT-L/16 (JFT-300M) minus BiT-L, level on ReaL and 0.01 behind on VTAB. Table 2 as printed; compute from its last row.
With fewer built-in assumptions than a ResNet, how much data does ViT need? Two experiments answer it (§4.3).
The authors' conclusion: "the convolutional inductive bias is useful for smaller datasets, but for larger ones, learning the relevant patterns directly from data is sufficient, even beneficial" (§4.3). The paper gives no table for Figure 4, so where between 9M and 90M the curves cross is only readable off the plot.
The smaller one: 77.91% against 76.53% (Table 5). Larger models need more data before their capacity helps. The chart shows ViT-L/16 minus ViT-B/16 on each fine-tuning dataset as the pre-training set grows; below it, this page's own version of the experiment.
Table 5 values; differences in percentage points. Table 5's ImageNet numbers are fine-tuned at 384 px without the Polyak averaging and 512 px images of Table 2.
The toy ViT and a ResNet of the same size and cost (53,221 and 56,005 parameters; 3.1M and 3.4M multiply-adds per image), trained on 500 to 64,000 toy images with identical hyperparameters and steps, early-stopped, as in the JFT-subset experiment; accuracy on 5,000 held-out images.
One training run per point (seed 0): the differences between points are not error-barred. 2,000 steps of batch 128 for every size, so 500 images are seen 512 times each and 64,000 images 4 times. "Train" accuracy is on the first 2,000 training images (all of them for 500). Training curves for every run are in the Run a ViT tab.
A controlled scaling study on JFT-300M, where data does not limit the models: 7 ResNets, 6 ViTs and 5 hybrids, pre-trained for 7 or 14 epochs (all listed in Table 6; for hybrids the number is the ResNet's downsampling, not a patch size), transfer accuracy against pre-training compute (§4.4). Three patterns:
In the appendix, depth is the best dimension to scale (gains up to 64 layers, diminishing after 16), width the worst, and smaller patches help without adding parameters, so compute predicts performance better than parameter count (App. D.2). Measured on TPUv3, ViT runs about as fast as similar ResNets and fits larger batches per core (App. D.5).
"Average of 5" is ImageNet, CIFAR-10, CIFAR-100, Pets and Flowers. Compute saving: for each ViT, the ResNet compute that would reach the same accuracy, read along the ResNets' best-so-far frontier by interpolating linearly in log compute, divided by the ViT's compute. Defaults reproduce the exaFLOPs column independently, by 3 × forward FLOPs (2 per multiply-add, attention included) × 303M images × epochs: .
Try: the toy ViT's own version of Figure 7 (right), measured in your browser on 100 held-out images. Each dot is one head at one layer.
Attention distance: for each patch query, the distance in pixels between patch centres, weighted by the attention weight, averaged over queries and images (the paper weights pixel distances; with 4 × 4 patches the difference is small). The class token is left out as query and key. Image width is 28 px.
Much of the Transformer's success in NLP comes from self-supervised pre-training, so the authors tried a masked patch prediction objective, mimicking BERT (§4.6): corrupt 50% of patch embeddings (80% replaced by a learnable [mask] embedding, 10% by another patch, 10% kept) and predict the 3-bit mean colour (512 colours) of each corrupted patch (App. B.1.2). With it, ViT-B/16 reaches 79.9% on ImageNet: about 2 points above training from scratch (Table 5's 77.91%) and about 4 behind supervised pre-training (83.97% from ImageNet-21k, 84.15% from JFT). Contrastive pre-training was left to future work.
Other targets worked about as well; returns diminished after 100k steps, and ImageNet pre-training gave similar gains (App. B.1.2).
The conclusion lists three challenges: apply ViT to detection and segmentation, keep exploring self-supervised pre-training, and scale further (§5).
This is the paper that ended CNN dominance in vision at scale. Its lesson: hand-designed inductive bias stands in for data, and with enough data and compute a generic architecture that learns the structure catches up, which put vision on NLP's scaling playbook and one architecture under both. Each later claim has its own source; what each line of work does now is taught on the page that owns it.
What holds up.
What to discount.
Table 5's ViT-H/14 JFT row differs from Table 6's and matches Table 2 on four columns, "Figure 4" is cited for Figure 3, Table 1's 307M recounts to 303.3M (details). None changes a conclusion.
At toy scale on this page the direction reproduces and the crossover does not: . The ResNet has more than the ViT to gain from its built-in bias here (the task is the same wherever the shapes are), and one seed per point says nothing about where large models cross. The learned position embeddings also show far less grid structure than Figure 7 (see Position embeddings).
Believe the architecture and the direction: a plain Transformer on patches, pre-trained on enough data, matches or beats the 2020 CNNs, Table 2's gaps are far outside the noise, and every later vision tower is built this way. Treat "large scale training trumps inductive bias" and the 2 to 4× saving as statements about the 2020 recipes: better training later made ViTs work on ImageNet alone, and CNNs trained at the same scale match them. The method is now standard, so Then and now replaces "What it takes to use this".
A real Vision Transformer, built exactly as Eq. 1 to 4 say, trained offline at toy scale and running here in plain JavaScript. The task makes every answer checkable: each 28 × 28 image holds three outline shapes (ring, square, triangle, plus, x), two of the same kind, and the model must name the kind that appears twice. That needs both local work (recognise a shape from its strokes) and global work (compare shapes far apart), which is what attention from the class token is for.
Pick a model on the right, draw or place shapes, and the prediction updates as you draw; the cards below show where it looks, test it on fresh images and show every run's training curve.
Click a patch with the pen off to pick it as the query for "From a patch". The pen draws at the image's intensity.
Draws images from seeds the training never used (from 230 up; training used seeds 1 to 64,000, validation and test 229 up) and checks the answer against the generator's label.
Transcribed from the arXiv HTML by script (mk_tables.py), printed precision kept; every derived number is recomputed in recompute.py.
Recount from Eq. 1 to 4: E and its bias (P²·3·D + D), the class token (D), Epos ((N+1)·D), per layer two LayerNorms (4D), qkv (3D² + 3D), the output projection (D² + D) and the MLP (2D·M + M + D), plus the final LayerNorm; no classification head (it depends on the dataset).
Mean ± standard deviation over three fine-tuning runs, as printed. Gap in standard deviations: difference divided by √(sda² + sdb²), only where both are printed. Noisy Student reports ImageNet and ReaL only; 88.5% is the slightly improved result reported by Touvron et al.
Fine-tuned at 384 px. ViT-H/14 was not pre-trained on ImageNet. Its JFT-300M row matches Table 2 on CIFAR-10, CIFAR-100, Pets and Flowers but not Table 6 (see below).
Table 6 and Figure 5, accuracy against pre-training compute with the compute-saving recount, are drawn in The paper, beside the claim they carry.
Table 8 is ViT-B/16, ImageNet 5-shot linear accuracy, printed as fractions. Table 7 is fine-tuning accuracy after 7 epochs of JFT pre-training; its Average row is recomputed: .
Token strips are schematic (a few patches stand for 196); the counts under them are exact for the configuration named in the step.
The 2020 ViT's input sequence, changed one sourced step at a time into what vision towers and image generators use now. Each step names the paper that made the change; what stayed the same is at the bottom.
Every link opens in a new tab. Reading time of the resources below: 4h 40m.
ICLR 2021, the paper itself; the HTML version has the anchors this page links to. abstract page, PDF.
(1h)
fine-tuning code and pre-trained models (repo, about 20 minutes for the README and entry path).
(20 min)
the authors: the authors' own condensed account of the architecture and the data-scale story.
(15 min)
Yannic Kilcher: section-by-section reading with good intuition on inductive bias against scale.
(1h)
lucidrains: minimal reference implementation plus dozens of ViT variants (repo, about 20 minutes for the README and the base model); the fastest way to see how little code the model needs.
(20 min)
AI Summer: diagrams and code snippets for patch embedding, the class token and position embeddings.
(25 min)
Steiner et al., 2021: the authors' follow-up: with augmentation, regularisation and more compute, ImageNet-21k pre-training matches JFT-300M; the main correction to this paper's data story.
(40 min)
Touvron et al., 2020: ViT-B trained on ImageNet alone to 83.1% with a modern recipe, two months after this paper.
(40 min)
2017: the encoder ViT reuses nearly unchanged.
2018: source of the [class] token, the Base and Large sizes, and the masked-prediction idea tried in section 4.6.
2020: the NLP scaling story whose vision counterpart this paper begins.
2021: pairs a ViT image encoder with a text encoder; the main route by which ViT reached multimodal models.
2020: the diffusion line that later swapped its U-Net for ViT-style DiT backbones.
2021: diffusion in a latent space; DiT later ran a ViT on patches of those latents.
2021: rotary position embeddings, which 2D-RoPE vision towers (Qwen2-VL) use instead of ViT's learned table.
vision encoders, VLMs and diffusion backbones, all built on this paper's patch tokens.
inductive bias, convolutions and attention.
This page is one row of the Papers database; its properties (Paper, Takeaway, Topics, Year) live there.