Normalization Layers
BatchNorm, LayerNorm and why they help optimization.
Batch normalization was introduced to cure "internal covariate shift". Three years later, a network with that shift injected on purpose trained just as well, and nobody stopped using the layer. This lesson derives what normalization actually does to gradients, to the learning rate and to weight decay, compares the family of normalizers by the symmetries they create, and looks at networks that train well with no normalization at all.
What you’ll learn
- Derive the Jacobian of batch normalization and show that its backward pass projects out the batch mean and the normalized direction.
- Prove that gradient descent with weight decay on scale-invariant weights is gradient descent without decay under an exponentially growing learning rate, and derive the equilibrium angular update .
- Weigh the competing explanations for why normalization helps against the experiments that test them.
- Compare BatchNorm, LayerNorm, GroupNorm, RMSNorm and weight normalization by the statistics they use and the invariances they create, and explain how normalizer-free networks replace them.
The normalization map and its backward pass
Fix one unit and a mini-batch of examples, and collect its pre-activations in . Batch normalization outputs with , and (we drop the small ). Layer normalization applies the same map to the vector of one example's features. Since and depend on every coordinate, each output depends on all inputs, and so does the gradient.
Centering is the orthogonal projection onto the complement of . With we have , so the normalized vector is a rescaled unit vector:
The derivative of is with . Multiplying by and using :
Chain with . The normalized vector has mean zero, so and the two projections merge into one symmetric matrix:
Backpropagate an upstream gradient . The vectors and are orthogonal and both have squared norm , so the bracket is the orthogonal projection onto the complement of their span:
Two facts follow. First, the gradient that reaches has zero mean over the batch and is uncorrelated with : the parts of that would only shift or rescale the whole batch are removed, because shifting or rescaling cannot change the output. Second, : if earlier weights grow and inflate , the gradient shrinks in proportion, a built-in brake.
Santurkar, Tsipras, Ilyas & Madry (2018) turned this projection into bounds on the gradient norm and on the curvature along the gradient of a batch-normalized network, compared with the same network without the layer, and read them as a smoother loss landscape that tolerates larger steps. How much smoother depends on how much of lies in the removed directions and on , so the bounds do not guarantee an improvement in every case.
A batch of has normalized pre-activations , upstream gradient , and . What is the norm of ?
Show the answer
2.83
, so . Next, ; subtracting leaves . Times : , with norm , against before the projection. A finite-difference check of the layer gives the same vector.
Why does it help? The candidate explanations
The input layer is where the story starts. LeCun, Bottou, Orr & Müller (1998) observed that the Hessian of a linear unit is proportional to the second-moment matrix of its inputs (with a constant 1 standing in for the bias), so centering, scaling and decorrelating the inputs bring it close to a multiple of the identity. The widget fits a line by full-batch gradient descent, on standardized inputs ("round") or on inputs with mean 0.905 and standard deviation 0.43 ("elongated", condition number 20).
| Explanation | Claim | Status |
|---|---|---|
| Internal covariate shift (Ioffe & Szegedy, 2015) | stabilizing layer-input distributions speeds training | the noise-injection experiment undercuts it |
| Smoother landscape (Santurkar et al., 2018) | the projection above improves Lipschitz and smoothness constants | bounds hold under conditions; widely cited, not a full account |
| Larger learning rates (Bjorck, Gomes, Selman & Weinberger, 2018) | normalization mainly enables larger steps, which speed convergence and may help generalization | supported empirically, though De & Smith (2020) found larger rates help mainly at large batch sizes |
| Automatic rate tuning (Arora, Li & Lyu, 2019) | with the rate of scale-invariant weights fixed at any constant, gradient descent still reaches a stationary point at rate | proved; the norm of the weights adapts the step |
| Residual branches start small (De & Smith, 2020) | at initialization normalization shrinks each residual branch by a factor of order , so blocks start near the identity | proved at initialization; reproduced without normalization by "SkipInit" |
| Sharpness reduction (Lyu, Li & Arora, 2022) | with weight decay, gradient descent on scale-invariant losses follows a flow that reduces a scale-invariant sharpness | proved for a broad class of networks, near the edge of stability |
What did the noise-injection experiment of Santurkar et al. (2018) establish?
- Batch normalization works by keeping each layer's input distribution stable
- Networks with deliberately unstable layer-input distributions after normalization trained about as well as ordinary batch-normalized ones
- Noise after normalization layers makes training diverge
- Batch normalization only helps networks without residual connections
Show the answer
B. Networks with deliberately unstable layer-input distributions after normalization trained about as well as ordinary batch-normalized ones
The injected noise changed every unit's input distribution at every step, more than in a network without normalization, yet training was almost unaffected. Whatever normalization does, it is not mainly reducing covariate shift.
Scale invariance meets weight decay
Gradient descent with weight decay at a constant rate multiplies the weights by before each gradient step:
Undo the shrinking: define , a positive multiple of , so the network computes exactly the same function. Its update is
Scale invariance gives . So the sequence is plain gradient descent, with no decay, and a learning rate that grows by the factor every step:
The two runs produce the same predictions at every step. Li & Arora (2020) prove the analogue with momentum, where the growth factor solves a quadratic equation, and trained standard batch-normalized networks with an exponentially increasing learning rate and no weight decay. On such weights, decay does not shrink the function class (only the direction matters); it changes the effective step size.
Because the gradient is orthogonal to , Pythagoras gives the norm after one step with decay:
Decay pulls the norm down and the gradient steps push it up. If hovers around a typical value , the squared norm settles where the two balance:
Each step then turns the direction by an angle of about . Substituting , the gradient size cancels:
At equilibrium the direction moves at a pace set by the product alone, however small the gradients have become: normalization plus decay acts like a constant "angular" learning rate. Linearizing the norm recursion shows the equilibrium is approached on a time scale of order steps. Wan, Zhu, Zhang & Sun (2021) proved, under stated assumptions, that the norm and the angular update converge to their equilibrium values at a linear rate, with for heavy-ball momentum , and measured it on ImageNet and COCO training runs. Empirically, Zhang, Wang, Xu & Grosse (2019) identified a larger effective learning rate as one of three distinct mechanisms by which weight decay regularizes networks.
SGD without momentum, , weight decay , on weights that feed a normalization layer. At equilibrium, by about how many degrees does the weight direction turn per step?
Show the answer
0.57
radian, about . Doubling and halving leaves it unchanged; quadrupling alone doubles it. That is why the learning rate and the weight decay of normalized networks are best tuned together.
Run A uses , ; run B uses , . Both train weights feeding normalization layers with plain SGD. How do their equilibrium angular updates compare?
- A's is four times B's
- B's is four times A's
- A's is twice B's
- They are about equal
Show the answer
D. They are about equal
Both have , so both settle at radian per step. The raw learning rates differ by a factor of 4, but the equilibrium norms differ to compensate.
The normalizer family, and life without it
| Method | Normalizes over | Output unchanged when | Notes |
|---|---|---|---|
| BatchNorm (Ioffe & Szegedy, 2015) | one unit (or channel) across the batch | a unit's pre-activations are shifted or rescaled across the batch | examples interact; running averages at inference |
| LayerNorm (Ba, Kiros & Hinton, 2016) | all units of one example | an example's pre-activation vector is shifted by a constant or rescaled | identical in training and inference |
| GroupNorm (Wu & He, 2018) | groups of channels within one example | a group is shifted or rescaled | one group is LayerNorm over channels; one channel per group is instance normalization |
| RMSNorm (Zhang & Sennrich, 2019) | all units of one example, without centering: | the vector is rescaled (not shifted) | cheaper; widely used in large language models as of the mid-2020s |
| Weight normalization (Salimans & Kingma, 2016) | no data statistics: | is rescaled | a reparameterization; no batch dependence |
Where the normalization sits matters. The original transformer applied layer normalization after each residual addition ("Post-LN"). Xiong et al. (2020) showed with mean-field theory that at initialization this gives large expected gradients for the parameters near the output, which makes a learning-rate warmup necessary; placing the normalization inside each residual branch ("Pre-LN") makes the gradients well behaved, and Pre-LN transformers trained comparably without warmup. Many large language models of the mid-2020s use the Pre-LN arrangement, often with RMSNorm.
Training without normalization. Batch dependence complicates small-batch and distributed training, and the train–test switch is a source of bugs. De & Smith (2020) traced BatchNorm's benefit in deep residual networks to the downscaled residual branch and reproduced it with "SkipInit": a learnable scalar at the end of each residual branch, initialized at zero. Brock, De, Smith & Simonyan (2021) built Normalizer-Free ResNets (NFNets) around adaptive gradient clipping, which rescales the gradient of each unit (a row of a weight matrix ) whenever it is large relative to that unit's weights:
Key takeaways
- Batch normalization's Jacobian is times the projection removing and : the backward pass discards gradient components that could only shift or rescale the batch, and shrinks the rest when grows.
- Deliberately injected covariate shift barely affects batch-normalized training; larger stable learning rates, automatic rate tuning, near-identity residual blocks and sharpness reduction are better-supported explanations, and none is the whole story.
- On scale-invariant weights, decay at rate equals no decay at rate (Li & Arora), and at equilibrium the direction turns by about per step: decay sets the effective learning rate.
- Normalizers differ in which statistics they pool (batch, example, group; centered or not) and in the invariances they create; their placement matters (Pre-LN vs Post-LN), and SkipInit or adaptive gradient clipping can replace them.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In a batch-normalization layer, the gradient with respect to one unit's pre-activations over the batch is always orthogonal to which vectors?
- Only the all-ones vector
- The upstream gradient
- Both and the normalized vector
- None in general
Show the answer
C. Both and the normalized vector
The Jacobian is , the projection onto the complement of up to the factor . These are exactly the directions along which moving (a shift or a rescaling) leaves the output unchanged.
For weights on which the loss is scale-invariant, gradient descent with weight decay at a constant learning rate produces the same sequence of functions as which procedure?
- Gradient descent without decay, with the learning rate shrinking as
- Gradient descent without decay, with the learning rate growing as
- Ridge regression with penalty
- Gradient descent without decay at the constant rate
Show the answer
B. Gradient descent without decay, with the learning rate growing as
Rescaling leaves the function unchanged and turns each decayed step into a plain step with rate , because the gradient of a scale-invariant loss scales inversely with the weights.
At the equilibrium of SGD with weight decay on scale-invariant weights, what happens to the angular update if you multiply the learning rate by 4 and keep fixed?
- It doubles
- It quadruples
- It does not change, because the weight norm compensates completely
- It halves
Show the answer
A. It doubles
The angular update is about , so a fourfold doubles it. The norm compensates only partly: it grows by a factor of 2 in squared norm terms (), not enough to cancel a fourfold step.
According to Xiong et al. (2020), why do Post-LN transformers need a learning-rate warmup while Pre-LN transformers can do without one?
- Pre-LN transformers have fewer parameters
- In Post-LN, the parameters closest to the output receive large expected gradients at initialization, so full-size early steps are unstable
- Layer normalization does not work at batch size 1
- Post-LN computes its statistics over the batch
Show the answer
B. In Post-LN, the parameters closest to the output receive large expected gradients at initialization, so full-size early steps are unstable
Their mean-field analysis shows large gradients near the output at initialization when normalization follows each residual addition. Putting it inside the residual branch keeps the gradients well behaved from the start.
Further reading
- S. Ioffe & C. Szegedy, "Batch normalization: accelerating deep network training by reducing internal covariate shift," ICML (2015).
- S. Santurkar, D. Tsipras, A. Ilyas & A. Madry, "How does batch normalization help optimization?," NeurIPS (2018).
- Z. Li & S. Arora, "An exponential learning rate schedule for deep learning," ICLR (2020).
- R. Xiong, Y. Yang, D. He, K. Zheng, S. Zheng, C. Xing, H. Zhang, Y. Lan, L. Wang & T.-Y. Liu, "On layer normalization in the transformer architecture," ICML (2020).
- A. Brock, S. De, S. L. Smith & K. Simonyan, "High-performance large-scale image recognition without normalization," ICML (2021).