One line of insurance
Gradient clipping caps the global norm (or value) of the gradient before the optimizer step. If the unclipped norm exceeds max_norm, scale the gradient down so the norm equals max_norm. The optimizer then sees a bounded update and can't take a wild step.
Standard default: max_norm=1.0 for transformers and RNNs, max_norm=0.5 for very unstable training, no clipping for stable CNN training. The cost is a tiny bit of compute per step — basically free.
Norm clipping vs value clipping
Norm clipping (clip_grad_norm_) — preserve direction, scale magnitude. Almost always what you want.
Value clipping (clip_grad_value_) — cap each coordinate independently. Distorts the gradient direction; rarely what you want unless you're doing something specific (e.g. PPO in RL).
Where to put the call
Between loss.backward() and opt.step(). With mixed precision, between scaler.unscale_(opt) and scaler.step(opt). The order matters because clipping operates on the actual gradient values.