Vanishing Gradients
Stack enough layers and the backward signal decays to nothing — residual connections are the highway that let it survive.
What vanishing gradients are
Why deep nets refused to train for decades
For decades, depth was the obvious way to make neural networks more powerful — and it didn’t work. Nets deeper than a handful of layers trained worse than shallow ones, not because they lacked capacity, but because the training signal never reached the early layers. The forward pass was fine. The backward pass was broken.
Here is the setup. Training has two halves: the forward pass runs the input through every layer and scores the output with a loss (for language models, cross-entropy on the next token). The backward pass then assigns blame — it computes, for every weight, how much the loss would drop if that weight moved. The blame is delivered by the chain rule, and the chain rule is a product: the gradient at layer 1 is the gradient at the loss multiplied by one local derivative per layer it passes through on the way back.
That product is the problem. If the typical factor is less than 1 — and with the classic activations it always was — the product shrinks exponentially with depth. Twenty layers of 0.5 is not “half as much signal,” it is 0.520 ≈ 9.5 × 10⁻⁷: about a millionth. Layer 20 gets a full-strength gradient; layer 1 gets noise. The early layers — the ones building the foundational features everything above depends on — effectively stop learning.
Definition. Vanishing gradients: during backpropagation, the gradient reaching layer k is a product of per-layer local derivatives from the loss down to k. When those factors are typically below 1, the product decays exponentially with depth, so early layers receive vanishingly small updates and stop learning.
Get the direction right, because it kills a common misconception: this is not a forward-pass or capacity problem. The deep net can represent the function fine — it just can’t be trained to, because the learning signal dies on the way back. And since every extra layer adds another sub-1 factor to the product, more layers make it worse, not better. That inversion — depth hurting — is exactly what stalled the field until the fixes below.
The mechanic
A product of local derivatives — and the identity path that survives it
Write the chain rule out for a 20-layer stack, where is the output of layer and is the loss:
Nineteen factors, multiplied. Each factor is the layer’s weight matrix times the derivative of its activation function — and the classic activations rig that product against you. The sigmoid’s derivative peaks at 0.25 (at input 0) and collapses from there: at input ±2 it is 0.105, at ±4 it is 0.018. Tanh peaks at exactly 1, but only at the single point 0 — at input 1 its derivative is already down to 0.42. Every saturated unit contributes a near-zero factor, and one near-zero factor anywhere in the chain zeroes the whole product.
Four things fixed this, and a transformer uses all of them:
- ReLU. Its derivative is exactly 1 everywhere it’s active — a factor that doesn’t shrink the product no matter how deep you stack. Modern LLMs use its smooth relatives, GELU and SwiGLU, which keep the property that matters here: a non-saturating slope near 1 for positive inputs. (ReLU’s own failure mode: a unit stuck in the negative region has derivative exactly 0 — “dead ReLU” — which is vanishing at the single-unit scale.)
- Residual connections. Reshape the layer from to . The derivative becomes . That leading 1 is the whole trick: multiply the factors out across 20 layers and among the terms is a pure identity path — a product of plain 1s that never touches a branch derivative. Even if every branch saturates to , the factor goes to 1, not 0, and the gradient rides the highway to layer 1 intact.
- Layer norm. Re-centers and re-scales each layer’s pre-activations, which keeps them in the activation’s responsive zone — derivatives near their peak instead of out in the saturated flats. It also keeps the residual stream’s scale from drifting upward layer after layer, which tames the exploding direction.
- Attention. RNNs had a second version of the same disease: to connect a word to context 50 tokens back, the gradient had to survive 49 sequential hops through the hidden state — the same shrinking product, through time instead of depth. Attention scores every pair of positions directly, so the path between any two tokens is one hop, regardless of distance.
Watch the product do its work. Start with sigmoid and no fixes, then flip the toggles: