torch:clip-grad-norm
(torch:clip-grad-norm params max-norm)
Gradient-norm clipping (PyTorch's torch.nn.utils.clip_grad_norm_) over
params: a module, an optimizer's parameter list, or a plain list of tensors.
Returns the TOTAL L2 norm of every gradient, taken over all of them at once as
if they were one long vector -- the norm as MEASURED, before any clipping, so a
training loop can log it. When that norm exceeds max-norm, every gradient is
scaled IN PLACE by max-norm / (norm + 1e-6), PyTorch's denominator; otherwise
nothing is touched. A parameter no gradient reached is skipped.
Call it between torch:backward and
torch:step: it rewrites the gradients the optimizer is about
to read, and touches no tape.