Abstract
In deep learning theory, the covariance matrix of the representations serves as a proxy to examine the network's trainability. Motivated by the success of Transformers, we study the covariance matrix of a modified Softmax-based attention model with skip connections in the proportional limit of infinite-depth-and-width. We show that at initialization the limiting distribution can be described by a stochastic differential equation (SDE) indexed by the depth-to-width ratio. To achieve a well-defined stochastic limit, the Transformer's attention mechanism is modified by centering the Softmax output at identity, and scaling the Softmax logits by a width-dependent temperature parameter. We examine the stability of the network through the corresponding SDE, showing how the scale of both the drift and diffusion can be elegantly controlled with the aid of residual connections. The existence of a stable SDE implies that the covariance structure is well-behaved, even for very large depth and width, thus preventing the notorious issues of rank degeneracy in deep attention models. Finally, we show, through simulations, that the SDE provides a surprisingly good description of the corresponding finite-size model. We coin the name shaped Transformer for these architectural modifications.
Introduction
As Large Language Models (LLMs) continue to scale, they face a fundamental theoretical challenge: deeper and wider models are more expressive but increasingly difficult to train. In standard Transformer architectures, deep layers often suffer from rank collapse, a phenomenon where the representations of different tokens become perfectly correlated. When tokens become indistinguishable to the network, the covariance matrix becomes poorly conditioned, leading to vanishing or exploding gradients.
While empirical techniques like LayerNorm and residual connections mitigate these issues, they do not fundamentally resolve the signal propagation failures that occur in the "infinite limit." This paper introduces the Shaped Transformer, an architecture designed to remain numerically stable even as depth and width grow to infinity.
The Proportional Limit and SDEs
To analyze these models, the authors utilize the proportional infinite depth-and-width limit. Unlike the common "NTK limit" which keeps depth fixed, this regime allows both depth ($d$) and width ($n$) to approach infinity while their ratio ($d/n$) remains constant. This is a more faithful representation of real-world networks because it preserves the random fluctuations and noise found in finite models.
In this limit, the evolution of the network's covariance structure can be described by a Stochastic Differential Equation (SDE). By treating the depth of the network as a continuous time parameter, the authors can mathematically ensure that the data "drift" and "diffusion" remain controlled as signals pass through the layers.
Architectural Innovations
To achieve a stable SDE and prevent rank collapse, the Shaped Transformer introduces two primary modifications to the attention mechanism:
- Shaped Attention: The Softmax-based attention matrix is modified to be a small perturbation of the identity matrix. By centering the Softmax output (subtracting the mean) and adding an identity term, the model encourages tokens to "self-attend" by default. This prevents the attention mechanism from mixing tokens so aggressively that they lose their individual identity.
- Width-Dependent Temperature Scaling: The Softmax temperature parameter $\tau$ is scaled by $\sqrt{n \cdot n_k}$. This specific scaling ensures that the updates provided by each attention layer are "infinitesimal" enough to converge to a stable stochastic process rather than diverging.
Empirical Results
The authors validated the Shaped Transformer through both synthetic simulations and practical training on the English Wikipedia and BookCorpus datasets.
Stability and Rank Preservation
The Shaped Transformer successfully resists rank collapse. In standard "Pre-LN" Transformers, token correlations typically hit 1.0 (perfect alignment) within 50 layers. In contrast, the Shaped Transformer maintains a stable correlation (between 0.2 and 0.4) even at depths exceeding 150 layers. This stability is maintained even without the use of LayerNorm.
Training and Performance
Beyond theoretical stability, the Shaped Transformer demonstrates healthy gradient flow across all depths. In practical Masked Language Modeling (MLM) tasks, the architecture achieved competitive or superior results compared to standard baselines. On the COLA task (GLUE benchmark), a 24-block Shaped Transformer achieved a score of 0.211, significantly outperforming the unshaped baseline score of 0.022. The model also showed increased robustness to high learning rates, avoiding the "entropy collapse" that often plagues standard Softmax distributions during unstable training.
Conclusion
The Shaped Transformer provides a principled framework for designing deep attention models by ensuring they possess a well-behaved covariance structure at initialization. By describing the network as a stable SDE, researchers can prevent rank degeneracy and ensure trainability at extreme scales. Future work will focus on applying these insights to frontier-scale models and exploring how these "shaped" properties evolve during the training process.
Summary updated