NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

On the Benefits of Rank in Attention Layers

Noah Amsel, Gilad Yehudai, Joan BrunaarXiv 2024 · DOI

Abstract

In the design of Transformer architectures, a standard heuristic scales the number of attention heads ($H$) and their rank ($r$) such that $H \times r$ equals the embedding dimension ($d$). This paper challenges this convention by demonstrating that low-rank attention heads are fundamentally less expressive than full-rank ones. Using the nearest neighbor retrieval task as a benchmark, the authors prove that a single full-rank head can outperform a vast collection of low-rank heads. While increased model depth can partially compensate for low rank through a "majority voting" mechanism, the theoretical and empirical evidence suggests that the standard scaling used in modern Large Language Models (LLMs) may be a bottleneck for high-precision retrieval tasks.

Introduction: The $H = d/r$ Convention

Modern Transformer scaling laws typically follow a "golden rule" for hyperparameters: the number of heads and the rank of attention matrices are scaled such that $H = d/r$. For instance, in the Llama architecture, the rank is often fixed at 128 even as the embedding dimension $d$ scales to 8192. This approach assumes that a "wide and shallow" configuration of many low-rank heads is equivalent to a "narrow and deep" configuration of fewer full-rank heads, provided the parameter count remains similar.

This paper investigates whether this assumption holds true. Specifically, it asks if low-rank attention is fundamentally weaker at representing essential functions like semantic search and nearest neighbor retrieval—the core operations that allow Transformers to process context.

The Nearest Neighbor Benchmark

To evaluate the expressivity of different attention ranks, the authors focus on the Nearest Neighbor (NN) function. In a retrieval context, this function identifies the most relevant "key" for a given "query." This is a natural proxy for the attention mechanism's primary role.

The study utilizes a theoretical framework of "Generalized Attention" that encompasses standard softmax attention, various biases, and positional encoding schemes (such as RoPE or ALiBi). For empirical testing, the authors use synthetic datasets where input vectors are drawn from a unit sphere ($S^{d-1}$). To avoid the trivial case where a token attends to itself in self-attention, the task is modified to a "farthest neighbor" search.

Theoretical Results: The Exponential Separation

The core theoretical contribution is the proof of an "exponential separation" between low-rank and full-rank attention. Using harmonic analysis on a sphere, the authors treat the attention mechanism as a series of "ridge functions." They demonstrate that these functions struggle to capture high-frequency, radially symmetric energy when restricted by rank.

Theorem 2 in the paper proves that to achieve high accuracy on the nearest neighbor task with a rank $r < d-3$, a model requires an exponential number of heads: $\Omega(\exp(d-r))$. In contrast, a single full-rank head ($r=d$) can solve the problem perfectly. This suggests that for high-dimensional embeddings, low-rank heads are effectively "blind" to the target function unless the head count grows to an impractical scale.

Depth as a Rank-Substitute

While a single layer of low-rank attention fails, the authors show that adding depth can bridge the gap. They propose a Majority Voting Construction, where a two-layer, low-rank architecture aggregates many "weak" votes from the first layer to identify the correct neighbor in the second.

However, this substitution is not free. Empirical validation showed that a 1-layer full-rank model ($r=64$) easily outperformed a 5-layer low-rank model ($r=32$), even when the low-rank model was given 80 times more parameters. This indicates that while depth helps, it is a highly inefficient way to compensate for insufficient rank.

The Impact of Positional Encodings

The research also highlights the role of positional encodings in overcoming rank deficiencies. Experiments confirmed that "concatenated" positional encodings—which effectively increase the internal dimensionality of the keys and queries—significantly help low-rank models succeed when combined with depth. Conversely, standard "additive" encodings do not provide the same benefit, leaving low-rank models struggling to learn the target function.

Limitations and Future Work

The study identifies several areas for further exploration:

  • Data Distribution: The proofs rely on rotationally invariant data (points on a sphere). It remains to be seen if the "rank gap" is as severe in natural language data, which possesses more complex, non-spherical structures.
  • Deep Transformers: While the authors explore depth, a rigorous proof for the limitations of very deep, low-rank Transformers is still an open challenge.
  • Context Length (Conjecture 8): The authors conjecture that while depth helps for short sequences, low-rank attention will always struggle as the context length ($N$) grows. If proven, this would establish full-rank attention as a fundamental requirement for truly effective long-context models.

Conclusion

The findings suggest that the industry-standard $H=d/r$ scaling is not theoretically justified and may be suboptimal. For tasks requiring high-precision retrieval and long-context processing, researchers and engineers may need to reconsider the promotion of attention heads to higher ranks, moving away from the current reliance on wide, low-rank configurations.

Summary updated

BibTeX
@misc{amsel2024benefits,
  author = {Noah Amsel and Gilad Yehudai and Joan Bruna},
  title = {{On the Benefits of Rank in Attention Layers}},
  year = {2024},
  eprint = {2407.16153},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.16153},
}
Figure