Daily AI Paper

Daily AI Paper

2026-10-25

Archived
2026-10-25

A Fix for Softmax and Cross-Entropy

Jonathan T. Barron, Dan Gnanapragasam, Michael Tschannen

arXiv:2610.31642v1

This paper is about a surprisingly practical but subtle problem: standard softmax, log-softmax, and cross-entropy are not just numerically imperfect in the usual overflow sense, but can produce qualitatively wrong gradients in common training regimes. That matters because these functions sit at the heart of classification, distillation, and many regularized training objectives. If they behave incorrectly at high confidence or when two distributions are nearly identical, then the model can get pushed in the wrong direction even when the math says it should be at or near equilibrium. To see why this is nontrivial, it helps to recall the standard story. Softmax turns logits into probabilities, and cross-entropy compares those probabilities to a target distribution. In exact arithmetic, the gradient of cross-entropy with respect to the logits is simply predicted probabilities minus target probabilities, and those gradients sum to zero. In practice, though, deep learning frameworks stabilize softmax by subtracting the maximum logit before exponentiating. That prevents overflow, but it does not solve everything. This paper identifies two remaining bugs. The first bug is called Softmax Collapse. It happens when the model is extremely confident in the correct class, so the target logit is much larger than all others. In that regime, the non-target exponentials become tiny. The issue is that floating-point numbers have much finer resolution near zero than near one, and standard implementations form the denominator by adding those tiny terms to 1. Once the margin is large enough, the tiny contribution gets rounded away and the denominator becomes exactly 1. That makes the target probability exactly 1, the target loss exactly 0, and the target gradient exactly 0, even though mathematically it should still be a small negative number. Meanwhile, the non-target gradients are still computed as small positive values. So the gradient vector no longer sums to zero. That asymmetry is not just a cosmetic error. When using adaptive optimizers like Adam or AdamW, which normalize updates based on gradient magnitudes, the mismatch can create a feedback loop. The paper connects this directly to the “Slingshot” behavior observed in grokking experiments: training loss sits near zero, then suddenly spikes, then falls again, often alongside jumps in test accuracy. The authors argue that this is a consequence of the collapsed target gradient interacting with the optimizer. The second bug is called Softmax Cancellation. This one shows up in knowledge distillation and KL-style regularization, where a student network is trained to match a teacher network. In the ideal case, if student logits equal teacher logits, the gradient should be exactly zero. But standard code usually computes the student probabilities and teacher probabilities separately, then subtracts them. When the two distributions are very close, that subtraction loses precision. Even worse, the forward path and backward path may use slightly different numerical formulas, so the two sides do not exactly match even when the logits are equal. The result is a spurious non-zero gradient that can keep nudging the student away from the teacher instead of letting it settle. The core idea of the paper is refreshingly direct: fix the implementations of softmax, log-softmax, and cross-entropy themselves, rather than patching around the symptoms with surrogate losses or higher precision everywhere. The authors build formulas that avoid the dangerous subtraction patterns. For the first bug, the key is to avoid adding 1 to a tiny exponential in a way that erases it. Instead of letting the target term vanish inside a denominator, they preserve the small exponential in the numerator and compute the expression so that the target gradient remains accurate all the way down to exponent underflow. In other words, the target entry no longer collapses to zero just because the probability is extremely close to one. For softmax and log-softmax, the paper makes a related change. The largest logit is still shifted to zero, but the implementation computes the log-sum-exp margin without including that zero term as an explicit 1 in the sum. That avoids the precision cliff. The same logic applies to hard-target cross-entropy: because the target slot is replaced by a constant zero rather than by a subtraction that can cancel, automatic differentiation can recover the correct target gradient as the negative sum of the other entries. The authors also provide a JAX implementation that preserves the exact zero-sum gradient structure. For the second bug, the solution is to compute the student-teacher difference directly in log space. Rather than forming two probability vectors and subtracting them, the loss function receives the teacher logits and uses stable primitives like expm1 and log1p to compute q minus p without throwing away the tiny differences. The paper emphasizes that this keeps the gradient accurate as the student approaches the teacher, and makes the gradient exactly zero when the logits are equal. They also explicitly remove any remaining floating-point drift so that the gradient sums to zero as it should. The experimental story in the paper is tied closely to these numerical pathologies. One set of experiments examines the Softmax Collapse phenomenon in settings where a model has already memorized the training data and the target probability is near one. The authors show that standard implementations can zero out the target gradient once the margin crosses the precision cliff, while their fixed implementation continues to produce the small but nonzero gradient expected from the math. This directly addresses the Slingshot behavior seen in grokking with AdamW, where loss spikes recur after memorization. The paper argues that the collapse in the target gradient is the mechanism behind those spikes. They also report that their fix speeds up grokking when weight decay is used, and prevents accuracy collapse when weight decay is absent. The main point here is not that the optimizer or the training setup is fundamentally broken, but that the numerical implementation of the loss was silently changing the effective dynamics once the model got very confident. On the distillation side, the paper shows that standard soft-target cross-entropy can produce gradients that are too large, slightly wrong in sign, or not exactly zero when student and teacher match. Their corrected version matches the exact fp64 gradient much more closely, even when the student logits are only a small fp32 perturbation of the teacher logits. That is important because distillation depends precisely on learning from small differences. If those small differences are numerically distorted, the student can drift instead of converging. The paper also draws an interesting conclusion about what happens after memorization. Once the model has driven the target probability close to one, logit growth does not continue without bound in the presence of weight decay. Instead, the authors observe that growth is bounded by an equilibrium between weight decay and Adam’s epsilon parameter. That is a useful reminder that in modern optimization, tiny numerical constants can shape the long-run behavior of training, especially when gradients become very small. As for limitations, the paper is focused on floating-point behavior in standard deep learning settings, so the fixes matter most when logits become large in magnitude or when two distributions are nearly identical. The paper does not claim that every training instability comes from these bugs. Rather, it isolates a specific and widespread source of error in the loss computations themselves. Another practical point is that the fixes are implementation-level changes, so their benefit depends on using these corrected versions rather than the default library routines. The broader lesson is that numerical stability is not only about avoiding overflow or NaNs. Even when a function returns finite values, the exact way it is computed can change the gradient qualitatively. Here, that difference shows up in two places that are central to modern training: very confident classification and teacher-student matching. The paper’s contribution is to make these operations behave like the mathematics says they should, even in the regimes where floating-point arithmetic is least forgiving.

Previous daily papers

2026-10-29Pushing Dexterity and Safety for In-Hand Object Pose Reaching That Works Remarkably Well2026-10-29Can LLMs Uncover Hidden Physical Laws through Free Exploration?2026-10-29Scaling Laws for Tool-Use Agents via Controllable Environment Synthesis2026-10-28Multi-State Linear Attention with Generalized Second-Order Routing2026-10-28Heads of Security: Learned Attention Gates Improve Prompt Injection Robustness2026-10-27Pretraining Knows What, Simulation Teaches How: Compositional Generalization in a Sim-Trained Robot Agent2026-10-27Retriever-Free Retrieval: Navigating Documents with Decision Models2026-10-27Reva: Real-Time Vulnerability Detection through Contextual Probing of Large Language Models2026-10-26Learning Positive Linear Combinations of ReLUs in Fully Polynomial Time2026-10-25Reliable AI-Assisted Decisions via Selective Auditing2026-10-25Sensorimotor Alignment: A Platonic Proxy for Embodied Policy Success2026-10-22LongZero: Enhancing Long-Context Reasoning in LLMs from Zero Data2026-10-22The End of Consensus Research?2026-10-22Asymmetric On-Policy Distillation Learns In-Context Exploration2026-10-21UniWALM: Unified World Action Language Model for Embodied Robot Control2026-10-21Joints, Camera, Action! Co-Generating 3D Motion and Video for Arbitrary Rigs2026-10-21Evolving Agent Interfaces2026-10-20OpenVLHarness: Real World Visual Agentic Tool-Use with Multimodal Memory2026-10-20Same Simulation, Different Evidence: Where Retrieved Tool Output Costs LLM Agents Accuracy2026-10-20Text-to-Image Generative Modeling Without Language Pretraining2026-10-19DiscoveryRSI: Recursively Learning to Discover Valuable Hypotheses2026-10-19Learning without relearning physical symmetry: an SO(3)-equivariant convolutional network (CNN) on the sphere2026-10-19Self-Building Labs2026-10-18T2-z: Test-Time Optimization of Environment Latents for Robotic World Models2026-10-18FDE-Gym: The Last Mile of AI Delivery2026-10-18MLExpert: Towards a Generalist Agentic Model for Autonomous Machine Learning Engineering2026-10-17Discovering state-of-the-art quantum circuits with large language models2026-10-15Your Transformer Is Secretly Elastic2026-10-15Hierarchical Residual Policy Learning for Real-World Mobile Manipulation with Sparse Human Guidance2026-10-15Latent Compaction with Test-Time Training2026-10-14Tev: Scaling Long-Horizon Agentic Environments with Dense Progress Rewards2026-10-14The Last Remote Sensing Model Built by Humans? Casting Any Earth Observation Task as Recursive Self-Improvement2026-10-14Hybrid Reasoning Agents2026-10-13AI Models Can Provably Hide Arbitrary Capabilities2026-10-13RATED: Reliability-Aware AI Agent Tool Retrieval via Execution Dynamics2026-10-13Designing Protein Structures from Natural Language2026-10-12RSI-Anything: Unlocking Recursive Self-Improvement with World Models2026-10-11A Balanced Data Diet: Addressing the Exploration Bottleneck in Mega-Scale RL for Robot Control2026-10-11FAITH: Feasibility-Aware Safety-Filtered RL for High-Dimensional Systems2026-10-11VioLA: Learning Generalist Humanoid Control Policies from Human Data2026-10-10FastBench: Can Streaming VLMs Perceive High-Dynamic Real-World Streams?2026-10-10Ecology of AI Agents: Collaboration Creates a Population Threshold for Takeoff2026-10-08Long-WAM: Scaling the Context of World-Action Models2026-10-08SciExam for ENSO: Can AI Agents Build Climate Models?2026-10-08RoboJEPA: Scaling Robotic Latent World Models2026-10-08RECAST: Learning to Compute the Right Context through Adaptive Evidence Routing2026-10-07WorldSonus: Bringing Sound to Worlds2026-10-07IdeaAnchor: Teaching LLMs to Turn Literature into Research Ideas2026-10-07Agent in a Bottle: Can LLM Agents Turn Their Capabilities Into Cheap, Scalable Artifacts?2026-10-06CLIFT: Conformal Self-Verification for Web Agent Training and Test-Time Scaling2026-10-06PlotGround: Grounding Plot Digitization in Real Scientific Figures and Their Source Data2026-10-06Base Models Can Reason By Taking a Cue From Training Data2026-10-05LESSER: Post-Training Data Selection with Output-Layer Gradients2026-10-05Language Models that Play Chess and Explain Their Moves2026-10-05Less Decoder is More Encoder: Geometric Representation Learning from Novel View Synthesis2026-10-04One Basis to Animate Them All: Gaussian Blendshape Distillation for Real-Time Avatars2026-10-04The Missing Primitive: Diagnosing and Repairing Mathematical Reasoning in Large Language Models2026-10-04DMAD: Distribution Matching as Adversarial Distillation for Fast Visual Generation2026-10-03VISTA: A Visual Harness for Reasoning in an Interactive World