Optimization/Weight Initialization

Lesson 4.32,492 words

Weight Initialization

The initial weights determine whether training can succeed before the first gradient step. Initialize every weight equal and all hidden units compute the same function forever; initialize too small or too large and the signal vanishes or explodes as it crosses depth.

╌╌╌╌

Gradient descent finds a direction to step; it cannot choose where to start. That choice is weight initialization, and for a deep network it matters: it sets whether the very first forward pass carries usable signal to the output and whether the very first backward pass carries usable gradient to the input. Two distinct failures follow from a careless choice: a symmetry that no gradient can break, and a scale that makes the signal vanish or explode with depth. This lesson derives the single variance condition that prevents both.1

We work with a plain feedforward net. Layer takes input , computes the pre-activation , and applies an elementwise nonlinearity . We write for the fan-in and for the fan-out of layer .

The symmetry-breaking problem

The most obvious initialization — set every weight and bias to zero — fails before training begins. Suppose and for all . Then every pre-activation in a layer is identical, so every unit computes the same activation, and backpropagation sends every unit the same gradient. Identical units that receive identical updates stay identical forever.

The argument is not limited to zero; it holds for any constant. Take two units in layer with equal incoming weight rows, , and equal biases. Then for every input their pre-activations agree, , so .

Constant init collapses a layer: equal weight rows give two units the same pre-activation, so backprop hands them identical gradients forever.

The gradient inherits the same equality. Writing for the error signal, backpropagation gives , and because units share both their outputs and (by the same collapse one layer up) their downstream weights, . The update is therefore identical:

The fix is randomness: sample each weight independently from a zero-mean distribution. Independent draws break the row equality at step , and from there the units diverge under their distinct gradients. Biases can safely start at zero, since they do not enter the symmetry argument, because the weights already distinguish the units. This leaves only the question of scale: from how wide a distribution should we draw?2

Variance propagation: the forward pass

Scale is not free to choose. Each layer is a linear map followed by a nonlinearity, and a linear map rescales variance. Track how the variance of the activations changes from layer to layer and a hard constraint appears: to keep the signal at a fixed scale across depth, the per-layer rescaling must be exactly .

Assume at initialization that the weights are i.i.d. zero-mean with variance , independent of the inputs, and (for this first pass) take the activation to be linear near zero, (true for about the origin). The bias starts at zero. A single pre-activation is a sum over the fan-in,

Because the are zero-mean and independent of the , the variance of a sum of independent products factors. Each weight is independent, so cross terms vanish and the variances add:

The middle step uses for independent zero-mean . Assuming the activations of the previous layer are identically distributed with variance and zero mean (so ), the sum is copies of the same term:

This is the variance recursion. The factor is the gain by which each layer multiplies the signal's variance. Iterating across layers compounds it:

The factor compounds geometrically with depth. If the gain exceeds the variance explodes; if it falls below it vanishes; only a gain of exactly keeps the signal at a fixed scale across arbitrary depth.

A worked example: variance through five layers

For example, take a network of width at every layer, unit-variance input , and the linear regime , and compare three weight scales. Sampling from a Gaussian with the stated standard deviation fixes , and the gain is .

  • Too small, : , gain . The variance after five layers is — the signal has shrunk by three orders of magnitude.
  • Preserving, : , gain . The variance stays at no matter how deep the stack.
  • Too large, : , gain . The variance after five layers is — a thousandfold blow-up, and each additional layer multiplies it again.

The table traces layer by layer.

Layer (too small) (preserving) (too large)

Only the middle column stays stable with depth. The figure plots the same three trajectories on a log scale, where the geometric decay and growth appear as straight lines fanning away from the flat preserving line.

Activation variance through five width- layers on a axis. The preserving gain holds a flat line; the gains and fall and rise as straight lines, since is linear in depth .

Variance propagation: the backward pass

The same calculation run on the gradient gives a second condition, and the two do not in general agree. Backpropagation pushes the error signal through the transpose of the weight matrix:

The two passes traverse the same weight matrix in opposite directions and sum over opposite fans. Forward, a unit collects incoming terms; backward, it collects outgoing terms. That asymmetry is what splits the two variance conditions.

The same layer seen both ways. Forward (blue) sums terms into each output; backward (red) sums terms into each input. The gain is one way and the other.

In the linear regime . The sum now ranges over the fan-out (the number of units the signal flows back from), so the identical variance argument yields

and across depth the gradient variance compounds by . Preserving gradient scale therefore demands

The forward condition gives ; the backward condition gives . Both can be satisfied exactly only when . The two conditions sit side by side:

PassQuantity trackedRecursion gainVariance condition
Forwardactivation
Backwardgradient

Xavier / Glorot initialization

Glorot and Bengio resolved the conflict with a compromise: take the harmonic-style average of the two targets so that neither pass is badly served. Set the variance to the reciprocal of the mean fan, which gives

This is Xavier (or Glorot) initialization.3 When it reduces to the exact both conditions require; otherwise it splits the difference, keeping forward and backward gains both near . Drawn from a uniform distribution , which has variance , matching the target variance fixes the bound:

Xavier rests on , which holds for but fails badly for the rectifier, and the rectifier is what modern networks use.

He initialization: correcting for ReLU

ReLU breaks the linear-regime assumption: it zeros every negative pre-activation, discarding half the signal. The fan-in derivation must be redone with that loss accounted for. For a symmetric zero-mean pre-activation , the rectifier keeps the positive half and flattens the negative half to zero.

ReLU halves the variance. A symmetric zero-mean input distribution (blue) loses its entire negative half to (shaded), leaving .

The factor of is exact, not heuristic. For symmetric about zero, the second moment of the rectified output splits into the negative half (which contributes nothing) and the positive half (which by symmetry carries exactly half the mass):

using in the last equality. So , and the forward recursion picks up that factor:

Setting the gain gives He (Kaiming) initialization, the same derivation as Xavier with one extra factor of to compensate for the variance ReLU removes:4

The catalogue of schemes

The same skeleton (zero mean, variance set by a fan count) generates every standard scheme. They differ only in which fan they use and whether they correct for a nonlinearity.

SchemeActivationNormal form Uniform bound
LeCunSELU, linear
Xavier / Glorot, sigmoid
He / KaimingReLU, leaky ReLU
Orthogonal(norm-preserving)deep / recurrent

The uniform bound is throughout, since has variance . For a leaky rectifier with negative slope the surviving fraction is , so He generalizes to .

For a square layer of width the three closed-form schemes place at (LeCun), (Xavier, which coincides with LeCun here because ), and (He). He is exactly twice the others, reflecting the factor that compensates for ReLU's halving.

for each scheme on a square layer with , in units of . LeCun and Xavier coincide at ; He doubles it to to offset ReLU's halving.

The failure mode: vanishing and exploding signal

When the per-layer gain departs from , the consequence is visible at the output as activation magnitude that decays toward zero or grows without bound across depth, and the backward pass mirrors it exactly.

Activation magnitude across depth. Gain below decays geometrically, gain above explodes, and the variance-preserving gain holds a flat scale.

The backward pass behaves identically: a sub-unit gain shrinks the gradient toward zero, so early layers stop learning (the vanishing gradient), while a super-unit gain blows it up, so updates diverge (the exploding gradient).

Gradient magnitude on the backward pass, plotted from output back to input. Bad init makes the gradient vanish (early layers learn nothing) or explode (updates diverge); good init keeps it flat.

The same instability has a distributional reading: the pre-activation spread at each layer should hold near unit variance. Good init keeps the histogram a fixed width; bad init collapses it to a spike (dead units, no gradient) or fans it out until the nonlinearity saturates (zero gradient at the tails).

Pre-activation spread by layer. Good init holds unit variance (center); too-small init collapses the distribution toward zero (left); too-large init fans it out until activations saturate (right).

Beyond i.i.d. draws

The variance analysis fixes the scale of independent draws but says nothing about their geometry. Two refinements address the residual instability that remains in very deep and recurrent nets.

MethodControlsGuaranteeCost
Xavier / Heper-element variancescale preserved in expectationclosed form
Orthogonalsingular valuesnorm preserved exactlyone QR per matrix
LSUVmeasured layer varianceunit variance on a real batchone forward pass

Initialization and normalization together

Good initialization sets the signal scale at step ; it cannot keep it set as the weights move during training. The modern practice pairs a variance-preserving init with a normalization layer (batch, layer, or group normalization) that re-centers and re-scales activations at every step, not just the first. Normalization makes the network far less sensitive to the exact init, but it does not remove the need for it: the very first forward pass, before any normalization statistics have stabilized, still relies on a sensible starting scale, and residual connections still need He-style init to keep their skip paths near unit gain.5

Initialization and training without normalization

The two closed-form schemes are named for two public papers, and the line of work that follows them is what lets modern networks skip normalization entirely.

  • The two source papers. The rule is Glorot and Bengio's, derived from exactly the forward/backward variance argument above; the extra factor of for rectifiers is He et al.'s, and it was the change that first let plain (unnormalized) -layer ReLU nets train.67
  • Fixup and training without normalization. Zhang, Dauphin, and Ma showed that a residual network can be trained to full accuracy with no normalization layer at all, purely by rescaling the initialization of the residual branches (-style shrinkage across blocks). The signal-preservation goal of this lesson, pushed far enough, removes the need for the normalization layer the previous section paired with it.8
  • Dynamical isometry. Pennington, Schoenholz, and Ganguli made the orthogonal-init argument precise: controlling the entire spectrum of the input-output Jacobian (not just its mean gain) — dynamical isometry — lets networks of layers train, far past what a variance-only argument can guarantee. It is the rigorous version of the preserve the norm exactly claim behind orthogonal init.9
  • Init for transformers. The warmup this module keeps invoking is partly an initialization patch: T-Fixup (Huang et al.) shows that scaling the initial weights of a transformer removes the need for a learning-rate warmup entirely, tying the two modules together — bad init and mandatory warmup are the same problem seen twice.10

In summary: break symmetry with independent zero-mean draws, set the variance to for ReLU (or for ), use orthogonal init in recurrent stacks, and use normalization to hold the scale steady as training proceeds.11 The next lesson studies the optimization landscape that this well-scaled signal must now descend.

Footnotes

  1. Goodfellow, Deep Learning, §8.4 — Parameter Initialization Strategies: why initialization sets whether deep training succeeds, and the heuristics that govern scale.
  2. Goodfellow, Deep Learning, §8.4 — the symmetry-breaking requirement: identical units receiving identical gradients never specialize, so random draws are mandatory.
  3. Goodfellow, Deep Learning, §8.4 — the Glorot/Xavier normalized initialization as a compromise between forward and backward variance preservation.
  4. Goodfellow, Deep Learning, §8.4 — rectifier-aware scaling: the extra factor of (He init) that refills the variance ReLU discards.
  5. Goodfellow, Deep Learning, §6.2, §8.2 — gradient flow and ill-conditioning: how per-layer gain off makes signal and gradient vanish or explode with depth, and why normalization complements init.
  6. Glorot & Bengio, Understanding the Difficulty of Training Deep Feedforward Neural Networks, AISTATS 2010 — the forward/backward variance argument and the initialization.
  7. He, Zhang, Ren & Sun, Delving Deep into Rectifiers, ICCV 2015 — the ReLU-aware factor of (He/Kaiming init) that enabled very deep rectifier networks.
  8. Zhang, Dauphin & Ma, Fixup Initialization: Residual Learning Without Normalization, ICLR 2019 — training deep residual nets to full accuracy by initialization alone, with no normalization layer.
  9. Pennington, Schoenholz & Ganguli, Resurrecting the Sigmoid in Deep Learning through Dynamical Isometry, NeurIPS 2017 — controlling the full Jacobian spectrum to train networks thousands of layers deep.
  10. Huang et al., Improving Transformer Optimization Through Better Initialization, ICML 2020 — T-Fixup: rescaling transformer init to remove the learning-rate warmup requirement.
  11. Stevens, Deep Learning with PyTorch, Ch. 6 — initialization in practice with torch.nn.init: Xavier/Kaiming helpers and pairing them with normalization layers.

╌╌ END ╌╌