TensorTau PathToAGI Training Deep Networks Level 07

Level 07 · Training Deep Networks · Chapter 098

Vanishing and Exploding Gradients

Why can gradients disappear to zero—or blow up—when backpropagated through many layers or time steps?

Backprop repeatedly multiplies local Jacobians. In a scalar simplification,

∂L∂x0=∂L∂xn∏k=1n∂xk∂xk−1.\frac{\partial L}{\partial x_0}=\frac{\partial L}{\partial x_n}\prod_{k=1}^{n}\frac{\partial x_k}{\partial x_{k-1}}.

If each factor is about 0.5, then after 20 layers:

0.520≈9.5×10−7.0.5^{20}\approx9.5\times10^{-7}.

If each factor is 1.5:

1.520≈3325.1.5^{20}\approx3325.

1. Vanishing

Early layers receive almost no learning signal. Saturating sigmoid/tanh derivatives can contribute strongly to this.

2. Exploding

Huge gradients create unstable parameter jumps, NaNs and divergence.

3. Remedies are connected

Careful initialization controls early scale. ReLU-like activations reduce saturation. Normalization stabilizes distributions. Residual connections shorten effective gradient paths. Gradient clipping limits extreme updates.

These are not disconnected tricks; they attack signal propagation from different angles.

4. Diagnose, do not guess

Log per-layer gradient norms:

for n,p in model.named_parameters():
    if p.grad is not None:
        print(n, p.grad.norm().item())

A healthy training loop observes gradients rather than assuming they are fine.

What to Remember

Depth multiplies derivative effects. Stable deep learning requires controlling the scale of forward activations and backward gradients.

Next → Batch Normalization: can we explicitly stabilize intermediate activation statistics during training?

Six ways to work the chapter, climbing from explaining it in your own words to investigating it like a researcher. Reading is not enough — this is where the chapter lands.

  1. Explain: Why repeated multiplication causes vanishing/exploding effects.
  2. Calculate: Compute 0.8^30 and 1.2^30.
  3. Predict: Why can saturated sigmoid layers worsen vanishing gradients?
  4. Break: Create a deep MLP with pathological initialization and inspect gradient norms.
  5. Build: Add gradient-norm logging hooks.
  6. Investigate: Compare initialization/activation choices across depth.