TL;DR
Standard Transformers struggle with long sequences because their "softmax" attention is too inclusive, diluting focus across thousands of irrelevant tokens. This paper introduces ASEntmax, a sparse attention mechanism with a learnable, length-adaptive temperature that assigns exact zeros to noise, enabling models to generalize to contexts up to 1000× longer than they saw during training.
The Problem: Softmax and the "Dense" Attention Wall
As we push Large Language Models (LLMs) to process millions of tokens, we hit a fundamental mathematical wall: the softmax function. Softmax is inherently "dense," meaning it must assign at least a tiny fraction of probability mass to every single token in a sequence, no matter how irrelevant.
In long contexts, this density leads to three critical failures:
- Attention Dispersion: As the sequence grows, the attention "budget" is spread so thin that the model's focus approaches a uniform distribution, losing the crucial signal in a sea of noise.
- Representational Collapse: Tokens become indistinguishable from one another because their representations are averaged over too many neighbors.
- Over-squashing: Gradients (the signals used for learning) are diluted across an exponential number of paths, making it nearly impossible for the model to learn long-range dependencies.
The Solution: ASEntmax and Sparse Attention
To combat these issues, the authors propose replacing softmax with $\alpha$-entmax, a sparse transformation that can assign exact zeros to irrelevant tokens. While $\alpha$-entmax has existed for a few years, its behavior in extreme long-context scenarios was previously poorly understood.
The paper’s primary contribution is ASEntmax (Adaptive-Scalable Entmax). This mechanism adds a learnable, head-specific temperature parameter that scales dynamically with the sequence length ($n$). Specifically, they use a scaling factor of $\delta + \beta(\log n)^\gamma$. This allows each attention head to decide how "sharp" or "diffuse" its focus should be as the context expands.
Additionally, they introduce NAPE, a hybrid positional encoding strategy. It splits attention heads: half use ALiBi (which favors nearby tokens) and half use NoPE (no explicit positional bias), allowing the model to balance local context with long-range retrieval.
Key Insights
- The Power of Zero: By assigning exact zeros, $\alpha$-entmax prevents the "leaking" of probability mass. This provides a theoretical guarantee that the model can maintain a constant level of focus on important tokens regardless of how many billions of "distractor" tokens are added.
- Sparsity Heals Gradients: The paper proves that sparse attention reduces the number of effective gradient paths from $O(n^L)$ to $O(s^L)$ (where $s$ is the number of active tokens). This concentration of gradient flow directly alleviates the "over-squashing" problem.
- Log-Scaling is the Sweet Spot: The authors found that the range of attention scores grows at a rate of $\sqrt{\log n}$. By making the temperature a function of $\log n$, ASEntmax counteracts this growth, preventing the model from becoming "overly peaky" or "overly diffuse" as the context window shifts.
Experimental Results
The researchers evaluated their approach on synthetic probes (designed to test length extrapolation) and language modeling (training 420M-parameter models on 7 billion tokens from the FineWeb dataset).
- 1000× Extrapolation: On the MQMTAR synthetic task, ASEntmax achieved 95.3% accuracy at a sequence length of 65,536 tokens, despite being trained on only 64 tokens. Standard softmax models collapsed to near-zero accuracy under the same conditions.
- Superior Retrieval: On the RULER "Needle-in-a-Haystack" benchmark (S-NIAH-2), ASEntmax maintained a 25.4% accuracy at 8k tokens, while the standard softmax baseline dropped to 0%.
- Better Perplexity: In real-world language modeling, ASEntmax showed a consistent downward trend in perplexity even when evaluated at 8× the training sequence length, outperforming both standard softmax and fixed-temperature sparse baselines.
Limitations and Future Work
While ASEntmax excels at retrieval and local pattern matching, the authors note that tasks requiring global ordering (like sorting a massive list of numbers) remain difficult for all current Transformer architectures.
Furthermore, while the authors utilize AdaSplash (a fast kernel for $\alpha$-entmax) to maintain efficiency, the computational overhead of calculating the sparse threshold $\tau$ is slightly higher than a simple softmax. Future work could involve further optimizing these kernels for hardware-level acceleration, potentially making sparse attention the default standard for trillion-parameter models.
Summary updated