ML & Deep Learning Foundations·Question 24 of 55Intermediate

What are vanishing and exploding gradients? What causes them, and what does modern architecture design do about them?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Backprop multiplies a chain of layer Jacobians. If those factors are typically <1 in magnitude, the product shrinks geometrically with depth - early layers get essentially zero gradient and stop learning (vanishing). If factors are >1, the product blows up - loss spikes, NaNs (exploding). Same mechanism, opposite sign of log-magnitude.

Full worked answer

Backprop multiplies a chain of layer Jacobians. If those factors are typically <1 in magnitude, the product shrinks geometrically with depth - early layers get essentially zero gradient and stop learning (vanishing). If factors are >1, the product blows up - loss spikes, NaNs (exploding). Same mechanism, opposite sign of log-magnitude.

Classical causes: saturating activations (sigmoid's max derivative is 0.25; tanh saturates at extremes), poorly scaled initialization, and depth or recurrence (RNNs multiply by the same recurrent Jacobian per timestep, making them the pathological case - historically fixed by LSTM/GRU gating).

Modern fixes, each attacking a different link in the chain:

  • Residual connections: y = x + f(x) gives Jacobian I + ∂f/∂x - the identity term provides a gradient highway that never vanishes, letting 100+-layer networks train. This is the single most important trick, and transformers are residual networks through and through.
  • Normalization (LayerNorm/RMSNorm): keeps activation scales controlled so Jacobians stay well-conditioned; pre-norm placement (norm before each sublayer) keeps the residual path clean and is why GPT-2-onward models train stably at depth.
  • ReLU/GELU activations: derivative ~1 on the active region, no two-sided saturation.
  • Variance-preserving init (Xavier/He): start with Jacobian factors near unit scale.
  • Gradient clipping (global norm, typically 1.0): a backstop against explosion - it rescales pathological updates rather than preventing the cause.

Diagnosis in practice: log per-layer gradient norms. A geometric decay across depth = vanishing; sudden grad-norm spikes preceding loss spikes = exploding, common in LLM pretraining and handled with clipping, LR reduction, or skipping the offending batch.

What a good answer covers

  • Backprop multiplies a chain of layer Jacobians
  • If those factors are typically <1 in magnitude, the product shrinks geometrically with depth - early…
  • If factors are >1, the product blows up - loss spikes, NaNs (exploding)
  • Same mechanism, opposite sign of log-magnitude
  • Classical causes: saturating activations (sigmoid's max derivative is 0.25; tanh saturates at extremes),…

Key terms: vanishing · exploding · Residual connections · Normalization · pre-norm · ReLU/GELU · Variance-preserving init · Gradient clipping

Interviewer follow-ups to expect

  1. Why exactly does I + ∂f/∂x fix gradient flow?

  2. Why do pre-norm transformers tolerate less warmup than post-norm?

  3. Your 30B pretraining run shows recurring loss spikes - what's your playbook?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep