For the past few years, the "Attention is All You Need" mantra has dominated deep learning. Transformers, powered by multi-head self-attention, have become the undisputed kings of both Natural Language Processing (NLP) and, increasingly, Computer Vision (CV). But is self-attention truly the indispensable "secret sauce," or is it just one way to achieve effective spatial communication?
In their paper "Pay Attention to MLPs," researchers from Google Research introduce gMLP, a simple architecture built entirely out of Multi-Layer Perceptrons (MLPs) with basic gating. Their findings are provocative: a well-designed MLP-based model can match or even exceed Transformer performance across major benchmarks, suggesting that the "necessity" of self-attention might be overstated.
TL;DR
The authors propose gMLP, a simple architecture based on MLPs and multiplicative gating that performs as well as Transformers in vision and language tasks. By replacing self-attention with a static "Spatial Gating Unit," gMLP achieves parity with BERT on pretraining and matches Vision Transformers (ViT) on ImageNet, proving that self-attention is not a requirement for scaling deep learning models.
What Problem Does This Paper Address?
The success of Transformers is usually attributed to two things: a recurrent-free architecture that allows for massive parallelism, and the self-attention mechanism, which dynamically weights the relationships between different tokens (words in a sentence or patches in an image).
However, self-attention is computationally expensive and introduces a specific inductive bias—that spatial interactions should be content-dependent. The authors wanted to know if this bias is essential. Could a simpler, static mechanism—like the classic MLP—capture these interactions just as well if scaled properly?
Methods
The core of the paper is the gMLP block. Instead of the complex multi-head attention layers found in Transformers, gMLP uses a stack of $L$ identical blocks, each consisting of:
- Channel Projections: Standard linear layers that operate on each token independently (similar to the Feed-Forward Networks in Transformers).
- Spatial Gating Unit (SGU): The "brain" of the model. It performs a linear projection across the spatial (token) dimension. Crucially, it uses multiplicative gating: the output is the element-wise product of the original representation and the spatially-projected version.
Unlike Transformers, gMLP does not require positional encodings. Because the spatial projection matrix is static and learns fixed weights for each position in the sequence, the model inherently understands the order of tokens.
Datasets
The authors evaluated gMLP on several heavy-hitting benchmarks:
- Computer Vision: ImageNet-1K for image classification.
- Language Pretraining: The C4 dataset (both the full English set and a RealNews-like subset) for Masked Language Modeling (MLM), following the BERT setup.
- NLP Downstream Tasks: The GLUE benchmark (specifically SST-2 and MNLI) and SQuAD (v1.1 and v2.0) for reading comprehension.
Key Insights and Ideas
- Self-Attention is Optional for Vision: For image classification, gMLP achieves the same accuracy as Vision Transformers (ViT/DeiT). This suggests that for images, static spatial weights are just as effective as dynamic attention.
- Spatial Weights Learn Structure: When the authors visualized the learned weights in the SGU, they found that the model automatically learned concepts like locality and spatial invariance. In vision, the weights look like convolutional kernels (Figure 3); in language, they learn Toeplitz-like structures, effectively discovering shift-invariance from data (Figure 4).
- The "Alignment" Gap: While gMLP is excellent at pretraining, it slightly lags behind Transformers on NLP tasks requiring complex cross-sentence alignment (like MNLI).
- Tiny Attention Goes a Long Way: To fix the alignment issue, the authors tested a hybrid model called aMLP. By adding a tiny single-head attention module (only 64 dimensions) to the gating unit, the model outperformed standard Transformers while remaining much more parameter-efficient.
Key Results
- ImageNet: gMLP-B achieved 81.6% Top-1 accuracy, matching DeiT-B (81.8%) and significantly outperforming other MLP-like models like MLP-Mixer (76.4%).
- BERT Parity: In MLM pretraining, gMLP achieved nearly identical perplexity to Transformers of the same size.
- Scaling: The authors demonstrated that gMLP follows the same "power law" scaling as Transformers. As you increase data and compute, the performance gap between the two architectures vanishes.
Limitations and Future Work
While gMLP is a powerful alternative, it isn't a total Transformer-killer yet. The spatial projection matrix $W$ is $O(n^2)$ relative to the sequence length $n$, which is the same scaling bottleneck as standard attention. This makes it difficult to apply to extremely long sequences without further optimization.
Additionally, while pure gMLP is impressive, the fact that a "tiny bit" of attention (aMLP) helps so much suggests that attention still provides a unique benefit for specific types of reasoning. Future work may focus on finding the optimal balance between static MLP structures and dynamic attention modules.
Summary updated