CoAtNet: Marrying Convolution and Attention for All Data Sizes

Zihang Dai, Hanxiao Liu, Quoc V Le, Mingxing Tan

TL;DR

CoAtNet is a hybrid neural network architecture that elegantly combines the strengths of Convolutional Neural Networks (ConvNets) and Transformers. By unifying depthwise convolution and self-attention into a single mathematical framework and optimizing their vertical arrangement, CoAtNet achieves state-of-the-art performance across all data scales—from standard ImageNet-1K to massive 3-billion-image datasets.

What Problem Does This Paper Address?

In the world of computer vision, two titans have been at odds: ConvNets and Vision Transformers (ViT).

  • ConvNets possess strong "inductive biases" like translation equivariance (an object is the same regardless of where it is in the image) and local receptive fields. This makes them highly efficient and great at generalizing from smaller datasets. However, they often hit a performance ceiling when data is abundant.
  • Transformers have massive model capacity and can capture global relationships across an entire image. While they scale incredibly well with massive data (like the JFT-300M dataset), they struggle to generalize on smaller datasets because they lack the "common sense" biases inherent in convolutions.

The authors tackle a fundamental question: How can we "optimally" combine these two architectures to create a model that generalizes like a ConvNet but scales like a Transformer?

Methods

The researchers introduced two key innovations to bridge the gap:

  1. Mathematical Unification: They observed that both depthwise convolution and self-attention are essentially weighted sums of values in a neighborhood. They proposed a "pre-normalization relative attention" mechanism. This effectively sums a static, learned convolution kernel with a dynamic, data-dependent attention matrix. This allows the model to attend to global context while maintaining the local stability of a convolution.
  2. Vertical Layout Design: Simply mixing layers isn't enough; the order matters. The authors experimented with different "stacking" strategies. They settled on a 5-stage architecture (S0 to S4):
  3. S0 & S1: Purely convolutional (using MBConv blocks) to handle high-resolution, low-level features where global attention would be computationally prohibitive.
  4. S2: A transitional stage (usually MBConv).
  5. S3 & S4: Transformer blocks with the new relative attention to capture high-level, global semantic information.
  6. This C-C-T-T (Convolution-Convolution-Transformer-Transformer) layout proved to be the "sweet spot" for balancing efficiency and capacity.
Comparison of different vertical layouts on ImageNet-1K and JFT.

Datasets

The models were rigorously tested across a spectrum of data sizes:

  • ImageNet-1K: 1.28 million images (Standard benchmark).
  • ImageNet-21K: 13 million images (Large scale).
  • JFT-300M: 300 million images (Extra-large scale).
  • JFT-3B: 3 billion images (Massive scale, proprietary Google dataset).

Key Insights and Ideas

  • Generalization vs. Capacity: The paper quantifies a crucial trade-off. Convolutions reduce the "generalization gap" (the difference between training and testing performance), while Transformers increase the "model capacity" (the ability to continue learning from more data). The C-C-T-T layout optimally balances these two properties.
  • The Power of Relative Attention: Adding a simple relative position bias to the attention mechanism is more effective than complex "local attention" schemes. It provides the translation equivariance that standard ViTs lack.
  • Data Efficiency: CoAtNet is remarkably data-efficient. A CoAtNet-3 trained on ImageNet-21K matched the performance of a ViT-Huge model trained on JFT-300M, despite using 23x less data.
  • The "Aha" Moment on Layout: The authors found that putting convolutions in the early stages isn't just about saving computation; it actually helps the later Transformer stages perform better by providing more stable, localized features.

Key Results

CoAtNet established new benchmarks across the board:

  • SOTA on ImageNet: Achieved 86.0% top-1 accuracy using only ImageNet-1K data.
  • Massive Scaling: When pre-trained on JFT-3B, CoAtNet-7 reached 90.88% top-1 accuracy on ImageNet, setting a new world record at the time of publication.
  • Efficiency: Compared to the previous state-of-the-art (ViT-G/14), CoAtNet achieved similar accuracy while being 1.5x faster in terms of computation.

Limitations and Future Work

  • Task Specificity: The paper focuses almost exclusively on ImageNet classification. While the authors believe the architecture is applicable to object detection and semantic segmentation, they leave those experiments for future work.
  • Hardware Optimization: The design choices were partially driven by what runs efficiently on TPUs (e.g., avoiding certain types of local attention). The performance might vary on different hardware architectures like GPUs or mobile chips.
  • Dataset Access: The most impressive results rely on the JFT-3B dataset, which is a private Google dataset, making those specific results difficult for outside researchers to replicate exactly.

Summary updated

BibTeX
@inproceedings{dai2021coatnet,
  author = {Zihang Dai and Hanxiao Liu and Quoc V Le and Mingxing Tan},
  title = {{CoAtNet: Marrying Convolution and Attention for All Data Sizes}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=JXAyJeYqUkZ},
}
Figure