How do you initialize deep networks, and why does it matter?
Written by the mlprep team · Updated
Walk me through weight initialization. Why do Xavier and He initialization exist, and what breaks if initialization is wrong?
The problem#
If weights are too small, activations and gradients shrink layer by layer. Learning is slow or stalls. If weights are too large, activations and gradients explode. The goal of initialization is to keep signal variance roughly stable through depth at the start of training.
Xavier / Glorot initialization#
For tanh or sigmoid-like activations, Xavier initialization chooses weight variance based on fan-in and fan-out:
Var(W) ~= 2 / (fan_in + fan_out)
This tries to keep both forward activations and backward gradients at a reasonable scale. It was designed for activations that are roughly symmetric around zero.
He initialization#
ReLU zeros out roughly half the activations. That changes the variance calculation. He initialization uses:
Var(W) ~= 2 / fan_in
This larger variance compensates for the dropped negative half of the signal. It is the standard default for ReLU-family networks.
What breaks in practice#
Bad initialization can look like a model, optimizer, or data problem:
- Loss is flat for many steps: gradients may be too small.
- Loss becomes NaN: activations or gradients may be exploding.
- Different random seeds produce wildly different results.
- Very deep models train only with tiny learning rates.
Normalization layers reduce sensitivity, but they do not remove the need for reasonable initialization. Transformers, for example, still need careful residual initialization, embedding initialization, and sometimes output-head scaling.
Senior/staff considerations#
Initialization interacts with architecture. A plain CNN, ResNet, transformer, and MoE model do not have identical stability constraints. Residual networks repeatedly add branch outputs to a residual stream, so residual branch scale can dominate depth stability. Transformers add attention and MLP updates many times, which is why Pre-LN, RMSNorm, warmup, and residual scaling matter.
For fine-tuning, initialization shifts from "how do I start from scratch?" to "which newly added layers are randomly initialized?" A randomly initialized classification head on top of a pretrained encoder may need a higher learning rate than the backbone, while LoRA adapters or prompt embeddings need carefully scoped initialization so they do not destroy pretrained behavior.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Initialization keeps activation and gradient variance stable at the start of training. Xavier fits tanh-like activations; He fits ReLU-like activations. In modern deep models, initialization still matters because it interacts with residual paths, normalization, warmup, and fine-tuning.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- Why does ReLU need a different initialization scale than tanh?
- How would you debug a model that produces NaNs in the first few hundred steps?
- How should initialization differ when fine-tuning a pretrained model with a new head?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions