pytorch
training_error
ai_generated
true
RuntimeError: Loss is NaN or Inf
ID: pytorch/gradient-explosion
75%Fix Rate
80%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
Root Cause
Gradient explosion causing NaN loss.
genericWorkarounds
-
90% success Use gradient clipping: torch.nn.utils.clip_grad_norm_(model.parameters(),1.0)
-
88% success Reduce learning rate and use learning rate warmup
Dead Ends
Common approaches that don't work:
-
Set learning rate to near zero
72% fail
Training never converges
-
Ignore NaN batches and continue
82% fail
Model weights already corrupted