3.2.9 · D5Training Deep Networks
Question bank — Layer normalization
The recurring characters below:
- — one example's activation row of features.
- — mean and variance computed across those features (never across the batch).
- — the standardized value; is a tiny safety number.
- — learnable scale and shift applied after standardizing.
True or false — justify
LayerNorm and BatchNorm both compute a mean, so they normalize over the same numbers.
False. Both compute a mean, but BatchNorm averages one feature down a column (across examples) while LayerNorm averages all features across a row (one example) — same tool, orthogonal axis.
LayerNorm behaves identically at training and inference time.
True. Its statistics come only from the current example, so there is nothing batch-dependent to freeze — no running averages like BatchNorm needs.
Scaling an entire input vector by changes the LayerNorm output (before ).
False. Multiplying every by multiplies both the deviation and by , so they cancel — is invariant to scaling the whole row (with ).
Adding a constant to every feature of the input changes .
False. Adding shifts by the same , so is unchanged — LayerNorm is invariant to shifting the whole row too.
The learnable are redundant once we force mean , variance .
False. A rigid unit-variance range can be wrong for the next nonlinearity; restore expressiveness and can even undo normalization entirely if that helps.
With and , LayerNorm returns the original input.
True. Then — the network can learn to be the identity, so LayerNorm never forces harm.
LayerNorm requires a batch of at least a few dozen examples to give stable statistics.
False. It uses only the current example's features, so batch size 1 works perfectly — that batch-independence is its whole selling point in Transformers.
Setting is fine as long as your data is "reasonable".
False in general. If any row is (near) constant, and you divide by , producing NaNs and exploded gradients. is a guard, not a tuning knob.
After Step 3 (ε=0), the standardized features have mean exactly and variance exactly .
True. by construction and — a purely algebraic identity, independent of the data values.
RMSNorm and LayerNorm produce the same output on any input.
False. RMSNorm skips mean-subtraction and divides only by the root-mean-square, so it is not invariant to shifting the row; it matches LayerNorm only when already equals .
Spot the error
"LayerNorm fixes internal covariate shift by making every feature's distribution match across the batch."
The batch/feature axes are swapped. LayerNorm stabilizes the per-example distribution across its own features; it never looks at other examples, so it cannot equalize a feature across a batch.
"We normalize to unit variance, therefore the output activations are guaranteed to stay unit-variance going into the next layer."
The learnable (and the next layer's weights) rescale the signal afterward, so post- activations need not be unit-variance — normalization is a starting point, not a permanent constraint.
"LayerNorm needs a running mean and variance stored for test time, just like BatchNorm."
No stored statistics exist. Each example computes its own live, so train and inference are byte-for-byte the same procedure.
"Because is , it's safe to say ."
The approximation is fine numerically but conceptually the lives inside the square root: , not — the placement matters for the degenerate near-constant case.
"LayerNorm removes the need for residual connections since both stabilize training."
They solve different problems: residuals give gradients a shortcut path (fighting vanishing gradients through depth); LayerNorm controls the scale/center of activations. Modern Transformers use both together.
"Since standardizing gives mean , the shift can only ever make things worse."
lets the network re-introduce a nonzero mean when the downstream activation prefers it (e.g. feeding a ReLU); it adds freedom, and the net learns if zero-mean is actually best.
Why questions
Why does LayerNorm normalize across features instead of across the batch?
To make each example self-contained, so statistics don't depend on batch-mates — enabling batch size 1, per-token autoregressive decoding, and identical train/test behaviour.
Why is placed inside the square root rather than added afterward?
So that when the denominator smoothly floors at (a small positive number), keeping the division well-defined instead of blowing up.
Why can LayerNorm afford to ignore the overall scale of the incoming vector?
Because an earlier layer multiplying all its outputs by cancels in , so that scale explosion never reaches the next layer — exactly the stability we wanted.
Why do Transformers prefer LayerNorm over BatchNorm specifically?
Transformers process variable-length sequences token by token, where a "batch" of activations is unreliable; LayerNorm's batch-independence and train=test consistency fit that regime.
Why does the affine step use per-feature rather than a single shared scalar?
Different features may need different scales/shifts to suit the next layer, so per-feature parameters give the network fine-grained control to reshape each dimension independently.
Why doesn't forcing variance destroy the information in the vector?
Standardizing is an invertible affine map on the row (subtract, divide) plus the invertible restore — relative differences between features survive; only the overall center and scale are made controllable.
Edge cases
A row is exactly constant, . What does LayerNorm output (γ=1, β=0)?
, so every deviation is and ; then . The output is the all-zero vector — prevents a NaN and the constant collapses to zero.
(a single feature). What happens?
, so and ; the output is (then ). LayerNorm is essentially meaningless for one feature — there is no spread across features to normalize.
Two rows that differ only by an overall shift, e.g. and . Same ?
Yes. Shifting a whole row by a constant cancels in , so both standardize to the identical — LayerNorm is shift-invariant per row.
A row with one huge outlier, . Does LayerNorm tame it?
Partially. The outlier inflates , so dividing shrinks all values, but the shape (one dominant feature) survives — LayerNorm rescales, it doesn't clip or remove outliers.
Batch of size 1 during inference. Any problem for LayerNorm?
None. It never used the batch dimension, so a single example is processed exactly as during training — unlike BatchNorm, which would have degenerate batch statistics.
Feeding LayerNorm's output into a saturating activation like tanh with tiny .
With small the inputs stay near where tanh is roughly linear, so gradients flow well; the network learns to place activations in the useful part of the nonlinearity, which is why isn't redundant.
Recall One-sentence self-test
If I can't state which axis LayerNorm averages over and why that axis makes it batch-independent, I haven't learned the topic — everything else (ε, γ, β, invariances) hangs off that single fact.