The Devil in Linear Transformer

Zhen Qin, Xiaodong Han, Weixuan Sun, Dongxu Li, Lingpeng Kong, Nick Barnes, Yiran Zhong

Abstract

Linear transformers aim to reduce the $O(n^2)$ complexity of standard attention to $O(n)$, but often suffer from performance degradation. This paper identifies two primary causes: unstable unbounded gradients and attention dilution. We introduce TRANSNORMER, which utilizes NormAttention for gradient stability and DiagAttention to restore local context. TRANSNORMER achieves state-of-the-art results on the Long-Range Arena (LRA) benchmark while maintaining superior speed and memory efficiency.

Introduction: The Quadratic Bottleneck

Vanilla Transformers rely on a softmax attention mechanism that compares every token to every other token, resulting in a computational cost that grows quadratically with sequence length. While linear transformers use kernel methods to achieve $O(n)$ complexity, they frequently underperform due to two "devils":

  1. Unbounded Gradients: The scaling denominator used to approximate softmax can become infinitesimally small, leading to training instability.
  2. Attention Dilution: Linear transformers often fail to capture local dependencies in early layers, spreading attention too thinly across the sequence.
Comparison of attention concentration and maps across Transformer variants.

Proposed Methods: Exorcising the Devils

NormAttention for Stability

To resolve gradient instability, the authors propose NormAttention. Instead of approximating the softmax denominator, the mechanism computes linear attention as $O = Q(K^T V)$ and applies a normalization layer (e.g., RMSNorm) directly to the output. This ensures bounded forward passes and stable gradients, facilitating smoother convergence.

DiagAttention for Locality

To combat attention dilution, DiagAttention is introduced for the model's early layers. By restricting tokens to attend only to immediate neighbors within fixed-size blocks, the model is forced to learn local semantics—mimicking the natural behavior of vanilla transformers—before transitioning to global NormAttention in later stages.

Experimental Results

The TRANSNORMER architecture was evaluated across several benchmarks, including WikiText-103, GLUE, and the Long-Range Arena (LRA).

Long-Range Arena (LRA) Performance

On the LRA benchmark, TRANSNORMER T2 achieved an average score of 64.80, significantly outperforming the vanilla Transformer (57.37) and other efficient variants like Performer (58.00) and FLASH (61.31).

Performance vs. Speed on Long-Range Arena (LRA) benchmark.

Speed and Efficiency

TRANSNORMER demonstrates exceptional throughput. In training tests with 5k-length sequences, it was approximately 3x faster than the vanilla transformer. Its $O(n)$ complexity also ensures a significantly smaller memory footprint, enabling the processing of much longer sequences.

GLUE Benchmark

On the GLUE natural language understanding tasks, TRANSNORMER T1 achieved an average score of 79.38, surpassing the vanilla transformer's 78.79, proving its versatility beyond long-range tasks.

Conclusion and Future Work

TRANSNORMER successfully bridges the gap between linear efficiency and quadratic performance by addressing gradient stability and attention locality. While highly effective in NLP, future research will explore its application in Computer Vision and investigate automated hyperparameter tuning for DiagAttention block sizes.

Summary updated

BibTeX
@inproceedings{qin2022devil,
  author = {Zhen Qin and Xiaodong Han and Weixuan Sun and Dongxu Li and Lingpeng Kong and Nick Barnes and Yiran Zhong},
  title = {{The Devil in Linear Transformer}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.473},
}
Figure