The simplest cure for exploding gradients: if the gradient’s norm exceeds a threshold, rescale it down to that threshold — g ← g·(τ/||g||) when ||g|| > τ. The direction is preserved exactly; only the runaway magnitude is capped. One line that keeps recurrent and transformer training from detonating on a bad batch.
The demo clips a gradient of norm 100 down to 5 — the direction (3,4) is unchanged: live demo
“Clipping distorts the gradient direction.” — norm-clipping preserves the direction exactly; only per-element clipping (a cruder variant) can bend it. cited
A leash on the magnitude, not the aim. optimizer
On i-13, a gradient (60,80) of norm 100 clips to (3,4) of norm 5, the direction preserved: