When Do Vanishing Gradients Occur?

Vanishing gradients occur when the training signal reaching the early layers of a neural network becomes too small to guide useful updates. The output layer can still be learning. The clue is not just a…

Arcade-style bars shrink from the output layer toward earlier layers, illustrating vanishing gradient magnitudes during backpropagation.

Vanishing gradients occur when the training signal reaching the early layers of a neural network becomes too small to guide useful updates. The output layer can still be learning. The clue is not just a flat loss curve: it is a persistent difference between the gradients near the output and those near the input.

Why the signal shrinks on the way back

Think of a network as a sequence of function calls. On the forward pass each call transforms a value. On the backward pass the question is different: if the input to one call changes slightly, how much does the final loss change? The chain rule multiplies the local sensitivities along the path. In a single chain, repeatedly multiplying by a number much smaller than one attenuates the signal. The analogy has a limit: real layers transform vectors, and contributions from multiple paths can add or cancel. For the mechanics of weight updates, see how backpropagation trains a neural network.

A ten-layer example you can check

Take a scalar layer with weight 1 and activation sigmoid(x). At zero, the sigmoid derivative is exactly 0.25. Set the bias in each successive layer so that its input to the sigmoid is zero. With a unit gradient at the output, the gradient magnitude one layer back is 0.25. What reaches the beginning of ten such layers?

gradient = 1.0
for layers_back in range(1, 11):
    gradient *= 0.25
    if layers_back in (1, 5, 10):
        print(f"{layers_back:2d} layers back: {gradient:.9g}")
 1 layers back: 0.25
 5 layers back: 0.0009765625
10 layers back: 9.53674316e-07

That last value is less than one millionth of the incoming gradient, even though none of the sigmoids is saturated. This is a controlled example of the gradient with respect to the input, not a prediction that every weight gradient in every ten-layer network will have this size. In an actual layer, the weights matter too. For example, tanh has slope 1 at zero but approaches slope 0 far from zero.

How to diagnose it during training

After the backward pass and before clipping or the optimizer step, record the magnitude of the weight gradients in an early, middle, and late layer. To compare layers with different parameter counts, use the root mean square of their gradients: the L2 norm divided by the square root of the number of weights. Repeat over several batches with the same loss reduction; there is no universal cutoff.

  • The output has a signal but early layers repeatedly have tiny gradients: inspect the activation values and the initial weight scale. Sigmoids near 0 or 1 and tanh units near −1 or 1 are saturated. See Glorot and Bengio’s study of deep feedforward networks for why both activation and initialization matter.
  • A gradient is missing altogether: check whether the parameter is frozen or disconnected from the loss. A missing gradient is not evidence that repeated multiplication made it small.
  • Gradients are present, but parameters barely change: inspect the learning rate and actual update size before replacing the activation. A tiny learning rate can make updates small even when gradients are healthy.

What helps, and what does not

ReLU passes the gradient through its activation on positive inputs, but has zero derivative on negative inputs. It is not a guaranteed cure: an inactive unit can receive no gradient through that path. Compare the curves in the activation function chart. Match the initialization to the activation, then rerun the same diagnostic. In a deeper architecture, a residual connection can also provide a shorter route for the backward signal.

Exploding gradients are the opposite pattern: the backward signal grows rather than shrinks. They are not exclusively a “large weights” problem. Pascanu, Mikolov, and Bengio analyze both problems in recurrent networks and describe gradient norm clipping for explosions. Clipping caps an excessively large norm; it does not amplify a vanishing one.

Further reading

Chapter 8 of Goodfellow, Bengio, and Courville’s Deep Learning, available from the authors, places this problem in the broader context of optimization. The online chapter is free.

If you prefer the print edition, the following is a paid link. As an Amazon Associate I earn from qualifying purchases.

View the hardcover edition of Deep Learning on Amazon US.

Original article credited to Roderick (Rodd) M.