A Fix for Softmax and Cross-Entropy

cs.LG Jonathan T. Barron, Dan Gnanapragasam, Michael Tschannen · Oct 22, 2026
Local to this browser
What it does
Standard softmax and cross-entropy hide two floating-point bugs: Softmax Collapse rounds the target gradient to zero once logit margins cross a precision cliff, while Softmax Cancellation produces phantom gradients when a student network...
Why it matters
rewrite both functions in log-space using softplus, expm1, and log1p to recover accurate, zero-sum gradients across bf16, fp32, and fp64. They tie these numerical issues to the Slingshot phenomenon in grokking and derive a clean...
Main concern
The paper presents a technically elegant and well-motivated fix for two real numerical issues. The analysis is careful, the derivations are correct, and the empirical demonstrations are compelling within their scope.
Community signal
0
0 up · 0 down
Sign in to vote with arrows
AI Review AI reviewed
Plain-language introduction

Standard softmax and cross-entropy hide two floating-point bugs: Softmax Collapse rounds the target gradient to zero once logit margins cross a precision cliff, while Softmax Cancellation produces phantom gradients when a student network approaches its teacher. Barron et al. rewrite both functions in log-space using softplus, expm1, and log1p to recover accurate, zero-sum gradients across bf16, fp32, and fp64. They tie these numerical issues to the Slingshot phenomenon in grokking and derive a clean equilibrium for logit margins under AdamW with weight decay.

Critical review
Verdict
Bottom line

The paper presents a technically elegant and well-motivated fix for two real numerical issues. The analysis is careful, the derivations are correct, and the empirical demonstrations are compelling within their scope. However, the experiments are confined to small-scale algorithmic tasks, and the broader practical impact on large-scale training remains largely unsupported. The authors candidly acknowledge this: "Though the extreme margins and near-zero student–teacher gaps probed by our experiments are uncommon in standard large-scale training, our fixed functions are easy drop-in replacements" (Barron et al., Section 8). The prior Slingshot phenomenon characterized by Thilak et al. is accurately cited as involving cyclic phase transitions between norm growth and plateau phases.

“Though the extreme margins and near-zero student–teacher gaps probed by our experiments are uncommon in standard large-scale training, our fixed functions are easy drop-in replacements”
Barron et al. · Section 8
“We denote the observations above as the Slingshot Effect, which is defined to be the full cycle starting from the norm growth phase, and ending in the norm plateau phase.”
What holds up

The decomposition of Slingshot as a direct consequence of Softmax Collapse is convincing. The authors show precisely that once $m > c_d$, standard cross-entropy rounds the target gradient $\tilde{g}_t$ to zero while non-target gradients persist, violating the zero-sum constraint and causing Adam's second moment to decay until a restored gradient triggers a catastrophic step: "Because $\sqrt{\hat{v}_i}$ decayed while those examples were above $c_d$, Adam divides the restored gradients by a very small denominator $\sqrt{\hat{v}_i}+\epsilon$, producing a large parameter step that spikes the training loss" (Barron et al., Section 4). The log-space derivation for soft-target gradients using expm1 and log1p (Section 3, Equation 9) is mathematically sound and avoids subtracting nearly-equal probabilities.

“Because \sqrt{\hat{v}_i} decayed while those examples were above c_d, Adam divides the restored gradients by a very small denominator \sqrt{\hat{v}_i}+\epsilon, producing a large parameter step that spikes the training loss”
Barron et al. · Section 4
Main concerns

The primary concern is narrow experimental scope: every demonstration uses small synthetic grokking benchmarks or tiny distillation setups, with no ImageNet, language-model, or large-scale validation where softmax dominates. The margin equilibrium analysis (Section 5) relies on a stationary-point approximation that does not strictly hold during transient training: "At a stationary point where the parameters stop changing, the moving averages converge to $\hat{m}_i=g_i$ and $\hat{v}_i=g_i^2$" (Barron et al., Section 5). In practice, Adam's biased moving averages deviate from this ideal during Slingshot cycles. Moreover, the soft-target fix requires a custom backward pass with jax.lax.stop_gradient tricks, which adds integration complexity not present in standard framework kernels. The paper also omits any runtime benchmark of the argmax-and-exclude logsumexp versus standard two-pass softmax.

“At a stationary point where the parameters stop changing, the moving averages converge to \hat{m}_i=g_i and \hat{v}_i=g_i^2”
Barron et al. · Section 5
Evidence and comparison

Within the studied grokking regime the evidence strongly supports the core claims: fixed cross-entropy eliminates precision-cliff spikes across all tested precisions, reaches predicted margin equilibria, and outperforms prior remedies. Table 1 shows fixed CE achieving 99–100% test accuracy where standard CE stalls at roughly 94% and fp32 StableMax yields about 97% with margins ballooning to thousands (Barron et al., Table 1). However, comparisons to Zero-sum Projection and StableMax are restricted to modular arithmetic; their broader failure modes are not tested on other task families. The claim that StableMax "remains lower than with our fixed cross-entropy" is only validated on $a+b \bmod 31$, leaving open how the methods compare in realistic high-entropy classification settings where margins rarely approach $c_d$.

“Fixed CE reaches the predicted equilibrium margin (\log(1/\epsilon)\approx 18.4, 27.6, 36.8) and 99–100% test accuracy across all precisions, whereas Standard CE stalls near its precision cliff c_d”
Barron et al. · Table 1
“StableMax ... test accuracy remains lower than with our fixed cross-entropy across all values of \epsilon”
Barron et al. · Section 6
Reproducibility

The paper provides complete inline JAX implementations for all three fixed functions and reports hyperparameters for grokking and distillation, including learning rate, betas, weight decay, and $\epsilon$ values. Random seeds are mentioned but not listed, and no public repository is linked. The modular arithmetic datasets are standard in the grokking literature, yet exact train/validation splits and model initializations are not fully specified. The core gradient identities can be verified immediately from the concrete numerical examples provided: "Standard implementations add 1 and $e^{-m}$ to form the denominator $1+e^{-m}$, which rounds to 1 when $m > c_d$ ... In contrast, our fixed expression $-e^{-m}/(1+e^{-m})$ keeps $e^{-m}$ in the numerator" (Barron et al., Section 2). Reproducing the full training curves, however, would require re-implementing data loaders and initialization protocols absent from the main text.

“Standard implementations add 1 and e^{-m} to form the denominator 1+e^{-m}, which rounds to 1 when m > c_d ... In contrast, our fixed expression -e^{-m}/(1+e^{-m}) keeps e^{-m} in the numerator”
Barron et al. · Section 2
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.

Challenge the Review

Pick a starting point or write your own. Challenges run in the background, so you can keep reading while the AI investigates.

No challenges yet. Disagree with the review? Ask the AI to revisit a specific claim.