2.9 — Vanishing and exploding gradients
Goal: Explain the multiplicative chain of g'(z) along the backward pass and why sigmoid kills depth while ReLU survives.
1. Why this session exists
The backprop recursion from 2.6,
is a product over layers. Whatever happens at the top gets multiplied by a chain of Jacobian factors as it propagates to the bottom. If those factors are systematically , the gradient signal vanishes before reaching the input layers. If they are systematically , it explodes. Either way, training stalls — vanishing because layer-1 weights stop receiving meaningful updates; exploding because the optimiser overshoots into noise.
This session quantifies the chain and pins down why ReLU saved deep learning circa 2012.[1, 2]
2. The multiplicative chain
Iterating the recursion from layer down to layer and ignoring the matrix factors for a moment (treating them as "approximately norm-preserving" — we'll fix this in 2.10),
with the product running from layer to layer and "typical" meaning the geometric mean of the per-unit derivatives along the path. The size of the gradient at layer 1 is set by this product.
If at every layer, then . For sigmoid, , so depth kills the gradient by a factor of . Vanishing gradient.
If , then blows up. Exploding gradient.
The matrix factors can rescue or destroy this in either direction — which is why we'll spend all of 2.10 on initialisation.
3. Sigmoid: vanishing by construction
Recall from 2.3 that , with equality only at . At typical operating points , . So the multiplicative factor at each layer is at most , and usually around .
For depth , , depending on operating points. The gradient at layer 1 is not getting useful training signal. This is the entire reason sigmoid hidden layers were abandoned around 2010–2012.
Tanh is slightly better: , with maximum at . But for the derivative is again close to , and the chain still shrinks. Tanh deep networks were trainable but slow; the AlexNet jump in 2012 was largely about replacing them with ReLU.
4. ReLU: vanishing is gone (on the active side)
For ReLU, . On the active side (), the multiplicative factor is exactly — gradient passes through undamped. On the dead side (), it is — gradient is killed completely for that unit.
The key statistical fact: a path from layer 1 to the loss is alive iff every ReLU along the way is active. If we initialise weights so each ReLU is active with probability (which is what symmetry around zero gives), then a single fixed path of length is alive with probability . But there are exponentially many paths, and they share weights — so the effective gradient at layer 1 stays bounded as grows, provided the weight matrices have the right scale.
That "right scale" is the He initialisation of 2.10: . It compensates for the factor of from dead ReLUs.
5. The exploding side
For unbounded activations or aggressively scaled weights, the per-step product can be , and the gradient explodes exponentially. Classical example: linear RNNs (no nonlinearity, weights unbounded) — the backprop product becomes the matrix power for time steps, and the largest eigenvalue of controls everything.
The clean clinical fix is gradient clipping: after computing the gradient, scale it down to a fixed norm threshold ,
This caps the maximum step size in parameter space and prevents the optimiser from veering off into infinity. Standard practice in RNNs and Transformers; clip threshold is typically .
6. What this implies for activation choice
- Avoid pure sigmoid / tanh in hidden layers. Their derivatives are bounded above by and respectively, and saturate fast. The gradient chain shrinks geometrically with depth.
- Prefer ReLU / GELU / SiLU. Their derivatives are bounded by everywhere on the positive side and don't go far above on the negative side. The chain is roughly preserved.
- Use the right initialisation (2.10) so the matrix factors don't unilaterally rescale the chain.
- Use residual connections (Chapters 4, 5) — they bypass the multiplicative chain entirely by adding the input to the output, .
The combination of "good activation + good init + residuals + layernorm" is essentially the entire story of how networks with 50–100+ layers became routine in the 2015–2020 stretch.
7. Takeaways
- The backprop signal at layer is a product of per-layer Jacobian norms.
- Sigmoid: typical factor → vanishing for .
- ReLU: typical factor on the active side → vanishing solved (modulo dying units).
- Exploding: rare with bounded activations, common in unbounded ones; fix with gradient clipping.
- Modern recipe: ReLU/GELU + He init + residual connections + layernorm.
(a) Compute at . For a sigmoid hidden net of depth with typical operating point , estimate the ratio .
(b) For ReLU at depth , assume each unit is active with probability . What is the probability that a single fixed path from input to output is alive end-to-end? With units per layer, what is the expected number of live paths?
(c) Show that scaling ensures and preserves direction. Is the resulting update step still a descent direction for the original loss?
(d) Residual connection: . Compute and explain why this Jacobian "always contains as a term", letting gradient flow through even when saturates.
References
- [1]
Hochreiter, S. (1991). Untersuchungen zu dynamischen neuronalen Netzen. Diploma thesis, TU Munich. — First vanishing-gradient analysis in RNNs (2.9).
↩ - [2]
Bengio, Y., Simard, P., & Frasconi, P. (1994). "Learning long-term dependencies with gradient descent is difficult". IEEE Transactions on Neural Networks, 5(2), 157–166. — Formal vanishing-gradient analysis (2.9).
↩