Gradient Clipping & NaN Loss Debugging provides the systematic troubleshooting framework to detect, isolate, and remediate training instabilities, exploding gradients, and numerical divergence in deep neural networks and LLMs; gradient explosion causes parameters to take catastrophic updates into steep non-convex walls, producing arithmetic overflows that cascade into `Loss = NaN`; standard remedies include: 1) Global Norm Gradient Clipping (
g←g⋅∥g∥2max_norm whenever
∥g∥2>max_norm, preserving directional vectors); 2) Dynamic Loss Scaling in mixed-precision FP16 (scaling loss by
S=216 to shift tiny gradients into representable float exponents while discarding NaN steps); 3) Anomaly tracing with PyTorch `detect_anomaly` and backward hooks.