pytorch
training_error
ai_generated
true
Loss is nan at step N
ID: pytorch/loss-nan
75%Fix Rate
80%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
Root Cause
Training loss became NaN. LR too high, bad data, or numerical instability.
genericWorkarounds
-
88% success Check data for NaN/Inf values in dataset
-
90% success Use anomaly detection: torch.autograd.set_detect_anomaly(True)
Dead Ends
Common approaches that don't work:
-
Replace NaN with 0 and continue training
85% fail
Model already diverged, garbage weights
-
Remove batch normalization
78% fail
BN is usually stabilizing