Cap the size, keep the direction
The gradient of a whole model is one long vector, and its norm is a single number describing how big the step would be.
- : the clipping threshold, a norm rather than a value.
Below the threshold nothing happens. Above it, the whole vector is scaled down so its norm is exactly .
The direction is untouched, which is the point: the step still goes where the gradient said, just not as far.
Why norm clipping rather than value clipping
Clipping each element separately also bounds the step, and it changes the direction of the update, because the elements that were clipped shrink and the others do not.
On a gradient where one parameter dominates, value clipping turns a step along one axis into a step along a completely different one.
Norm clipping rescales everything by the same factor, so the update remains parallel to the true gradient. It is the default for that reason alone.
One step, in order
- Backward, so every parameter has a gradient.
- Compute the total norm across all parameters, as one vector.
- If it exceeds the threshold, multiply every gradient by the ratio.
- Then step the optimiser.
- Log the pre-clip norm, because that number is the diagnostic.
Clipping happens between backward and step. Applied after the optimiser it does nothing, and applied before backward there is nothing to clip.
Choosing the threshold
Train for a few hundred steps without clipping, record the norms, and set the threshold near the top of the normal range rather than at the middle.
A threshold that clips most steps is a learning rate reduction wearing a disguise, and it will slow training without saying so.
One is the conventional value for transformers, and it works because the norms of a well-scaled model sit below it in ordinary steps.
What it does and does not fix
It makes exploding gradients survivable. A single bad batch that would have produced a NaN instead produces a normal-sized step.
It does nothing at all for vanishing gradients, since scaling down a tiny gradient is not something the rule ever triggers.
It is essential in recurrent networks, where the same matrix is applied at every timestep and the norm genuinely can explode by orders of magnitude on one sequence.
A sudden spike in the logged pre-clip norm is worth chasing rather than clipping away. It usually means a corrupt batch, a label error, or a learning rate that is already too high.