TL;DR
Training takes a step in the direction of the gradient, and occasionally that gradient is enormous. One huge step can throw the weights far away from anything useful, and the loss jumps. Gradient norm clipping fixes this by measuring the length of the whole gradient vector and, if it is longer than a threshold, shrinking it to exactly that threshold. The direction stays the same. Only the size changes.
Where you'll see it: in the training loop of almost every recurrent network and large language model, where the default setting is a maximum gradient norm of 1.0 or 5.0.
Intuition
A steering wheel that turns too far
Gradient descent is driving downhill and steering by the slope under the wheel. Usually the slope is gentle and the car moves sensibly. Occasionally the slope becomes a cliff, and the car lurches off the road. The obvious fix is to limit how far the car can move in one go, and keep it pointed the same way.
Clipping does exactly this. It does not change where the car is heading, only how far it is allowed to go in that direction this step.
Why the gradient explodes
Recall the backward pass. The gradient for an early weight is a product of many local factors, one per layer or per time step. In a recurrent network the same weight matrix is applied at every step, so the product is repeated again and again. If the typical factor is a little above 1, the product grows geometrically. Ten steps at a factor of 2 give times the original signal.
The opposite problem is the vanishing gradient, where factors below 1 shrink the signal to nothing. Clipping is a tool for the first problem only. It does not help when the gradient is already too small.
flowchart LR
G[Compute gradient g] --> N{Length of g above threshold c?}
N -->|no| U[Use g unchanged]
N -->|yes| S[Rescale g so its length is c]
U --> W[Update weights]
S --> W
The math
Setting up the gradient as a vector
Let be all the trainable weights of a model, stacked into one long vector. The gradient of the loss with respect to them, , is a vector of the same length. Each entry says how the loss would change if one weight moved a little. Gradient descent updates the weights by
where is the learning rate.
The size of is measured with the Euclidean norm over all weights together, the global norm:
The clipping rule
Choose a threshold . Then clip the gradient:
When the norm is above the threshold, the gradient is multiplied by . This scalar is less than 1, so every entry shrinks by the same factor. The new vector has length exactly :
Because every entry is scaled by the same number, points in exactly the direction of . That is the key difference from clipping each entry separately, which changes the direction.
- scale factor, c = 5
Global norm versus per-parameter clipping
There is a design choice. Clipping by the global norm over all weights, as above, keeps the relative sizes between layers. Clipping each parameter tensor separately makes every layer's gradient have its own cap, which changes the direction of the full gradient. Most libraries default to the global norm, because it is the version that matches the geometric description.
Worked examples
Take a gradient with two weights, before clipping, and threshold .
- Compute the norm: .
- Compare with the threshold: , so clipping applies.
- Compute the scale: .
- Multiply: .
- Check the new length: , so .
The direction is unchanged: and both point along the line with slope . Only the size has been cut from 5 to 1.
Suppose a recurrent network produces a gradient of on one batch, because a factor of about 2 has been multiplied in over ten time steps. Use threshold .
- Norm: .
- Scale: .
- Clipped gradient: .
- Check: .
Without clipping, the update with learning rate would move the weights by , a jump of length 10. With clipping it moves by , a step of length 0.05 that still heads in the same direction as the true gradient.
Take with threshold .
- Norm: .
- Compare: , so no clipping happens.
- Result: .
Clipping only acts above the threshold. On ordinary batches, training behaves exactly as it would without clipping, which is why the method is almost free to leave on.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Occasional huge gradients in a recurrent network | Sudden jumps wreck training | Clip the global norm |
| Gradients that are always small | Clipping never activates and does nothing | Look at the vanishing-gradient fix instead: better initialisation, gated units, or residual connections |
| Threshold set too low | Clipping fires on most steps, so training is slowed by a permanently shrunk learning rate | Log the norm and pick a threshold above its typical value |
| Threshold set too high | Clipping rarely fires, so it does not help | Choose a threshold near the 90th to 99th percentile of observed norms |
| Mixed-precision training | A norm can overflow to infinity before clipping sees it | Scale the loss first, and check for non-finite gradients |
The failure that is easiest to miss is a threshold that is too low. The training run looks stable, but it learns slowly because every large but correct gradient is silently shortened. Always log the gradient norm before and after clipping, so the choice is visible.
History
Exploding and vanishing gradients in recurrent networks were analysed in the early 1990s, including by Yoshua Bengio and colleagues, who studied why such networks struggle to learn long-range dependencies. Clipping gradients was used as a practical fix in recurrent language models in the early 2010s. Razvan Pascanu, Tomas Mikolov and Yoshua Bengio analysed the problem geometrically in their 2013 paper and argued for rescaling the whole gradient to a fixed norm, which preserves the direction of the update. Norm clipping has since become a standard option in deep learning libraries and is still common when training large language models.
Check yourself
QuestionA gradient has norm 8 and the threshold is . What is the scale factor applied to it?Show answer
Clipping applies because . The scale factor is . Every entry of the gradient is multiplied by 0.25, and the new norm is 2.
QuestionWhy does clipping by the global norm keep the direction of the gradient, but clipping each entry to the range does not?Show answer
Global-norm clipping multiplies every entry by the same scalar, so the vector is only stretched or shrunk and points the same way. Per-entry clipping caps each entry separately. A large entry is cut while a small entry is left alone, which changes the ratio between entries and so changes the direction.
QuestionA gradient is and the threshold is . Is clipping applied, and what is the result?Show answer
The norm is . The condition is , since , so no clipping is applied and the gradient stays . This is the boundary case: clipping only starts above the threshold.
QuestionWhy is exploding gradient clipping a poor fix for vanishing gradients?Show answer
Clipping only reduces large gradients. When the gradient is already small, its norm is below the threshold, so clipping does nothing. Vanishing gradients need a different fix, such as careful initialisation, gating, or residual connections that give the signal a shorter path.
QuestionA model trains stably but is slower than expected, and logging shows the clip is active on 80 percent of steps. What is the likely cause and what would you change?Show answer
The threshold is probably too low, so most normal gradients are shortened and the effective learning rate is much smaller than intended. Raise the threshold to a value near the high percentiles of the observed gradient norms, so clipping only fires on genuine spikes.