Introduction
Transformers have revolutionized machine learning, but they fundamentally struggle with long contexts due to the quadratic computational cost of their attention mechanisms. To address this, researchers introduce LevAttention, a novel method that leverages statistical leverage scores to identify a small, "universal" set of important keys. These keys dominate attention scores for any query. By restricting attention to this universal set, LevAttention reduces the time and space complexity of attention from quadratic to linear with respect to context length, all while supporting streaming and distributed environments.
The Quadratic Bottleneck
At the heart of the Transformer architecture is the attention mechanism, which computes an $n \times n$ attention matrix by multiplying an $n \times d$ Query matrix ($Q$) with an $n \times d$ Key matrix ($K$), applying a function (like softmax), and normalizing the rows. Because this requires comparing every query to every key, it takes $O(n^2 d)$ time. When the context length $n$ grows large, this quadratic bottleneck becomes prohibitive.
Many existing solutions attempt to bypass this by assuming the attention matrix is sparse or low-rank, or by restricting the input data. However, these methods often lack rigorous guarantees that they are actually capturing the most important attention weights—the "heavy" attentions. The authors pose a critical question: for a given threshold $\varepsilon$, can we find all the large attention scores in time that scales linearly with $n$, without making any assumptions about the underlying data?
The LevAttention Methodology
To bypass the hardness of approximating standard softmax attention, LevAttention focuses on polynomial attention functions of the form $f(x) = |x|^p$, which have recently gained traction in fast transformer designs.
The "Universal Set" of Keys
The core novelty of this work is the mathematical proof of a universal set of keys. The authors demonstrate a surprising theoretical insight: you do not need to look at the queries to know which keys will be important. By analyzing the Key matrix $K$ alone, it is possible to find a small subset of keys $U$ that will contain all the heavy attention scores for any possible query $Q$.
Leverage Scores over Row Norms
To find this universal set, the authors utilize tools from randomized numerical linear algebra. For $p=2$, the algorithm computes the statistical leverage scores of the rows of $K$, which essentially measures how much a specific key "stands out" in the geometric space. Keys with leverage scores above a certain threshold are added to the universal set $U$. The authors show that simply looking at the magnitude (row norm) of the key vectors is a poor heuristic; leverage scores, which account for the entire column space of the matrix, are vastly superior predictors of key importance.
Streaming and Distributed Capabilities
Because leverage scores can be approximated efficiently, LevAttention can compute $U$ in a single pass over the data (streaming) using only $O(d^3 \log n)$ memory. It can also be computed across multiple servers by sharing small $d \times d$ sketch matrices ($K^T K$).
Empirical Results
The authors evaluated LevAttention primarily on computer vision tasks, using the standard ImageNet-1k dataset to test Vision Transformer (ViT) models (S/16, L/16, and L/8 architectures).
- Theoretical Speedup: The size of the universal set $U$ is bounded by $O(d/\varepsilon)$ (for $p \le 2$). The algorithm finds this set in $O(n \cdot \text{poly}(d/\varepsilon))$ time, successfully breaking the $O(n^2)$ quadratic barrier and replacing it with a linear dependence on $n$.
- Inference on Pre-trained Models: When forcing a standard pre-trained L/16 ViT to only attend to the top-32 keys selected by LevAttention, the model retains a non-trivial 48.58% accuracy. If those 32 keys are selected using simple row norms instead, accuracy plummets to 8.9%.
- Training from Scratch: ViT models trained from scratch using LevAttention (attending to only 32 out of 197 keys per head) achieve over 90% of the accuracy of full softmax attention. For example, the L/16 LevAttention model hits 75.12% accuracy, compared to 78.83% for the full attention baseline.
Limitations and Future Work
The authors are highly transparent about a frustrating empirical reality: while LevAttention has beautiful theoretical guarantees and vastly outperforms heuristics during inference, this advantage vanishes during training. When training ViTs from scratch, models that used naive "row norm selection" or even "random key selection" achieved similar accuracies to LevAttention.
While random selection lacks the provable "universality" guarantees of leverage scores, neural networks are remarkably adept at adapting to random sparsity during the training process. A major direction for future work is translating the strict theoretical superiority of leverage scores into better empirical performance over naive baselines when training foundation models from scratch.
Summary updated