
gmlp_ti16_224
Image classification488 ops5.9M params
An all-MLP image classifier whose Spatial Gating Unit replaces self-attention with a learned token-mixing matrix.
Image classification · 488 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
How this diagram was made
timm.create_model('gmlp_b16_224', pretrained=False) About this model's family
gMLP is a vision model that drops self-attention entirely: each block is nothing more than channel projections and spatial projections with static parameterization. The paper's aim was to ask whether the inductive bias of self-attention is essential to the success of Transformers, and the answer it reaches is that it is not critical for Vision Transformers. The captured members are timm's gMLP-Tiny, gMLP-Small and gMLP-Base. They follow the ViT/B16 input protocol, so the image is cut into 16 by 16 pixel patches at the stem and each patch becomes a token.
The key idea is the Spatial Gating Unit. After a channel expansion and a GeLU, the activations are split into two halves along the channel dimension; one half passes through a single linear projection across the token (spatial) dimension and is multiplied element-wise into the other half. What makes this different from attention is that the mixing matrix is a fixed learned weight, independent of the input, rather than something computed from the image. Because that layer carries positional information, gMLP needs no position embeddings. A quirk worth knowing when reading a freshly initialized graph: the spatial weights start near zero and the bias at one, so every block behaves like a regular feed-forward layer at the start of training and tokens only gradually begin to interact.
On ImageNet without extra data the authors find gMLPs comparable with DeiT, the regularized Vision Transformer, and with 66% fewer parameters a gMLP model is 3% more accurate than MLP-Mixer. They are candid that gMLPs still trail the best convolutional and hybrid models. Note that timm's author labels this gMLP implementation preliminary and not verified. One last finding from the paper: after training, the spatial projection matrices show locality and spatial invariance, so each one has effectively learned a convolution with a data-driven, irregular kernel shape.
Key idea. The Spatial Gating Unit: a static linear projection over the spatial (cross-token) dimension, gating one half of the channels with the other, in place of self-attention. With it, a stack of plain MLP blocks reaches the same ImageNet accuracy as a Vision Transformer and scales as well as Transformers with more data and compute.
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
@misc{liu2021payattentionmlps,
title={Pay Attention to MLPs},
author={Hanxiao Liu and Zihang Dai and David R. So and Quoc V. Le},
year={2021},
eprint={2105.08050},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2105.08050},
}