Introduction
Standard Transformer models rely on Softmax attention, which suffers from quadratic complexity ($O(N^2)$) relative to input sequence length. While "Efficient Transformers" using Linear attention ($O(N)$) have been proposed to mitigate this, they often sacrifice significant accuracy. This research explores a fundamental hypothesis: the sub-optimal performance of efficient models stems from using architectures originally designed for Softmax attention. The authors argue that changing the attention mechanism necessitates a fundamental redesign of the model's "shape" or architecture.
Methodology: RankNAS and Mixed Attention
To identify the optimal architecture for efficient models, the researchers employed RankNAS, a high-efficiency Neural Architecture Search (NAS) framework. Unlike traditional NAS that requires training thousands of models from scratch, RankNAS uses pairwise ranking and search space pruning to identify top candidates rapidly.
A key innovation in this work is the introduction of a Mixed Attention Search Space. In addition to standard hyperparameters like embedding size, layer count, and head numbers, the algorithm can choose the Attention Type for every individual layer.
The search space allows the model to select between:
- Softmax Attention: High accuracy but computationally expensive.
- Linear Attention (cosFormer): An efficient alternative using a ReLU kernel and cosine reweighting to preserve local information.
The resulting hybrid model, mFormer (Mixed Transformer), automatically balances these types to optimize the accuracy-efficiency trade-off for specific tasks.
Key Results and Insights
The mFormer was evaluated on machine translation (WMT’14 En-De) and image classification (CIFAR-10) to test its versatility across domains.
Performance Benchmarks
- Machine Translation: mFormer achieved a BLEU score of 25.79. While slightly lower than a fully searched Softmax Transformer (28.34), it utilized 18% fewer parameters and FLOPs. Notably, pure Linear attention models (cosFormer*) struggled to converge on this task, highlighting the necessity of the hybrid approach discovered by NAS.
- Image Classification: On CIFAR-10, mFormer reached 93.59% accuracy. It proved significantly more efficient than standard Transformers, requiring only 8.39G FLOPs compared to the standard's 10.90G—a nearly 23% improvement in efficiency while maintaining competitive accuracy.
Architectural Discoveries
The NAS process revealed several critical design principles for efficient models:
- "Shallow and Thin" Designs: Optimal efficient architectures tend to have fewer decoder layers and smaller Feed-Forward Network (FFN) dimensions than standard Transformers.
- Strategic Softmax Placement: High accuracy can be maintained by placing Softmax attention in just a few strategic layers while using Linear attention for the majority of the model.
- The Decoder Constraint: The researchers discovered a "repeater" problem where Linear attention in decoders causes models to get stuck in loops. Consequently, the most effective mFormer variants for translation retain Softmax in the decoder.
Conclusion and Future Work
This study demonstrates that efficient Transformers require custom-tailored architectures rather than simple module swaps. By using NAS to create mFormer, the researchers proved that a hybrid of Softmax and Linear attention provides a superior balance of speed and precision. Future work will focus on resolving the stability issues of linear attention in decoders and scaling these findings to large-scale pre-training environments like GPT or BERT.
Summary updated