How Do Vision Transformers Work?
Namuk Park, Songkuk Kim
TL;DR
The paper challenges the view that Vision Transformers rely primarily on long-range dependencies by showing that multi-head self-attention acts as data-specific spatial smoothing that flattens loss landscapes. It demonstrates that MSAs function as low-pass filters and tend to aggregate feature maps, making them complementary to Convs (which are high-pass). Through extensive analysis of loss landscapes, Hessian spectra, and Fourier properties, the authors argue that stronger inductive biases and locality improve representations, particularly in small-data regimes, while large datasets mitigate non-convexities. They introduce AlterNet, an alternating CNN–MSA architecture with MSAs placed at the end of stages, showing improved performance on CIFAR and ImageNet and offering design rules for harmonizing MSAs with Convs. The work thus provides a unified perspective on how to combine CNNs and ViTs to exploit the strengths of both, along with practical guidance for architecture and training to achieve robust performance.
Abstract
The success of multi-head self-attentions (MSAs) for computer vision is now indisputable. However, little is known about how MSAs work. We present fundamental explanations to help better understand the nature of MSAs. In particular, we demonstrate the following properties of MSAs and Vision Transformers (ViTs): (1) MSAs improve not only accuracy but also generalization by flattening the loss landscapes. Such improvement is primarily attributable to their data specificity, not long-range dependency. On the other hand, ViTs suffer from non-convex losses. Large datasets and loss landscape smoothing methods alleviate this problem; (2) MSAs and Convs exhibit opposite behaviors. For example, MSAs are low-pass filters, but Convs are high-pass filters. Therefore, MSAs and Convs are complementary; (3) Multi-stage neural networks behave like a series connection of small individual models. In addition, MSAs at the end of a stage play a key role in prediction. Based on these insights, we propose AlterNet, a model in which Conv blocks at the end of a stage are replaced with MSA blocks. AlterNet outperforms CNNs not only in large data regimes but also in small data regimes. The code is available at https://github.com/xxxnell/how-do-vits-work.
