Why "classic" Transformers are shallow and how to make them go deep

Yueyao Yu, Yin ZhangarXiv 2023 · DOI

Introduction: The Post-Norm vs. Pre-Norm Divide

In the evolution of Transformer architectures, two primary normalization schemes have emerged: Post-Norm (the original 2017 design where LayerNorm follows the residual connection) and Pre-Norm (where LayerNorm precedes the sub-layers). While Post-Norm models often exhibit superior performance in shallow configurations, they become notoriously difficult to train as depth increases. Modern Large Language Models (LLMs) like Llama and GPT-4 almost exclusively use Pre-Norm for its stability.

This research investigates the root cause of this instability, identifying a phenomenon called Token Similarity Escalation (TSE). The authors demonstrate that in deep Post-Norm models, tokens become nearly identical as they pass through layers, effectively destroying the model's expressive power.

The Problem: Token Similarity Escalation

The core issue in deep Transformers is "rank collapse" or "token uniformity." As data progresses through the layers, every word or image patch begins to look exactly like every other one. This research provides a mathematical proof for why this happens so predictably.

Token similarity rapidly approaches 1.0 as the number of blocks increases in BERT and ALBERT models, indicating a loss of representational diversity.

By modeling the Self-Attention (SA) plus residual sub-layer as a variation of the "power method," the authors show that attention matrices—which are row-stochastic—naturally have a leading eigenvalue of 1. Repeated operations push all tokens toward this "all-ones" subspace. They define a "TSE rate" to quantify this loss of diversity, proving that the SA mechanism increases token similarity at a linear rate by default.

Beyond Vanishing Gradients

A common misconception in deep learning is that training failures in deep models are primarily due to vanishing or exploding gradients. However, this study reveals a different reality for Transformers.

Gradient norms in deep BERT models remain relatively stable even as the number of blocks increases to 100, suggesting that training failure is not solely a gradient issue.

As shown in the figure above, gradient norms can remain stable even while the model fails to learn. The failure is not a loss of signal, but a loss of expressivity. When tokens become identical, the model loses its ability to distinguish between different parts of the input, making further training futile regardless of gradient health.

Methods: The "De-escalation" Strategy

To counteract TSE, the authors propose a simple "surgical" intervention. They insert a linear "de-escalation" operator: $$Y = (I - \tau\Pi_1) X$$ where $\Pi_1$ is a projection matrix capturing the "average" component of the tokens. By subtracting a portion ($\tau$) of this common component, they "spread" the tokens back out in the representation space, preserving their unique identities without weakening the attention mechanism itself.

Key Results and Implications

The strategy was validated on two distinct deep architectures:

  • Vision Transformer (ViT): An 80-layer Post-Norm ViT on CIFAR-10, which typically fails to converge, trained successfully and slightly outperformed its Pre-Norm counterpart.
  • Transformer-XL: A 60-layer configuration on WikiText-103 matched the stability and performance of the Pre-Norm model using the de-escalated Post-Norm approach.

The authors argue that Pre-Norm's success is actually a "dilution" strategy—it implicitly diminishes the role of self-attention relative to the residual branch. Their proposed de-escalation is more direct, removing the harmful similarity while allowing the attention mechanism to remain potent.

Conclusion

By identifying Token Similarity Escalation as the primary barrier to depth in classic Transformers, this work opens a path to more expressive deep models. While currently tested on smaller-scale models, the mathematical precision of the TSE theory suggests that "de-escalation" could be a vital tool for scaling the next generation of massive architectures.

Summary updated

Abstract

Since its introduction in 2017, Transformer has emerged as the leading neural network architecture, catalyzing revolutionary advancements in many AI disciplines. The key innovation in Transformer is a Self-Attention (SA) mechanism designed to capture contextual information. However, extending the original Transformer design to models of greater depth has proven exceedingly challenging, if not impossible. Even though various modifications have been proposed in order to stack more layers of SA mechanism into deeper models, a full understanding of this depth problem remains lacking. In this paper, we conduct a comprehensive investigation, both theoretically and empirically, to substantiate the claim that the depth problem is caused by \emph{token similarity escalation}; that is, tokens grow increasingly alike after repeated applications of the SA mechanism. Our analysis reveals that, driven by the invariant leading eigenspace and large spectral gaps of attention matrices, token similarity provably escalates at a linear rate. Based on the gained insight, we propose a new strategy of surgically removing excessive similarity in contrast to the existing approach of diminishing the SA mechanism explicitly or implicitly (such as in pre-norm transformers). Preliminary experimental results confirm the effectiveness of the proposed strategy in small-scale post-norm Transformer models.
BibTeX
@misc{yu2023why,
  author = {Yueyao Yu and Yin Zhang},
  title = {{Why "classic" Transformers are shallow and how to make them go deep}},
  year = {2023},
  eprint = {2312.06182},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.06182},
}
Figure