Vanishing and Exploding Gradients
Vanishing and exploding gradients are two typical numerical pathologies during backpropagation in deep networks: the former leaves shallow-layer parameters with almost no effective updates, while the latter makes the update steps so large that training diverges. Together they reveal that "depth" is not a free lunch, and they are the necessary prerequisite for understanding residual connections, normalization, activation function choice and gradient clipping.
Core Principles
Backpropagation is essentially a chain of multiplications under the chain rule. If the spectral norm of each layer's local Jacobian is less than one, repeated multiplication makes the gradient decay exponentially toward zero, which is vanishing gradients; if greater than one, it amplifies exponentially, causing numerical overflow, which is exploding gradients. The derivative of the activation function participates directly in this product: sigmoid's derivative approaches zero in the saturated region, so stacking multiple layers inevitably exhausts the signal, which was especially fatal in early recurrent networks.
Vanishing gradients manifest outwardly as shallow layers barely learning: the model seems able to fit but cannot learn long-range dependencies; in recurrent networks they manifest as failing to remember distant information. Exploding gradients manifest as the loss suddenly jumping to infinity or nan, with parameters instantly becoming huge garbage values.
Mainstream countermeasures each target something specific. Switching the activation to ReLU and its variants keeps the derivative at one in the positive region, easing decay. Residual connections let gradients pass straight through an identity path, turning multiplication into addition and making extremely deep networks trainable. Normalization layers pull each layer's input distribution back to a stable scale, improving the Jacobian properties. Gated structures such as LSTM guard long-term memory with an additive path on the cell state. Gradient clipping works on the exploding side, truncating the magnitude of updates by norm.
Joint Analysis Along Layers and Along Time Steps
In long-sequence modeling the gradient is multiplied along time steps, so even if the per-step Jacobian spectral radius is slightly below one, after several hundred accumulated steps it vanishes completely; gated or linearized paths are therefore needed to convert multiplication into addition. In deep feedforward networks the same reasoning appears as layer-by-layer multiplication. For diagnosis, plot the logarithm of gradient norms layer by layer: a healthy network shows a roughly flat or slowly declining shape; an obvious exponential slope calls for adjusting initialization or adding normalization. Care is also needed when resuming after an interruption: if the original schedule is kept while the learning rate and optimizer state do not match, the loss often jumps, and a safe practice is to slow down briefly before resuming the original rhythm.
Key Points
Initialization: proper variance-scaled initialization keeps activation and gradient variance roughly preserved across layers and is an invisible line of defense.
Gradient clipping: clip by global norm, with a threshold often around one; it is almost mandatory for large recurrent networks.
Loss scaling: in mixed-precision training, use loss scaling to prevent underflow and skip the step when inf is detected.
Residuals and normalization: the most effective and cheapest general measures; use them first.
Diagnosis: record gradient norms and activation distributions per layer and observe whether they decay exponentially with depth.
Common Misconceptions
Some think vanishing gradients only happen in very deep networks, while in fact shallow recurrent networks show it within a few steps. Others blame all training loss oscillation on the learning rate when the real cause is exploding gradients; in that case add clipping first, then tune the learning rate. Another misconception is that normalization can replace good initialization, whereas the two are complementary rather than mutually exclusive.
Application Scenarios
Training extremely deep convolutional networks, recurrent networks and long-sequence modeling, Transformer pretraining, large-scale mixed-precision training, multi-step return propagation in reinforcement learning, deep stacking of generative models.