Subtle numerical bugs in softmax/cross-entropy may cause mysterious training loss spikes

lmoroney · x · 2026-10-24

Citing Jon Barron's result, lmoroney explains two subtle numerical bugs in standard softmax and cross-entropy implementations (JAX, PyTorch, even textbooks): "Softmax Collapse", where one dominant logit's gradient rounds to zero while others don't so gradients no longer sum to zero; and "Softmax Cancellation", where near-perfect outputs (e.g. a student initialized as the teacher in distillation) still produce non-zero gradients. A simple rewrite fixes both and removes the "slingshot" spikes seen during grokking. He urges learners to understand the math under the APIs and try the fix on a small model.

Related event: Google's Barron Reveals Two Numeric Bugs in All Softmax/Cross-Entropy Implementations(21 posts)→

Original post →

More from Research

Research channel →