Gradient clipping stabilizes training by limiting excessively large gradient values before they produce unreasonable parameter updates. For a threshold z, each gradient value is restricted to the interval [-z, z], while smaller values remain unchanged. It works with SGD, Adam, and learning-rate schedules, and directly addresses exploding gradients. section 5.3.3
Elementwise clipping
With z = 5, g = [1, -2, 1000, 3, -7] becomes clip₅(g) = [1, -2, 5, 3, -5]. In PyTorch, register a hook on every model parameter and clamp each gradient: for p in model.parameters(): p.register_hook(lambda grad: torch.clamp(grad, -5, 5)). This implementation clips values independently rather than rescaling the whole gradient. section 5.3.3
Use clipping when exploding gradients prevent learning, and treat its effect as empirical: it can improve or worsen results when the model is otherwise stable. Recurrent neural networks are a common case for including it because recurrent connections tend to produce exploding gradients. An autoregressive character model uses a tighter [-2, 2] bound. section 5.3.3 section 7.5.1

