How Do Vision Transformers Work?

Namuk Park, Songkuk Kim
2/14/2022
744 citations
cs.CVcs.LG
transformer-attention

Official code: xxxnell/how-do-vits-work (820 stars, Python, Apache-2.0, PyTorch, last commit 2022-07-14).

Abstract

The success of multi-head self-attentions (MSAs) for computer vision is now indisputable. However, little is known about how MSAs work.

Show full abstract

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.

View on arXivView PDF

Code Implementations(1)

PyTorchApache-2.0

(ICLR 2022 Spotlight) Official PyTorch implementation of "How Do Vision Transformers Work?"

82078Python, Jupyter NotebookMar 9, 20214 years agoApache-2.0
loss-landscapepytorchself-attentiontransformervision-transformer

Similar Papers

Cite this paper

@article{park2022vision,
  title  = {How Do Vision Transformers Work?},
  author = {Namuk Park and Songkuk Kim},
  year   = {2022},
  eprint = {2202.06709},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2202.06709}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2202.06709.svg)](https://codeofpaper.com/paper/2202.06709)

Discussion