Xavier/He initialization, vanishing and exploding gradients
What it is
Every layer scales both forward activations and backward gradients. When many scales below one multiply together, early layers receive vanishing gradients; when scales above one compound, values or updates explode. Xavier initialization chooses variance based on fan-in and fan-out for roughly variance-preserving tanh-like layers, while He initialization is calibrated for ReLU-like layers that discard half their signal. Gradient clipping is a safety mechanism for occasional extreme updates, not a substitute for a consistently ill-scaled model.
Why it matters
Bad initialization can make a correct model appear broken before it has learned anything. These are signal-scale problems, not evidence that the dataset is impossible. Watching activation and gradient distributions by layer can distinguish a structural scaling failure from ordinary underfitting, and is especially valuable in deep recurrent or Transformer training.
In the real world: The right starting weights are the difference between a deep model that trains and one that never does.
Visual example
Gradient healthUseful gradients stay in a workable range across layers.
import torch.nn as nn
layer = nn.Linear(256, 256)
nn.init.kaiming_normal_(layer.weight, nonlinearity="relu") # ReLU stacks
nn.init.zeros_(layer.bias)
tanh_layer = nn.Linear(256, 256)
nn.init.xavier_uniform_(tanh_layer.weight) # tanh/sigmoidInitializing every weight to zero. Symmetric neurons get identical gradients and remain identical, so a whole layer learns only one feature.
Practise it: ReLU, Forward and Backward