Abstract
Softmax attention is the cornerstone of modern Transformers, yet its quadratic complexity has led to numerous linear-time alternatives. Despite their efficiency, these models often struggle with retrieval-heavy tasks. This paper investigates this performance gap through the lens of Single-Location Regression (SLR). We demonstrate that softmax attention is Bayes-optimal for retrieval, satisfying the Nishimori condition from statistical physics, while linear alternatives suffer from fundamental normalization and sharpening constraints.
Introduction
Large Language Models (LLMs) almost universally rely on softmax attention, which incurs a computational cost that grows quadratically with sequence length ($O(L^2)$). To mitigate this, researchers have proposed "linear attention" and State-Space Models (SSMs) that offer $O(L)$ efficiency. However, an empirical mystery persists: while these efficient models perform well on general language tasks, they consistently fail at retrieval tasks—such as the "Needle-in-a-Haystack" test—where a model must extract specific information from a long context. This paper provides a theoretical foundation for this gap, proving that the advantage of softmax is rooted in its statistical properties rather than mere engineering.
Theoretical Framework: Single-Location Regression
To bridge theory and practice, we utilize a simplified mathematical framework called Single-Location Regression (SLR). In this task, a model must produce an output based on a single "relevant" token hidden among "distractor" tokens. We analyze two variants:
- Spiked-SLR: The relevant token possesses a directional bias in the hidden space.
- Max-SLR: The relevant token is identified by its maximal correlation with a hidden key.
We characterize the performance of these models using various risk metrics, defined in the table below.
Using tools from statistical physics, specifically the replica method, we describe the behavior of high-dimensional neural networks through order parameters that capture the alignment of keys and values with the ground truth.
Key Insights: The Power of Softmax
The primary finding is that softmax attention is Bayes-optimal for retrieval tasks. In statistical physics terms, it satisfies the Nishimori condition, meaning the attention mechanism perfectly mimics the true posterior probability of token relevance.
In contrast, linear attention fails due to two fundamental limitations:
- Lack of Sharpening: It lacks the exponential sharpening required to effectively ignore distractors.
- Normalization Issues: Without global normalization, the "noise" from irrelevant tokens eventually overwhelms the signal as sequence length ($L$) increases. Softmax’s denominator is a feature, not a bug, providing the necessary normalization to maintain signal integrity.
Empirical Results
Our theoretical predictions are supported by empirical evaluations comparing LLaMA (softmax) against efficient alternatives like TNL (kernelized) and HGRN2 (SSM).
As shown in Figure 1, LLaMA maintains near-perfect accuracy across various context lengths, whereas the accuracy of linear and SSM alternatives degrades significantly as the sequence length increases. Furthermore, while linear models can approach softmax performance on general linguistic metrics (e.g., WikiText perplexity), the gap in retrieval accuracy remains stark, particularly in the finite-sample regime where a "hard phase" may cause local optimization algorithms like SGD to get stuck in sub-optimal solutions.
Conclusion
This work demonstrates that softmax's global normalization and exponential sharpening are critical for robust retrieval. By reaching the Bayes risk, softmax sets a statistical benchmark that linear alternatives cannot match without significant architectural modifications. Future research will focus on extending this analysis to multi-index models where outputs depend on multiple tokens, moving closer to complex multi-step reasoning.
Summary updated