Mind the Gap: a Spectral Analysis of Rank Collapse and Signal Propagation in Attention Layers

Thiziri Nait Saada, Alireza Naderi, Jared Tanner

TL;DR

This paper identifies a previously overlooked phenomenon in transformers called rank collapse in width, where increasing context length causes the self-attention matrix to effectively become rank-one at initialization. Using Random Matrix Theory, the authors show that this collapse is driven by a prominent "spectral gap" inherent to the softmax operation. They propose a remarkably simple fix—subtracting the uniform attention matrix—which removes this gap, restores stable rank, and mitigates exploding gradients.

What Problem Does This Paper Address?

Transformers are the undisputed kings of modern AI, yet they remain notoriously unstable to train and highly sensitive to hyperparameter tuning. At initialization (with random weights), deep transformers suffer from rank collapse in depth, meaning that as token representations pass through multiple layers, they converge and become geometrically identical.

While depth collapse is a known byproduct of repeated matrix multiplications, this paper uncovers a parallel, hidden culprit unique to attention layers: rank collapse in width. Here, "width" refers to the context length ($T$). The authors reveal that as the context length grows, the attention matrix within a single layer collapses toward a rank-one matrix. This width-wise collapse acts as a catalyst, severely accelerating depth collapse and causing gradients to behave pathologically (either vanishing or exploding).

Methods

The authors leverage Random Matrix Theory (RMT) and free probability theory to rigorously analyze the eigenvalues and singular values of attention matrices at initialization. They mathematically model attention layers as a class of i.i.d. Markov matrices, defined by the property that their rows sum to one due to the softmax activation function.

To counteract rank collapse, they introduce a modified attention mechanism called "Attention without the gap" ($A^\perp$). Since the dominant outlier eigenvalue of 1 is caused by the row-summing property of softmax, they project out this troublesome direction by subtracting the uniform attention matrix:

$$A^\perp(\mathbf{X}_0) = A(\mathbf{X}_0) - \frac{1}{T}\mathbf{1}_{T \times T}$$

This simple subtraction cleanly removes the outlier eigenvalue, eliminating the spectral gap while leaving the rest of the matrix's spectral "bulk" intact.

Datasets

Because this work is theoretical and focused on network behavior at initialization, the authors do not train models on standard downstream datasets. Instead, they validate their mathematical claims using:

  • Synthetic data: Orthonormal and non-isometric Gaussian token embeddings.
  • Real text data: Sentences taken from the paper's own abstract, processed using pretrained tokenizers from commercial transformer architectures—specifically BERT, ALBERT, and RoBERTa—loaded directly from Hugging Face.

Key Insights and Ideas

  • The Softmax Curse: Because softmax forces rows to sum to 1, the attention matrix always possesses a dominant eigenvalue of 1. As the context length ($T$) grows, the remaining eigenvalues shrink toward zero. This creates a massive spectral gap that distorts the geometry of the input data, forcing signal propagation down a single, uninformative direction.
  • Not Just Softmax: Alternative attention mechanisms designed to replace softmax—such as ReLU and Sigmoid attention—also exhibit a spectral gap at initialization due to their non-zero mean distributions. They are not immune to width collapse.
Figure 1: Theorem 1 demonstrates that applying the conventional softmax key-query attention mechanism to orthonormal input tokens yields a spectral gap in its spectrum (a). Due to their non-zero mean, ReLU (c) and sigmoid attention (d) mechanisms also exhibit a spectral gap— although of a different size. As the size T of an i.i.d. Markov matrix (Definition 3.1) grows, its eigenvalues form a circular bulk of radius O(T −1/2) in the complex plane, except for the largest eigenvalue which remains 1 (the black dot in (b)). In practice, T does not need to be too large for the limiting behaviour to appear, as shown above.
  • Width Feeds Depth: Rank collapse in width directly accelerates rank collapse in depth. By preventing the attention matrix from flattening in width, the severe token degradation across deeper layers is naturally slowed down.
  • Unifying Recent Empirical Fixes: Recent state-of-the-art tweaks, such as the Differential Transformer (which subtracts two softmax attention maps) and Centered Self-Attention, have shown great empirical success. This paper provides the missing theoretical justification for them, proving they succeed precisely because they implicitly remove this spectral gap.

Key Results

  • Mathematical Proof of Collapse: The authors prove that the stable rank of the token covariance matrix collapses to 1 at a polynomial rate of $O(T^{-3})$ as context length increases.
  • Linear Scaling Restored: By applying their $A^\perp$ modification, the authors prove and empirically demonstrate that the stable rank no longer collapses, instead scaling linearly with the context length ($\text{sr}(\mathbf{\Sigma}^\perp)/T = C$).
  • Taming Exploding Gradients: In deep networks with standard random attention, gradient norms explode exponentially at a rate of $T^{L-1}$ (where $L$ is depth). Removing the spectral gap controls this growth, reducing it to a manageable linear rate relative to the embedding dimension.

Limitations and Future Work

  • Bounded to Initialization: The rigorous proofs in this study apply strictly to the network's state at initialization with random weights. While it explains the starting conditions of training, full training dynamics are not explicitly modeled.
  • Deep Outliers: In very deep networks, the authors empirically observed that secondary outlier eigenvalues begin to emerge from the bulk in an intricate way. Cheaply and dynamically removing these secondary outliers during training remains an open challenge for future research.

Summary updated

BibTeX
@inproceedings{saada2025mind,
  author = {Thiziri Nait Saada and Alireza Naderi and Jared Tanner},
  title = {{Mind the Gap: a Spectral Analysis of Rank Collapse and Signal Propagation in Attention Layers}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=sRKtbGsebH},
}
Figure