# A Fix for Softmax and Cross-Entropy

- **ID:** 1442
- **Kind:** paper
- **URL:** https://arxiv.org/abs/2610.31642
- **Authors:** Jonathan T. Barron, Dan Gnanapragasam, Michael Tschannen (all Google DeepMind)
- **Venue:** arXiv cs.LG preprint v1, submitted 22 Oct 2026 (no venue stated, not peer-reviewed)
- **Published:** 2026
- **Source:** arxiv
- **Language:** en
- **Access:** free
- **Added:** 2026-10-23
- **Verified:** 2026-10-23
- **Page:** https://papers.projxon.ai/entries/1442

## Summary

Shows that the standard softmax + cross-entropy implementation (JAX, PyTorch, TensorFlow — all named) silently computes WRONG gradients in finite precision, via two distinct failures, and fixes both by pure reformulation (no higher-precision casting). BUG 1 — SOFTMAX COLLAPSE (hard targets): implementations shift logits by their max, then form the denominator as 1 + e^(−m) where m is the target logit margin; values added to 1.0 are lost to rounding, so once the margin exceeds the PRECISION CLIFF (c ≈ 5.5 in bf16, 16.6 in fp32, 36.7 in fp64) the denominator rounds to exactly 1.0 — the target logit's loss and gradient round to exactly 0, but the NON-target gradients do not (they never add 1.0, staying accurate down to underflow at m ≈ 88), so the gradient silently loses one entry and no longer sums to zero. BUG 2 — SOFTMAX CANCELLATION (soft targets / distillation / KL): standard soft-target CE softmaxes student and teacher separately and subtracts probabilities; rounding destroys the logit difference δ as z_S → z_T, and the forward/backward operation sequences differ so q ≠ p to machine precision EVEN WHEN z_S = z_T exactly — a nonzero gradient noise floor where the true gradient is 0. THE FIX: for hard targets, exclude the argmax/target from the log-sum-exp, compute the margin, combine via softplus(−m), and let autodiff produce the target gradient as the negated sum of the non-target gradients (Σg = 0 by construction, accurate down to underflow); for soft targets, pass teacher logits into the loss and compute q − p IN LOG SPACE from δ using expm1/log1p with a final Σg = 0 correction — gradient exactly 0 when z_S = z_T (implemented via a custom-gradient stop_gradient trick, ~15 lines). SLINGSHOT EXPLANATION: after memorization, margins grow; once a batch sits entirely above the cliff, parameter gradients nearly vanish, Adam's v̂ decays toward zero while weight decay shrinks the weights — until a few examples drop back below the cliff, their gradients abruptly switch back ON and get divided by the decayed √(v̂)+ε, producing a huge step → loss spike → repeat. This gives the Slingshot phenomenon (Thilak et al. 2022) a complete causal mechanism. MARGIN EQUILIBRIA (§5, standalone result): at an AdamW stationary point |g_i| ≈ ε·λ·|θ_i| and |g| ∝ e^(−m) after memorization, so margins saturate at m*(ε) ≈ log(1/ε) — independent of η, β1, β2 (RMSProp and LaProp share it). Default ε=1e-8 is pathological in fp32: its equilibrium log(1/ε) ≈ 18.4 sits JUST ABOVE the fp32 cliff 16.6, so standard CE hits the cliff right before equilibrium; for ε ≥ 1e-7 the equilibrium (≤16.1) sits below the cliff and training settles without spiking. RESULTS (ALL first-party toy experiments — grokking testbeds, 1-layer width-64 ReLU Transformers and 2-layer MLPs on modular arithmetic, full-batch AdamW; NO LLM-scale experiment anywhere): slingshot setting (a+b mod 31, λ=1, ε=1e-8, 5 seeds) — standard CE repeatedly spikes and degrades grokking, 94 ± 5% vs fixed CE 100 ± 0%; no-weight-decay setting — standard CE tracks fixed CE to 61% accuracy until m hits c₃₂ at ~step 1250, where one spike drops accuracy 61% → 23%; fixed CE continues smoothly to 85%. Precision × ε grid: fixed CE reaches 99–100% in bf16, fp32 AND fp64 at every ε, with final margins matching log(1/ε) predictions; standard CE stalls at its format's cliff (bf16 accuracy ~93–95%, fp32 ~94–97%), and even fp64 breaks at ε=1e-16. Prior-work baselines on the same grid: Zero-sum Projection (Liu et al. 2026) collapses to ~49% at ε ≤ 1e-12; StableMax (Prieto et al. 2025) trails fixed CE at every ε with margins blowing up to 10³–10⁴. Four literature grokking benchmarks: fp32 fixed CE matches fp64 standard CE and reaches 100% on all four. DISTILLATION DRIFT (§7): student initialized EXACTLY at teacher weights should not move; with standard soft-target CE the residual gradient is ~1e-17 in fp64 (student stays), ~1e-8 in fp32 (brief KL spike), and ~1e-3 in bf16 — Adam normalizes it into full-size steps, driving the student AWAY from the teacher and degrading accuracy; fixed CE returns g = 0 exactly at all precisions. Caveats: TOY SCALE ONLY — the authors concede (§8) the extreme margins and near-zero student–teacher gaps probed are uncommon in standard large-scale training; whether LLM training actually sits above the cliff in practice is asserted plausible, not demonstrated (mitigating: most LLM stacks compute the loss in fp32, cliff 16.6; the bf16 cliff at 5.5 is low enough that very confident tokens could plausibly cross it — extrapolation, not a result). The distillation experiment is the degenerate identical-initialization case; real student–teacher gaps are larger, where the cancellation error is proportionally smaller — practical drift magnitude unmeasured. "Bug" is a framing choice: the formulas are correct in exact arithmetic; the failure is evaluation order (though the computed gradient is genuinely wrong — sign flips, deleted entries, Σg ≠ 0 — and prior mitigations existed: fp64 casting, StableMax, zero-sum projection; the contribution is the direct fix + the Slingshot/equilibrium explanation). The equilibrium derivation is idealized (stationary point); the Slingshot is not always harmful on the paper's own account (with pre-LN and no weight decay, spikes act as accidental LR decay); "no meaningful slowdown" is claimed without timing benchmarks. Paper is one day old, no independent replication.

## Research notes

- Discovery: Hudson shared the bare arXiv link 2026-10-23. Relevance: (1) the PRECISION-AS-TRAINING-VARIABLE thread gains its loss-function member — joins #59 (TF-OPD bf16/fp16 scoring gotcha), #66 (Muon polynomials needing float32), #77 (batch invariance), #107 (OPAL's bf16 compensated rounding), and PULSE (held #98): here the gradient itself is silently WRONG in bf16/fp32, not merely noisy, and the fix is reformulation rather than upcasting. (2) Distillation — Softmax Cancellation is exactly the regime of his distillation cluster (#26 Spork, #59 TF-OPD, #84 Glimmer, #111 Carbon-X): student ≈ teacher near convergence, where the standard loss's bf16 noise floor (~1e-3) exceeds the true gradient and Adam amplifies it into drift — a floor on how close a bf16-distilled student can stay to its teacher under a standard soft-target loss. (3) His RLVR/post-training (mechanism-level, untested at scale — flagged): RL produces very high-confidence tokens (memorized formats, boilerplate) = the high-margin regime; a target gradient rounding to zero while non-target gradients persist is a Σg ≠ 0 corruption of the policy gradient; mean logit margin vs the loss dtype's cliff is a CHECKABLE quantity in his own runs. (4) Launch Helm — two loggable diagnostics: margin-vs-cliff tracking for the loss precision ("training past the cliff" warning), and Adam ε reframed as a margin-equilibrium knob (log(1/ε) predicts where post-memorization logit growth saturates). NO attention/kernel relevance — loss-function numerics, orthogonal to his 3:1 SWA backbone; do not map onto the architecture. Near neighbors NOT to merge: Thilak et al. 2022 Slingshot (arXiv 2206.04817), Prieto et al. 2025 StableMax, Liu et al. 2026 "Grokking or Glitching?" (arXiv 2605.06152), #77 (different numerics bug).
- License: paper CC BY 4.0 (verified); code: complete implementations are short INLINE JAX listings in the paper (§2–3) — no repository, no PyTorch version, and NO separate code license stated — flagged (do not assert a code license at insert); no weights (no trained model is a deliverable)

## Similar entries

- [Planning to Learn (The horizon problem: policy gradients are myopic)](https://papers.projxon.ai/entries/1260) (paper, #1260)
- [Towards Looped Models Done Right — Part II: Rethinking at Fixed Points](https://papers.projxon.ai/entries/871) (paper, #871)
- [Why Adaptive Optimizers Underestimate Rare Tokens](https://papers.projxon.ai/entries/1219) (paper, #1219)
- [Adaptive Reward Routing: Dynamic Multi-Reward Optimization for Joint Audio-Video Diffusion via Forward-Process RL](https://papers.projxon.ai/entries/1199) (paper, #1199)
- [Cross-Benchmark Transfer from RL on Agentic Coding Tasks](https://papers.projxon.ai/entries/1245) (paper, #1245)
- [Emergent One-Third Scaling Law as Attention Tries to Concentrate](https://papers.projxon.ai/entries/852) (paper, #852)
