A deep neural network can have enough capacity to solve a task and still fail to learn because useful training signals do not reach all of its layers. Parameters near the output may update normally while earlier layers receive gradients that are almost zero. In the opposite case, gradients can grow so large that one optimizer step destabilizes the model.
These are the vanishing-gradient and exploding-gradient problems. They are not simply labels for “training is bad.” They describe what happens to derivatives as backpropagation repeatedly applies the chain rule through many transformations.
This article builds a practical way to reason about both problems. You will learn why depth can amplify them, what symptoms to measure instead of guessing from loss alone, how initialization, activations, residual paths, normalization, and gradient clipping affect the situation, and how to choose a fix that matches the cause.
Start with the chain rule
Consider a deliberately simple scalar network with three repeated multiplications:
h1 = w1 * x
h2 = w2 * h1
h3 = w3 * h2
loss = L(h3)The gradient of the loss with respect to w1 contains derivatives from every later stage:
dL/dw1 = dL/dh3 * w3 * w2 * xSuppose the relevant factors w2 and w3 are both 0.2. Their product is:
0.2 * 0.2 = 0.04With ten similar factors, the product is:
0.2^10 = 0.0000001024A backward signal multiplied by such factors can become tiny before it reaches early parameters. That is the basic mechanism behind a vanishing gradient.
Now replace 0.2 with 2:
2^10 = 1024Repeated factors larger than one can instead make the backward signal grow rapidly. That is the simplest picture of an exploding gradient.
Real neural networks use vectors, matrices, nonlinear activations, normalization, branching paths, and many different parameter values. Their gradients are not governed by one repeated scalar. The scalar example is useful because it exposes the core mechanism: backpropagation composes many local derivatives, and their combined scale determines whether a signal remains useful.
Vanishing and exploding are properties of a path
It is tempting to say that weights below one cause vanishing gradients and weights above one cause exploding gradients. That rule is too crude for real networks.
For a vector-valued layer, backpropagation involves multiplication by a Jacobian, the matrix of local derivatives. Along a chain of layers, the backward pass contains a product of Jacobians:
g_early = J1^T J2^T ... Jk^T g_lateThe effect depends on how those matrices transform the gradient vector, not on whether individual weight entries happen to be above or below one. Activation derivatives also participate. Some directions can shrink while others grow.
This leads to a better mental model:
forward path: representation is transformed layer by layer
backward path: gradient is transformed by local derivatives in reverseIf the backward transformations repeatedly contract important directions, early layers receive little learning signal. If they repeatedly expand directions, gradient magnitudes can become unstable.
Depth makes the issue important because there are more transformations to compose. Depth does not guarantee either failure: modern architectures are designed specifically to keep signals trainable across many layers.
Activation functions change gradient flow
Nonlinear activations contribute their own derivatives to the chain rule.
The sigmoid function is a classic example. Its derivative is:
sigmoid'(z) = sigmoid(z) * (1 - sigmoid(z))For finite z, this derivative is positive and no greater than 0.25. When z has large positive or negative magnitude, sigmoid approaches saturation and its derivative approaches zero. Repeated multiplication by small activation derivatives can therefore weaken gradients in deep sigmoid networks.
The hyperbolic tangent function also saturates for inputs with large magnitude, although its derivative can reach 1 near zero.
ReLU behaves differently:
ReLU(z) = max(0, z)Its derivative is 1 for positive inputs and 0 for negative inputs, apart from the convention chosen exactly at zero. ReLU avoids a small derivative on its positive side, but it introduces another failure mode: a unit that stays on the negative side can receive zero gradient through the activation. That is the dead-ReLU problem, not a guarantee that ReLU networks are immune to poor gradient flow.
Activation choice therefore changes one part of the gradient path. It does not remove the effects of weight matrices, architecture, loss scaling, or optimizer settings.
Initialization sets the starting signal scale
A network can begin training in a poor regime before the optimizer makes its first update. If initial transformations consistently shrink activations and gradients, signals can fade with depth. If they consistently amplify them, values can grow.
Variance-aware initialization schemes try to avoid that systematic drift at initialization. Xavier or Glorot initialization accounts for layer fan-in and fan-out and is commonly paired with activations such as tanh. He or Kaiming initialization accounts for the behavior of rectifier networks such as ReLU.
The important idea is not to memorize one initializer for every architecture. It is to preserve a reasonable signal scale under the assumptions of the activation and layer being initialized.
Those assumptions matter. Initialization controls the starting point, not the entire training trajectory. A network can still become unstable later because of an excessive learning rate, unusual loss scale, numerical issues, or architectural choices.
Diagnose gradient flow directly
A loss curve tells you whether optimization is succeeding. It usually does not tell you why it is failing.
When gradient flow is suspect, inspect gradients across depth. Useful measurements include:
- the L2 norm of each parameter tensor’s gradient;
- gradient norms grouped by layer or block;
- the ratio of update magnitude to parameter magnitude;
- activation statistics at different depths;
- whether values become non-finite during the forward or backward pass.
Suppose a 24-block network shows this pattern after several representative batches:
block 24 gradient norm: 8.0e-2
block 18 gradient norm: 4.5e-2
block 12 gradient norm: 7.0e-3
block 6 gradient norm: 9.0e-5
block 1 gradient norm: 2.0e-7That monotonic pattern is evidence that the backward signal is becoming much smaller toward the input. One batch is not enough to establish a robust diagnosis, because stochastic training naturally produces noisy gradients. Look for a persistent pattern across batches or steps.
An exploding case might instead show ordinary values for many steps followed by very large norms, a sharp loss spike, and eventually inf or NaN values. The first non-finite value is especially useful: later non-finite tensors may only be consequences of the original failure.
Absolute gradient norms also need context. A norm of 0.001 is not inherently bad, and a norm of 100 is not inherently wrong. Parameter scale, model width, loss reduction, batch size, and optimizer all affect magnitude. Compare layers, compare training steps, and connect the measurements to whether useful updates are occurring.
Residual paths shorten the difficult backward route
A residual block has the form:
y = x + F(x)Its derivative with respect to x contains two terms:
dy/dx = I + dF/dxThe identity term provides a direct gradient path that does not require the backward signal to pass only through every operation inside F. This is one reason residual architectures make very deep networks easier to optimize.
The statement needs an important boundary: residual connections do not guarantee stable training. Branch scale, normalization placement, initialization, optimizer settings, and the rest of the architecture still matter. A residual branch that produces badly scaled values can destabilize the network even though an identity path exists.
Use residual connections as an architectural mechanism for improving information and gradient flow, not as a substitute for measuring what the model is doing.
Normalization can stabilize intermediate scales
Normalization layers can reduce large changes in the scale of intermediate representations. Batch normalization uses batch-derived statistics during training and typically running statistics during evaluation. Layer normalization normalizes features within each example according to its defined normalized dimensions and is widely used in transformers.
By controlling intermediate activation scale, normalization can make optimization less sensitive to some parameter-scale changes. It can therefore contribute to stable gradient flow.
But normalization is not simply “a fix for exploding gradients.” Different normalization methods have different statistics and train/evaluation behavior, and their placement changes the computation. Adding a normalization layer to an architecture can change the model’s function and optimization dynamics. Treat it as an architectural design choice rather than an emergency patch applied without measurement.
Gradient clipping limits an update but does not repair the cause
When gradients occasionally become extremely large, gradient clipping can keep an optimizer step within a chosen bound. Global norm clipping is a common form. Conceptually, for gradient vector g and maximum norm c:
if ||g|| > c:
g_clipped = g * c / ||g||
else:
g_clipped = gThis preserves the gradient direction while reducing its global magnitude when the threshold is exceeded.
Clipping is useful when large gradients are an expected risk, as in some recurrent or otherwise unstable training settings. It can also prevent a rare spike from destroying an otherwise healthy run.
It does not solve vanishing gradients, and it does not explain why gradients exploded. If clipping activates on nearly every step, investigate the underlying scale: learning rate, initialization, loss computation, numerical precision, data outliers, and architecture are all plausible contributors.
The clipping threshold is therefore a hyperparameter to measure, not a universal constant. Log the unclipped norm and how often clipping occurs. Without those measurements, aggressive clipping can hide instability while silently changing optimization.
Learning rate and gradient magnitude are different problems
The gradient tells the optimizer about the local loss landscape. The learning rate helps determine how strongly the optimizer responds.
For plain gradient descent:
parameter_update = -learning_rate * gradientA very large learning rate can make updates unstable even when gradients are finite and reasonably scaled. Conversely, lowering the learning rate can make an exploding-gradient symptom less destructive without fixing the mechanism that produced the large gradient.
Adaptive optimizers complicate the exact update because they maintain state derived from past gradients, but the distinction remains useful: gradient scale and optimizer step scale are related, not identical.
When debugging, record both if possible. A model with modest gradients and huge relative parameter updates points toward a different problem than a model whose raw gradients themselves suddenly become enormous.
A practical debugging sequence
When a deep model stops learning or becomes unstable, change one thing at a time when practical. A useful sequence is:
- Verify the loss and data first. A malformed target, wrong reduction, extreme input, or invalid value can imitate an optimization problem.
- Record per-layer gradient norms over multiple steps. Look for systematic decay with depth, sudden spikes, zeros, and the first non-finite values.
- Inspect activation statistics. Saturated nonlinearities or rapidly growing activations provide evidence about the forward side of the same problem.
- Check initialization against the layer and activation assumptions. This is especially important when implementing a network from scratch.
- Check the learning rate and update-to-parameter ratios. Separate oversized optimizer steps from oversized raw gradients.
- For deep architectures, examine whether residual paths and normalization are being used and placed as intended by the architecture.
- If large gradient spikes remain a known property of the training setup, evaluate gradient clipping and log how frequently it activates.
This order prevents a common debugging mistake: applying several stabilizers at once, observing that training improves, and never learning which problem actually existed.
Common mistakes
Treating every flat loss curve as vanishing gradients
A flat loss can come from bad labels, frozen parameters, detached tensors, an inappropriate learning rate, saturated activations, or a model that simply cannot fit the task. Confirm that gradients are actually small where learning is expected before diagnosing vanishing gradients.
Looking only at one global gradient norm
A global norm can hide depth-specific behavior. A large output layer may dominate the total while early layers receive almost no signal. Per-layer or per-block measurements reveal the shape of gradient flow.
Assuming clipping fixes instability
Clipping constrains gradient magnitude after the backward pass. It does not correct a forward computation that has already produced non-finite values, and it does not repair a systematically poor initialization or invalid loss.
Comparing raw norms across unrelated models
Gradient magnitude depends on parameter count, tensor shape, loss scaling, batch construction, and other implementation details. Trends within one training setup are often more informative than an absolute threshold copied from another model.
When simpler action is enough
Not every training run needs special gradient machinery. If a modest network trains stably, gradients reach all trainable layers, validation behavior is sensible, and values remain finite, adding clipping or extra normalization can create complexity without solving a demonstrated problem.
Start from an architecture and initialization appropriate for the task, use a defensible learning rate, and instrument the run. Add a stabilization technique when measurements identify a failure mode it can actually address.
For example, occasional large but finite gradient spikes may justify clipping. A strong decay in gradient norms through a deep plain stack points more toward architecture, activation, or initialization. Non-finite activations before backward begins point toward the forward computation rather than gradient clipping.
Conclusion
Vanishing and exploding gradients are consequences of how derivatives compose through a network. Repeated contraction can starve early layers of learning signal; repeated expansion can make updates unstable. The useful response is therefore not to reach for one universal fix, but to observe the gradient path and identify where scale is being lost or amplified.
Measure gradients across depth, inspect activations, and separate raw gradient problems from optimizer-step problems. Initialization and activation choice shape the starting conditions, residual connections create shorter backward paths, normalization can stabilize intermediate scales, and clipping can contain large gradient spikes. Each tool addresses a different part of the system.
Once you reason about gradient flow as a path of composed transformations, training failures become easier to diagnose—and fixes become choices you can justify rather than rituals you apply blindly.