Skip to content
BIASED

Normalization and initialization

Why signal and gradient scale multiply at every layer, Glorot and He initializations, BatchNorm and related layers, residual connections, and a thirty-layer experiment.

From regularization to scale

The topic Losses and regularization trained a three-layer net and asked how to keep it from fitting its training set too well. A network of thirty layers has the opposite problem first: at the default initialization it does not fit its training set at all. Signal and gradient are each multiplied by a factor every layer; over thirty layers any factor other than one grows or shrinks geometrically. This topic derives initializations that set that factor to one, shows what normalization layers compute, and explains how a residual connection carries signal and gradient through depth.

Notation. Pre-activation zl=Wlhl−1z_l = W_l h_{l-1}, activation hl=φ(zl)h_l=\varphi(z_l); fan-in nl−1n_{l-1}, fan-out nln_l; weight variance vlv_l; adjoint δl=∂L/∂zl\delta_l=\partial L/\partial z_l. For normalization: batch size BB, mean μ\mu, variance σ2\sigma^2, standardized x^\hat x, learned γ,β\gamma,\beta.

Scale at every layer

For independent zero-mean weights,

Var⁡(zl)=nl−1vlκVar⁡(zl−1),κ=E[φ(z)2]Var⁡(z),\operatorname{Var}(z_l)=n_{l-1} v_l \kappa\operatorname{Var}(z_{l-1}),\quad \kappa=\frac{E[\varphi(z)^2]}{\operatorname{Var}(z)},

and backward Var⁡(δl−1)=nlvlκ′Var⁡(δl)\operatorname{Var}(\delta_{l-1})=n_l v_l \kappa'\operatorname{Var}(\delta_l) with κ′=E[φ′(z)2]\kappa'=E[\varphi'(z)^2]. For ReLU and symmetric zz, κ=κ′=12\kappa=\kappa'=\tfrac12. Over LL layers both products are raised to power L−1L-1.

On 50 width-256 ReLU layers: unscaled v=1v=1 overflows by layer 25; v=1/nv=1/n and PyTorch's default 1/(3n)1/(3n) crush the signal; only v=2/nv=2/n keeps both forward and backward scales usable. A thirty-layer digit net at default init stays at loss ln⁡10=2.303\ln 10=2.303 for all of training.

Glorot and He

Glorot (symmetric activations near linear): compromise vl=2/(nl−1+nl)v_l=2/(n_{l-1}+n_l).

He (ReLU): fan-in mode vl=2/nl−1v_l=2/n_{l-1}. The backward product then telescopes to nL/n1n_L/n_1, independent of depth. For a 256×256256\times 256 layer, Glorot std 2/512=0.0625\sqrt{2/512}=0.0625, He 2/256≈0.0884\sqrt{2/256}\approx 0.0884.

PyTorch's nn.Linear default is uniform with variance 1/(3nin)1/(3n_{\mathrm{in}}) — He's form with gain squared 1/31/3, six times too small for a plain ReLU stack; it relies on normalization layers to restore scale.

What init cannot fix. After a He-initialized ReLU layer the correlation of two inputs follows the arc-cosine kernel; from orthogonal inputs it climbs to 0.9880.988 by layer 50. Every example maps toward the same direction — rank collapse. Init sets scale at step 0; it does not keep examples apart during depth.

Batch normalization

Batch normalization standardizes each feature over the batch:

x^i=xi−μBσB2+ϵ,yi=γx^i+β.\hat x_i=\frac{x_i-\mu_B}{\sqrt{\sigma_B^2+\epsilon}},\qquad y_i=\gamma\hat x_i+\beta.

Training uses batch statistics and updates running averages; evaluation (model.eval()) uses the averages. Gradients through the batch statistics sum to 0 and are orthogonal to x^\hat x; each example's gradient depends on the others.

Small batches hurt: with B=2B=2 standardized values are always ±1\pm 1. Running averages lag after large weight changes. Explanations of why BN helps (internal covariate shift, scale invariance, identity bias in ResNets, noise) are still debated; the practical facts are larger stable learning rates and faster training of deep convnets.

Other normalization axes

Every norm computes y=γ⊙(x−μS)/σS2+ϵ+βy=\gamma\odot(x-\mu_S)/\sqrt{\sigma_S^2+\epsilon}+\beta; they differ only in the set SS:

layer SS
BatchNorm one channel, all examples and positions
LayerNorm one example, all channels (in a Transformer: one token's features)
InstanceNorm one example, one channel
GroupNorm one example, a group of C/GC/G channels (G=32G=32 typical)

Only BatchNorm's set crosses examples, so only it depends on batch size and has two modes. LayerNorm alone does not undo rank collapse in a plain stack — it restores per-example scale without comparing examples. Residual architectures are what make LayerNorm work in Transformers.

Residual connections

A residual block xl+1=xl+Fl(xl)x_{l+1}=x_l+F_l(x_l) has Jacobian I+∂Fl/∂xlI+\partial F_l/\partial x_l: an identity path for the gradient. At init, variances add: E[xl+12]=E[xl2]+E[Fl(xl)2]E[x_{l+1}^2]=E[x_l^2]+E[F_l(x_l)^2].

For a branch that returns the input's mean square, over L=50L=50 blocks from mean square 1: plain residual →2L\to 2^L; pre-norm F(LN(x))F(\mathrm{LN}(x)) →1+L\to 1+L; scaled F/LF/\sqrt L →(1+1/L)L<e\to (1+1/L)^L < e. The identity path also slows correlation growth between examples.

Thirty layers on digits

Thirty hidden layers of width 64 on digits, Adam, 12 epochs (means over seeds):

configuration cosine at init val accuracy
plain, default init 1.000 0.102
plain, He 0.993 0.834
plain, batch norm 0.335 0.556
plain, layer norm 0.995 0.100
residual, default 0.850 0.966
residual, pre-norm LN 0.758 0.961

Default stacks learn nothing; He restores gradient but not separation; BN separates examples but can explode gradients without residuals; LayerNorm alone fails like the default; residuals train to >96%>96\% validation accuracy.

Signals now keep their scale. Whether training then goes fast and ends somewhere good is up to the optimizer and its schedule. The next topic, Optimizing deep networks, closes the Training module with SGD+momentum, Adam, warm-up, clipping and the curves you watch.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • BatchNorm reduction axesoptional

    NumPy: mean/variance over (N,H,W) per channel; verify standardization. Self-check in the notebook.

    ~15 min · easier on a computer · Normalization and initialization read.

    Self-check in the notebook — not part of mastery or the certificate.

Full notes

Answers are saved on the server and tied to this browser until you sign in.