A Fix for Softmax and Cross-Entropy
Jonathan T. Barron, Dan Gnanapragasam, Michael Tschannen
Key points
From the paper's conclusion- We present simple implementations of log-softmax, softmax, and cross-entropy that fix both bugs.
Abstract
Standard implementations of softmax, log-softmax, and cross-entropy have two numerical bugs. The first bug, Softmax Collapse, rounds the target logit's gradient to zero if that one logit is much larger than the others, resulting in gradients that no longer sum to zero. The second bug, Softmax Cancellation, occurs when student logits are close to teacher logits, and produces non-zero gradients even when the student and teacher logits are equal. We present simple implementations of log-softmax, softmax, and cross-entropy that fix both bugs. Our fix eliminates the previously-observed "Slingshot" phenomenon, speeds up grokking with weight decay, prevents accuracy collapse without weight decay, stops student networks from drifting away from the teacher during distillation, and shows that after memorization, logit growth is bounded by an equilibrium between weight decay and Adam's $\epsilon$ hyperparameter.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Property-Based Testing for Robust Softmax and Cross-EntropyarXiv · 2026
- On numerical issues of divergences between nearly equal distributionsarXiv · 2026
- The KL Divergence Is Never Negative, Except in PyTorcharXiv · 2026
- Distillation with Errors: Sparse Unbiased Backpropagation for Knowledge DistillationarXiv · 2026
- Broken Symmetry in BF16 Attention: Why FlashAttention Gradients Blow Up Late in TrainingarXiv · 2026
- Continuum AttentionarXiv · 2026