A rounding flaw in standard AI training code hurt small models

A Fix for Softmax and Cross-Entropy

TL;DR On a small math puzzle, fixing a rounding flaw in standard training code raised accuracy on unseen cases from about 94% to 100%. All major AI toolkits share this code, though the authors call such extreme cases uncommon in large-scale training.

Words to know

softmax
A step that turns a model’s raw scores for each possible answer into probabilities that add up to one.
gradient
The set of small adjustments that tells a model which way to change its internal numbers while learning.
cross-entropy
A standard measure of how far a model’s probabilities are from the right answers, which training tries to lower.
Adam
A widely used training method that sets the size of each learning step from the recent sizes of past adjustments.
distillation
Training one model to copy the probabilities that another, already trained model gives for each answer.

The problem

An AI model that picks among answers scores each one, and a step called softmax turns the scores into probabilities. Training computes a gradient, a small nudge for each score. The nudges should add up to zero. When the model grows very confident, the standard code adds a tiny number to 1, and rounding erases it. The right answer’s nudge becomes zero, but the wrong answers keep theirs.

The idea

The authors rewrote softmax and cross-entropy, the error score training lowers, to never add the tiny number to 1. The standard code is like weighing a bag of flour with one grain of salt, then subtracting the bag’s weight. The scale shows zero salt. The fix weighs the grain alone, so it shows up. Adam, a common training method, scales each nudge by its recent size. By the authors’ account, a vanished nudge that returns becomes an oversized step. The fix never lets the nudge vanish, so training should stay smooth. Another fix covers distillation, where a student model copies a teacher. There, the standard code leaves a false nudge even when the two match.

What they showed

  1. Back to full marks. On addition where numbers wrap around like hours on a clock, the fixed code scored 100% on unseen cases in every run. The standard code averaged about 94%, slowed by repeated sudden jumps in its error.
  2. One spike erased most progress. Another puzzle ran without the usual controls on the size of the model’s internal numbers. There, a single sudden jump dropped the standard code from 61% to 23% accuracy. The fixed code kept climbing to 85%.
  3. The copy stayed put. The team started a student as an exact copy of its teacher, so it should not change. In the coarsest number format, the standard code pushed the student away and hurt its accuracy. The fix held it in place in every format.

Why it matters

Teams that build AI toolkits should care, along with anyone training very confident models or copying a model into a near-identical one. The authors say their versions can replace the old ones with no meaningful slowdown. Earlier workarounds stored numbers with more digits. The fix does not need that. The paper prints the new code in full. The result shows that rounding in routine AI code can change what a model learns.

The catch

All the evidence comes from small models on toy arithmetic puzzles. The authors note that such extreme confidence, and such close student-teacher matches, are uncommon in large-scale training. So the benefit for chatbot-sized models is unknown. The standard code’s score also varied widely across its few runs. When computers stored numbers with the most digits, the standard code often matched the fix. Other values of a default setting in Adam also narrowed the gap.

Who wrote it

Jonathan T. Barron, Dan Gnanapragasam and Michael Tschannen, all at Google DeepMind, wrote the paper. Barron co-authored “DreamFusion: Text-to-3D using 2D Diffusion” (2022). Tschannen co-authored “Born Again Neural Networks” (2018).