Simple Algorithm
Deep Learning · Emergence · 26 min

ConvNets vs Vision Transformers

Inductive bias, data scale and the modernized ConvNet.

In 2021 the story seemed simple: vision transformers, with fewer built-in assumptions than convolutional networks, win once they see enough data. Within two years a retrained ResNet, a "modernized" ConvNet and ConvNets scaled to tens of thousands of accelerator-hours had complicated it. This lesson sorts out what is actually known about inductive bias and data, and how much of the apparent gap was the training recipe.

What you’ll learn

  • Contrast the inductive biases of convolution and self-attention, and state precisely what the Vision Transformer's data-scaling experiments showed.
  • Explain how DeiT and "ResNet strikes back" exposed training recipes as a confounder in architecture comparisons.
  • Walk ConvNeXt's modernization of ResNet-50 step by step, with the accuracy each change bought.
  • Evaluate the evidence from large-scale ConvNet scaling, controlled robustness studies, representation comparisons and hybrid architectures.
  • State what is settled and what is open in the debate over inductive bias versus data.

Two inductive biases

A convolutional layer assumes three things about images: what matters is local (small kernels), the same pattern means the same thing everywhere (shared weights), and so the layer should be translation-equivariant. A Vision Transformer (ViT; Dosovitskiy et al., 2021) assumes almost none of this. It cuts the image into 16×1616\times16 patches, embeds each linearly, adds learned position embeddings and runs a transformer encoder. Only the patching and the per-patch MLPs are local; self-attention mixes all patches from the first layer on with weights computed from the content; and the position embeddings start with no information about 2-D layout, which must be learned.

Attention is not weaker than convolution in principle. A multi-head self-attention layer with NhN_h heads and relative positional encodings can express any convolution with a Nh×Nh\sqrt{N_h}\times\sqrt{N_h} kernel, and trained attention layers often do attend in grid-like local patterns (Cordonnier, Loukas & Jaggi, 2020). The question is what each architecture learns from finite data, at a given compute budget.

PropertyConvolutionSelf-attention (ViT)
Mixing across spacelocal window, widening with depthglobal from the first layer
Mixing weightsfixed after training, the same at every positioncomputed from the input for every pair of patches
Symmetrytranslation-equivariant by constructionpermutation-equivariant; position enters only through embeddings
Cost in the number of positions nnlinearquadratic in tokens, O(n2)\order{n^2}
Multiscale featuresnatural, from strided stagessingle scale unless built in (Swin, hierarchical designs)

The ViT paper's own experiments set up the debate. Trained on ImageNet's 1.3 million images without strong regularization, ViTs reached accuracies a few points below ResNets of comparable size; larger ViTs did worse than smaller ones there. Pretrained on ImageNet-21k (14 million images) the sizes evened out, and only with the 300-million-image JFT-300M did the largest models pull ahead, matching or beating the best ConvNets of the day. The authors summarized: "large scale training trumps inductive bias". Hybrids, a ViT on top of ResNet features, beat pure ViTs at small compute budgets, but the difference vanished for larger models.

Check your understanding

What did the original ViT experiments show about pretraining data size?

  1. ViTs beat ResNets at every data scale, including ImageNet-1k alone
  2. ViTs fall a few points short of comparable ResNets when trained on ImageNet-1k without strong regularization, and overtake them only with much larger pretraining sets
  3. Data size made no difference; only model size mattered
  4. ViTs cannot be trained on ImageNet-1k at all
Show the answer

B. ViTs fall a few points short of comparable ResNets when trained on ImageNet-1k without strong regularization, and overtake them only with much larger pretraining sets

On ImageNet alone, ViT-Large even underperformed ViT-Base. With ImageNet-21k the sizes evened out, and with JFT-300M larger ViTs matched or beat strong ConvNets. As the next step shows, "without strong regularization" turned out to matter a great deal.

Recipes as confounders

DeiT (Touvron et al., 2021) trained a ViT-Base-sized model on ImageNet-1k alone to 81.8% top-1, on a single 8-GPU node in two to three days, with a recipe of heavy augmentation (RandAugment, Mixup, CutMix, random erasing, repeated augmentation), stochastic depth, AdamW and long training. It added a distillation token: an extra token, like the class token, trained to match a teacher's hard predictions. A convolutional teacher (RegNetY-16GF, 82.9%) worked better than a transformer one, which the authors attribute to the inductive bias inherited through distillation; with it, DeiT-B reached 83.4% at 224×224224\times224 and, with longer training at higher resolution, 85.2%.

The same lesson cut the other way. ResNet strikes back (Wightman, Touvron & Jégou, 2021) retrained a plain ResNet-50 with a modern procedure (600 epochs, binary cross-entropy, LAMB, heavy augmentation) and reached 80.4% at 224×224224\times224 without extra data or distillation, against the 76.1% usually quoted. A gap of several points between "ConvNets" and "transformers" in 2020 papers had therefore mixed architecture with training recipe, and comparisons had to hold the recipe fixed.

Modernizing a ConvNet

ConvNeXt (Liu et al., 2022) made the comparison controlled by walking from ResNet-50 toward the design of the Swin Transformer one change at a time, keeping each change that helped, with no attention anywhere. Every accuracy below is ImageNet-1k top-1 in the ResNet-50 / Swin-T compute regime, averaged over three seeds:

ChangeTop-1What it borrows
ResNet-50, original recipe76.1%—
Modern training recipe: 300 epochs, AdamW, Mixup, CutMix, RandAugment, random erasing, stochastic depth, label smoothing78.8%DeiT and Swin training
Blocks per stage (3, 4, 6, 3) → (3, 3, 9, 3)79.4%Swin's 1:1:3:1 stage ratio
Stem: 7×77\times7 stride-2 convolution and max pool → 4×44\times4 stride-4 "patchify" convolution79.5%ViT/Swin patch embedding
Depthwise 3×33\times3 convolutions, width 64 → 9680.5%ResNeXt grouping; spatial and channel mixing separated, as in attention + MLP
Inverted bottleneck (expand 4×, as in a transformer MLP)80.6%the transformer MLP block
Move the depthwise convolution to the top of the block79.9%attention before the MLP (a temporary loss)
Kernel 3×33\times3 → 7×77\times780.6%Swin's 7×77\times7 windows; gains saturated at 7
ReLU → GELU80.6%transformer activation
One activation per block instead of three81.3%transformer blocks
One normalization per block81.4%transformer blocks
BatchNorm → LayerNorm81.5%transformer normalization
Separate 2×22\times2 stride-2 downsampling layers (with LayerNorm)82.0%Swin's patch merging
The final ConvNeXt-T reached 82.1% against 81.3% for Swin-T, both at 4.5 billion FLOPs and about 28–29 million parameters, with similar throughput and memory and no specialized modules such as shifted windows or relative position biases. The single largest step was the training recipe.
python
import torch.nn as nn

class ConvNeXtBlock(nn.Module):
    """Depthwise 7x7 -> LayerNorm -> 1x1 expand (4x) -> GELU -> 1x1 project, plus the identity."""
    def __init__(self, dim):
        super().__init__()
        self.dwconv = nn.Conv2d(dim, dim, kernel_size=7, padding=3, groups=dim)  # spatial mixing only
        self.norm = nn.LayerNorm(dim)                                           # over channels
        self.pwconv1 = nn.Linear(dim, 4 * dim)                                  # 1x1 convolutions, written
        self.act = nn.GELU()                                                    # as linear layers on
        self.pwconv2 = nn.Linear(4 * dim, dim)                                  # channels-last tensors

    def forward(self, x):                          # x: (B, C, H, W)
        y = self.dwconv(x).permute(0, 2, 3, 1)     # (B, H, W, C)
        y = self.pwconv2(self.act(self.pwconv1(self.norm(y))))
        return x + y.permute(0, 3, 1, 2)

The paper's block also scales the branch by a learned per-channel factor ("layer scale", initialized to 10−610^{-6}) and drops whole branches at random during training (stochastic depth); both are omitted here. Read as a transformer block, the depthwise convolution takes the place of attention: it mixes positions, with fixed instead of input-dependent weights.

Predict before you look

At width 96 the block above has 79,200 parameters. What percentage of them are in the 7×77\times7 depthwise convolution (weights and biases)?

Show the answer

6 %

96⋅49+96=4,80096\cdot49+96=4{,}800 of 79,20079{,}200, about 6%; the two 1×11\times1 layers hold the rest. A dense 3×33\times3 convolution at width 96 would need 962⋅9=82,94496^2\cdot9=82{,}944 weights by itself. Depthwise, a large kernel is cheap in parameters and FLOPs, though, as Efficient ConvNets explains, not in memory traffic.

Scale, robustness and representations

At scale. ConvNeXt with ImageNet-22k pretraining reached 87.8% top-1 and matched or beat Swin Transformers of similar size on COCO detection and ADE20K segmentation. Smith, Brock, Berrada & De (2023) then pretrained NFNet ConvNets on JFT-4B with budgets from 0.4 to 110 thousand TPU-v4 core-hours: held-out loss followed a power law in compute, and after fine-tuning they matched the reported ImageNet accuracy of ViTs with comparable budgets, up to 90.4% top-1. Large kernels also scaled: RepLKNet used depthwise kernels up to 31×3131\times31 and found much larger effective receptive fields and a higher shape bias than small-kernel CNNs (Ding et al., 2022).

Robustness. Claims that transformers are inherently more robust compared models trained with different recipes. With a unified setup, Bai et al. (2021) found that CNNs that adopt transformers' training recipes are as robust to adversarial attacks as transformers, while transformers did generalize better to out-of-distribution data, an advantage their ablations traced to the self-attention-like architecture rather than to pretraining or other training settings.

What the models compute. Comparing internal representations, Raghu et al. (2021) found ViTs' representations much more uniform across layers than ResNets'. Self-attention aggregates global information already in the lowest layers, which mix local and global heads, and residual connections propagate features strongly upward, while spatial information is preserved. Trained on ImageNet alone, without large-scale pretraining, the large ViT-L/16 and ViT-H/14 did not learn to attend locally in their lowest layers and performed much worse (the smaller ViT-B/32 still learned local heads), which suggests that the early use of local information hard-coded in CNNs matters, and that a ViT must learn it from enough data. Vishniakov, Shen & Liu (2024) compared ConvNeXt and ViT models of similar ImageNet accuracy, trained either supervised or with CLIP, and found that they differ in the kinds of mistakes they make, in calibration, in transferability and in which transformations their features are invariant to: a single ImageNet number hides much of the difference.

Hybrids. CoAtNet (Dai et al., 2021) studied the trade-off directly: convolutional stages generalize better and converge faster thanks to their prior, attention stages have more capacity for large data. Its best layout, two convolutional stages followed by two transformer stages, reached 86.0% on ImageNet-1k alone, 88.56% with ImageNet-21k pretraining and 90.88% with JFT-3B. ConViT (d'Ascoli et al., 2021) instead initialized attention heads to behave like convolutions and let each learn to escape locality, improving sample efficiency over DeiT. ConvNeXt V2 (Woo et al., 2023) brought masked-autoencoder pretraining to ConvNets with a fully convolutional masked autoencoder and a new global response normalization layer, reaching 88.9% with a 650-million-parameter model trained on public data only. Self-supervised pretraining is covered in Masked Modeling Across Modalities.

What is settled, and what is not

As of the mid-2020s, a few conclusions are well supported:

  • Recipes first. Training procedure, data and compute explain much of what was once attributed to architecture; fair comparisons need matched recipes.
  • Priors matter most when data are scarce. Convolutional priors help sample efficiency on small and mid-sized datasets, for whole networks (CoAtNet's convolutional stages, ConViT's soft locality) and even when transferred through a teacher (DeiT's distillation).
  • At scale the gap closes. With large pretraining sets and compute, well-designed ConvNets and ViTs reach similar accuracy at similar compute (ConvNeXt, NFNets), and the remaining differences show up in robustness, calibration and transfer more than in top-1 accuracy.
  • Convergence in design. The two families borrowed from each other until their blocks look alike: separated spatial and channel mixing, inverted MLP-like bottlenecks, LayerNorm, patchify stems and hierarchical stages.

In practice, transformers dominate where models must share an architecture with language (vision–language models, multimodal pretraining), and ConvNets remain common where latency, memory or high-resolution inputs dominate. Vision Transformers & Vision–Language Models and Hierarchical Vision Transformers take the transformer side of the story further.

Key takeaways

  • Convolution builds in locality, weight sharing and translation equivariance; self-attention mixes globally with input-dependent weights and can express convolution. ViT fell short of ResNets on ImageNet-1k without strong regularization and pulled ahead only with much larger pretraining sets.
  • DeiT (81.8% on ImageNet-1k, better with a convolutional teacher) and ResNet strikes back (80.4% for a plain ResNet-50) showed that training recipes confound architecture comparisons.
  • ConvNeXt's roadmap, recipe 76.1 → 78.8%, then stage ratio, patchify stem, depthwise convolutions, inverted bottleneck, 7×77\times7 kernels, fewer activations and norms, LayerNorm and separate downsampling to 82.0%, matched Swin-T at equal FLOPs without attention.
  • At scale, ConvNets match ViTs at comparable compute (NFNets on JFT-4B up to 90.4%); with matched recipes adversarial robustness is similar while transformers generalize better out of distribution; similar accuracy can hide different errors and calibration.
  • Convolutional priors help most with limited data, and hybrids combine generalization with capacity; quantifying what a prior is worth remains open.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Why did "ResNet strikes back" and DeiT matter for the ConvNet-versus-transformer debate?

  1. They showed that ViTs cannot be trained without JFT-300M
  2. They proved that convolution is strictly better than attention
  3. They showed that modern training recipes move ImageNet accuracy by several points for both families, so earlier comparisons had confounded architecture with recipe
  4. They introduced new architectures that replaced both ResNets and ViTs
Show the answer

C. They showed that modern training recipes move ImageNet accuracy by several points for both families, so earlier comparisons had confounded architecture with recipe

DeiT trained a ViT to 81.8% on ImageNet-1k alone with a strong recipe; RSB lifted a plain ResNet-50 from about 76% to 80.4% with one. Holding the recipe fixed became a requirement for any architecture claim.

Question 2

In ConvNeXt's modernization of ResNet-50, which single change brought the largest accuracy gain?

  1. Replacing BatchNorm by LayerNorm
  2. The modern training recipe, before any architectural change
  3. Moving from 3×33\times3 to 7×77\times7 kernels
  4. Replacing ReLU by GELU
Show the answer

B. The modern training recipe, before any architectural change

The recipe alone took ResNet-50 from 76.1% to 78.8%, +2.7 points. The architectural changes together added another 3.2, each step at most about one point; GELU alone changed nothing.

Question 3

What did Bai et al. (2021) find when comparing the robustness of CNNs and transformers under a unified training setup?

  1. Transformers are far more robust to adversarial attacks whatever the recipe
  2. CNNs are more robust in every respect
  3. Robustness depends only on the amount of pretraining data
  4. CNNs trained with transformers' recipes are as robust to adversarial attacks, while transformers generalize better out of distribution, owing to their self-attention-like architecture
Show the answer

D. CNNs trained with transformers' recipes are as robust to adversarial attacks, while transformers generalize better out of distribution, owing to their self-attention-like architecture

The adversarial gap reported earlier came from unequal training. The out-of-distribution advantage persisted under matched settings and, by their ablations, came from the architecture rather than from pretraining.

Question 4

Which statement best summarizes the evidence on inductive bias versus data as of the mid-2020s?

  1. Inductive bias never matters; only data and compute do
  2. Convolutional priors help most when data are limited, while with large-scale pretraining well-designed ConvNets and ViTs reach similar accuracy at similar compute
  3. Transformers are better at every data scale once tuned
  4. ConvNets are better at every data scale once tuned
Show the answer

B. Convolutional priors help most when data are limited, while with large-scale pretraining well-designed ConvNets and ViTs reach similar accuracy at similar compute

Low-data results (CoAtNet's generalization study, ConViT, DeiT's convolutional teacher) favor convolutional priors; large-scale results (ConvNeXt with ImageNet-22k, NFNets on JFT-4B, ViTs on JFT) show the families converging. What remains differs in robustness, calibration and transfer.

Further reading

  • A. Dosovitskiy et al., "An image is worth 16x16 words: Transformers for image recognition at scale," ICLR (2021).
  • H. Touvron, M. Cord, M. Douze, F. Massa, A. Sablayrolles & H. Jégou, "Training data-efficient image transformers & distillation through attention," ICML (2021).
  • Z. Liu, H. Mao, C.-Y. Wu, C. Feichtenhofer, T. Darrell & S. Xie, "A ConvNet for the 2020s," CVPR (2022).
  • S. L. Smith, A. Brock, L. Berrada & S. De, "ConvNets match vision transformers at scale," arXiv:2310.16764 (2023).
  • Y. Bai, J. Mei, A. Yuille & C. Xie, "Are transformers more robust than CNNs?," NeurIPS (2021).