On Layer Normalizations and Residual Connections in Transformers

Sho Takase, Shun Kiyono, Sosuke Kobayashi, Jun Suzuki · OpenReview

Abstract

In the perspective of a layer normalization (LN) position, the architecture of Transformers can be categorized into two types: Post-LN and Pre-LN. Recent Transformers prefer to select Pre-LN because the training in Post-LN with deep Transformers, e.g., ten or more layers, often becomes unstable, resulting in useless models. However, in contrast, Post-LN has also consistently achieved better performance than Pre-LN in relatively shallow Transformers, e.g., six or fewer layers. This study first investigates the reason for these discrepant observations empirically and theoretically and discovers 1, the LN in Post-LN is the source of the vanishing gradient problem that mainly leads the unstable training whereas Pre-LN prevents it, and 2, Post-LN tends to preserve larger gradient norms in higher layers during the back-propagation that may lead an effective training. Exploiting the new findings, we propose a method that can equip both higher stability and effective training by a simple modification from Post-LN. We conduct experiments on a wide range of text generation tasks and demonstrate that our method outperforms Pre-LN, and stable training regardless of the shallow or deep layer settings.

Introduction

The placement of Layer Normalization (LN) is a critical architectural decision in Transformer models. The original Post-LN design, which places LN after the residual connection, is known for high performance in shallow models but suffers from extreme instability in deeper configurations (10+ layers). Conversely, Pre-LN places LN inside the residual branch, ensuring training stability for deep models at the cost of a performance ceiling. This study identifies the root causes of these behaviors and introduces the Bottom-to-Top (B2T) connection to bridge the gap between stability and performance.

The Bottom-to-Top (B2T) Connection

The primary issue with Post-LN is that LN layers act as bottlenecks for gradient flow, leading to vanishing gradients. In contrast, Pre-LN models often exhibit high redundancy, where higher layers perform transformations very similar to lower layers, failing to fully utilize the model's depth.

To address this, the authors propose the B2T connection. This architectural modification introduces an additional residual path that links the input of a layer directly to the output of its Feed-Forward Network (FFN), effectively bypassing internal LN operations during backpropagation. This ensures there is always a path for the gradient to flow that isn't "choked" by multiple LN operations.

Architectural comparison of Post-LN, Pre-LN, and B2T.

Gradient Flow Analysis

Empirical analysis confirms that LN in Post-LN is the main source of vanishing gradients. As shown in the gradient norm analysis, vanilla Post-LN exhibits a sharp decline in gradient norms in the decoder side as we move toward lower layers (higher depth in backprop). The B2T connection successfully stabilizes these norms, maintaining a profile similar to or better than Pre-LN while preserving the effective transformation characteristics of Post-LN.

Gradient norm analysis across layer depths.

Experimental Results

The B2T connection was validated across machine translation (WMT), summarization (Gigaword), language modeling (WikiText-103), and speech recognition (LibriSpeech).

  • Stability at Depth: In an 18-layer encoder-decoder setup where Post-LN failed to converge, B2T achieved 27.30 BLEU, outperforming Pre-LN (26.57 BLEU).
  • Extreme Scaling: B2T successfully trained a 100-layer model, consistently outperforming Pre-LN by an average of 0.7 BLEU points.
  • Efficiency: B2T provides these gains with negligible computational overhead compared to other stabilization techniques like Admin or DLCL, as it is a simple architectural change.

Conclusion

The B2T connection offers a simple yet powerful solution to the stability-performance trade-off in deep Transformers. By mitigating the vanishing gradient problem inherent in Post-LN while avoiding the redundancy of Pre-LN, it enables the training of high-performance, very deep models. Future work includes further theoretical exploration of Post-LN transformations and refining regularization strategies for models exceeding 100 layers.

Summary updated

BibTeX
@inproceedings{takase2023layer,
  author = {Sho Takase and Shun Kiyono and Sosuke Kobayashi and Jun Suzuki},
  title = {{On Layer Normalizations and Residual Connections in Transformers}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.192},
}
Figure