Abstract
Training deep Transformers is often plagued by numerical instability and exploding activations. While Layer Normalization (LN) is a standard component, its placement—Pre-LN versus Post-LN—significantly impacts training dynamics. This paper introduces a control theory framework to analyze Transformer stability, proving that the widely used Pre-LN variant is mathematically "degenerate." We propose Peri-LN, a configuration that normalizes both module inputs and outputs, which, when combined with a scaled residual step, ensures bounded hidden state growth and superior training stability.
Introduction
The evolution of Transformer architectures has been marked by shifts in Layer Normalization (LN) placement. Post-LN, used in the original Transformer, suffered from vanishing gradients, necessitating complex learning rate warmups. Pre-LN solved this but introduced a new problem: hidden states that grow excessively with depth, leading to potential numerical overflow. Recent high-profile models like Gemma 2 and Olmo 2 have adopted a hybrid "Peri-LN" approach. This paper provides the first rigorous mathematical foundation for why Peri-LN succeeds where Pre-LN falters.
Methods: A Control Theory Toolkit
The authors model the Transformer as a continuous-time system, treating discrete layers as an Euler discretization of an Ordinary Differential Equation (ODE). By framing training as a Mean-Field Optimal Control problem, they analyze the associated Hamilton-Jacobi-Bellman (HJB) equations.
A key finding is that the Pre-LN Hamiltonian is infinite, rendering the optimization problem "degenerate." Geometrically, LN projects inputs onto an ellipsoid. In Pre-LN, the lack of a terminal normalization in the residual branch allows the "velocity" of hidden state changes to grow unchecked, leading to the exploding activations observed in deep models.
The Peri-LN Advantage
Peri-LN places normalization at both the input and output of each attention and feedforward module. This acts as a physical constraint, forcing the updates to remain within a bounded ellipsoid. This ensures that hidden states grow linearly or quadratically rather than exponentially.
Furthermore, the authors introduce a "scaled residual step" ($\Delta t < 1$). By reducing the step size of the residual update (e.g., to 0.1), the growth of activations is significantly dampened without sacrificing the model's expressive power.
Empirical Validation
The theory was validated using GPT-2 models (ranging from 124M to 1.5B parameters) pretrained on the OpenWebText dataset.
Zero Divergence
In stability stress tests, Pre-LN models frequently diverged (crashed), particularly when weight decay was disabled. In contrast, Peri-LN models achieved a 0% divergence rate across all trials, regardless of weight decay settings. This confirms that Peri-LN provides a fundamental architectural safeguard against training instability.
Performance Gains
Beyond stability, the combination of Peri-LN and a scaled residual step ($\Delta t = 0.1$) consistently yielded the best performance across metrics like Val Loss, Perplexity, and BERTScore for all model sizes. Visualization of the trained models confirmed that while Pre-LN activations climb steeply across layers, Peri-LN with scaling keeps the mean absolute value of hidden states significantly lower and more regular.
Conclusion
By moving beyond empirical observation to a control-theoretic analysis, this work identifies the fundamental instability in Pre-LN Transformers. Peri-LN, combined with scaled residual steps, provides a mathematically grounded and empirically superior alternative, ensuring stable training for the next generation of deep models. Future work may extend this HJB-based framework to screen other emerging architectures like State Space Models for similar stability properties.
Summary updated