Why Exact by Hand Stops
Observe 32-bit floating-point swamping when small gradient or loss increments are added one by one onto a large accumulator.
The problem
Paper algebra assumes real-number associativity: . Hardware accelerators do not store infinite-precision reals; standard 32-bit floating point (float32) allocates sign bit, exponent bits, and fraction bits ( bits of significand precision).
Once a running loss sum or parameter accumulator reaches , consecutive representable float32 values are spaced apart. What happens when we add eight small increments of onto in float32 on [8388608, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25]? On paper, and the total is , yet naive left-to-right float32 addition loses the entire update.
Work through the numbers
Trace the naive sequential loop in float32 starting at total . Step 1 forms the exact sum . Because adjacent float32 numbers in are and (gap ), sits one-quarter of a step above and rounds back down to .
Steps 2 through 8 repeat the identical trap: each arrives alone, rounds back to , and vanishes. After all eight updates, naive sequential float32 reports [8388608, 0], losing 100 percent of the change.
Now regroup the sum in float32 without changing precision: reduce the eight small increments first. Adding eight copies of produces gain with zero rounding error, and adding lands on the representable integer , recovering [8388610, 2].
The live model
The demo runs both float32 orders against exact update (blue) and prints [naive_gain, grouped_gain], coloring preserved bars green and swamped bars crimson. At default base_scale (base 8,388,608, gap ), it prints [0, 2]. At 0.25 (base 2,097,152, gap ), both survive: [2, 2]. At 2.0 (base 16,777,216, gap ), naive vanishes while grouped survives: [0, 2]. At 4.0 (base 33,554,432, gap ), grouped ties halfway to even 33,554,432 and rounds down: [0, 0].

let base_scale = scene.parameter("base_scale", 1.0, 0.25, 4.0, 0.25);
let f = input.to(DType.F32);
let base = f.slice(0, 0, 1) * torch.full(1, base_scale).to(DType.F32);
let seq = base;
for (i in range(1, f.size(0))) {
seq = seq + f.slice(0, i, i + 1);
}
let naive_gain = seq - base;
let grp = base + f.slice(0, 1, f.size(0)).sum().reshape(1);
let grouped_gain = grp - base;
let answer = torch.cat(torch.list().add(naive_gain).add(grouped_gain), 0);
out.set("naive_and_grouped_gain", answer);
{
"naive_and_grouped_gain": [
0,
2
]
}Watch the parameter change
Your turn
The starter program returns [8388608, 0] on the default fixture because each 0.25 increment is absorbed before the rest arrive. Set answer to the float32 result [total, total - base] obtained when the small increments are grouped in float32 before adding base in float32; Check tests both cases where grouping recovers [8388610, 2] and larger bases where float32 still rounds differently from float64.

let f = input.to(DType.F32);
let base = f.slice(0, 0, 1);
let total = base;
for (i in range(1, f.size(0))) {
total = total + f.slice(0, i, i + 1);
}
let recovered = total - base;
let answer = torch.cat(torch.list().add(total).add(recovered), 0);
out.set("total_and_gain", answer);
{
"total_and_gain": [
8388608,
0
]
}Compute the float32 result [total, total - base] obtained when the small increments in input[1..] are grouped in float32 before adding input[0] in float32.
Read the result carefully
Two practical rules of large-scale training come directly from this nine-number experiment. First, parallel tensor reductions sum trees of similar-sized values before combining large partial sums, which dramatically reduces swamping compared with a long sequential loop.
Second, when base reaches (gap ) — or equivalently when a float16 weight of magnitude (gap ) receives tiny learning-rate updates of — regrouping updates within one step is no longer enough. That is why mixed-precision training stores a float32 master copy of weights even when matrix multiplications run in 16-bit formats.
Recap
- Floating-point addition is not associative: can round away updates that preserves.
- At ,
float32spacing reaches , swamping individual increments added sequentially (0) while preserving their grouped sum (2). - Tree reductions and higher-precision master accumulators prevent millions of small gradient steps from rounding to zero.