The exploding gradient problem is a training instability in which the gradients of the loss grow exponentially as they are propagated backward through many layers or time steps, producing excessively large weight updates that destabilize or destroy the model. In the training of neural networks in artificial intelligence, it is the mirror image of the vanishing gradient problem, and practitioners often refer to it simply as exploding gradients.
Training with gradient descent assumes that a small step along the negative gradient reduces the loss. When gradient norms reach thousands or millions, that assumption fails: a single update can overshoot into a region of the loss landscape where the loss is enormous or numerically undefined.
Why gradients explode during backpropagation
Gradients explode because backpropagation multiplies many Jacobian matrices together, one per layer or time step. If the typical magnitude of these factors exceeds one, the product grows roughly exponentially with depth. A factor of only 1.1 repeated across 100 layers already amplifies the signal by more than 13,000 times.
In recurrent neural networks, the same weight matrix is applied at every time step, so the gradient through a sequence of length T contains that matrix raised to roughly the power T. When its largest singular value exceeds one, long sequences produce explosive gradients. This analysis, formalized in the early 1990s and revisited in work on training recurrent networks, explains why plain RNNs were notoriously hard to train.
The table below lists the main factors that push gradient magnitudes upward.
| Cause | Mechanism | Where it appears |
|---|---|---|
| Poor weight initialization | Layer gains above one compound with depth | Deep feedforward and convolutional networks |
| Recurrent weight reuse | Same matrix multiplied across many steps | Vanilla RNNs on long sequences |
| High learning rate | Large steps push weights into steep regions | Any architecture, especially early in training |
| Missing normalization | Activations drift and scale up layer by layer | Deep networks without LayerNorm or BatchNorm |
| Low-precision arithmetic | Overflow in FP16 turns large values into infinity | Mixed-precision training without loss scaling |
Symptoms and how to detect them
The most reliable diagnostic is to log the global gradient norm at every step. A healthy run shows a norm that fluctuates within a stable band; an exploding run shows sudden jumps of one or more orders of magnitude, often followed by a loss spike.
| Symptom | What it indicates | Severity |
|---|---|---|
| Loss becomes NaN or infinity | Numerical overflow in weights or activations | Run is usually unrecoverable |
| Sharp loss spike | One update overshot the stable region | Often recoverable with rollback |
| Gradient norm jumps 10x or more | Instability is starting to build | Early warning signal |
| Weights grow without bound | Repeated oversized updates | Model quality degrades steadily |
| Oscillating loss | Updates bounce across a steep valley | Training stalls without converging |
Not every loss spike comes from exploding gradients. Corrupted data batches, a learning rate schedule that rises too quickly during learning rate warmup, or optimizer state issues can produce similar curves, so the gradient norm log should be checked before applying a fix.
Techniques that prevent exploding gradients
Modern training stacks combine several complementary defenses, because no single technique removes the risk across all architectures and scales.
Gradient clipping is the most direct safeguard. Clipping by global norm rescales the full gradient vector whenever its norm exceeds a threshold, preserving its direction while capping its size. A threshold of 1.0 is a common default in large language model training, although values between 0.5 and 5 are used depending on the model and optimizer.
| Technique | How it helps | Trade-off |
|---|---|---|
| Gradient clipping by norm | Caps update size, keeps direction | Threshold needs tuning; can hide root causes |
| Careful initialization | Xavier or He schemes keep layer gain near one | Must match the activation function |
| Normalization layers | LayerNorm or BatchNorm stabilize activations | Extra computation; placement matters |
| Residual connections | Provide identity paths for gradient flow | Requires careful scaling in very deep stacks |
| Gated recurrent units | LSTM and GRU gates regulate gradient flow | More parameters than vanilla RNNs |
| Learning rate warmup | Starts with small steps while statistics settle | Slightly slower early progress |
| Dynamic loss scaling | Avoids FP16 overflow and underflow | Skips steps when overflow is detected |
Adaptive optimizers such as the Adam optimizer and AdamW normalize updates by a running estimate of gradient variance, which dampens the effect of large gradients. They do not eliminate the problem, however, because a sudden outlier gradient can still corrupt the moment estimates and trigger instability several steps later.
Exploding versus vanishing gradients
Both problems arise from the same multiplicative structure of backpropagation, but they fail in opposite directions and call for different responses.
| Aspect | Exploding gradients | Vanishing gradients |
|---|---|---|
| Gradient magnitude | Grows exponentially with depth | Shrinks exponentially with depth |
| Visible effect | Loss spikes, NaN values, divergence | Early layers stop learning |
| Detection | Easy, because failures are abrupt | Harder, because training merely stalls |
| Primary fix | Clipping and lower learning rates | Residual paths, gating, better activations |
Because exploding gradients fail loudly, they are easier to detect but more destructive: a single bad step can waste days of compute on a large run if checkpoints are infrequent.
Exploding gradients in large-scale training
In large transformer models, instability rarely looks like the textbook recurrent case. It tends to appear as intermittent loss spikes late in pretraining, linked to attention logit growth, outlier activations or interactions between high learning rates and optimizer state.
- Frequent checkpointing allows teams to roll back to a point before the spike and skip the offending data batches.
- QK normalization and logit soft-capping limit the growth of attention scores.
- BF16 precision offers a wider exponent range than FP16 and reduces overflow risk.
- Monitoring per-layer norms helps identify which block starts the divergence.
The idea in brief
A neural network learns by making many small corrections. Each correction is based on a signal that says which way to adjust. Sometimes this signal gets multiplied again and again as it travels through the network. It becomes huge.
Imagine a microphone placed too close to a speaker. A small sound turns into a loud screech. Exploding gradients work the same way. The fix is to limit the signal, start learning gently and design the network so that the signal stays at a sensible level.
A practical scenario
A machine learning team trains a 1.3-billion-parameter language model on a cluster of GPUs. Around step 42,000, the loss jumps from 2.4 to 7.9 and then becomes NaN. The gradient norm log shows a rise from about 0.8 to over 300 within three steps.
The team restores the checkpoint saved at step 41,500, enables global gradient clipping at 1.0, switches from FP16 to BF16 and skips the two data batches that coincided with the spike. They also lower the peak learning rate by about 20 percent.
The run continues past step 42,000 without incident, and the gradient norm stays below 1.5 for the rest of training. The incident costs about half a day of compute instead of the full restart that would have been needed without regular checkpoints.