pub fn clip_grad_norm(
vars: &[(String, Var)],
grads: &mut GradStore,
max_norm: f64,
) -> Result<f64, CodecError>Expand description
Computes the global L2 norm across vars’ gradients and rescales grads in place when above max_norm.
Matches PyTorch’s torch.nn.utils.clip_grad_norm_ (norm_type=2.0, eps=1e-6).
§Errors
Returns CodecError::Candle if gradient reduction or scaling fails.