Parallel reduction order can change a valid floating-point answer
Trace nonassociative sums through parallel and distributed execution while separating determinism, accuracy, conditioning, and actual implementation defects.
On this page
The question for today
What you’ll understand
- Compute different rounded sums from the same exactly represented inputs.
- Distinguish reproducibility of an execution path from closeness to a reference result.
- Design a controlled investigation of backend and reduction-order changes.
Parallel execution partitions a reduction into partial sums and combines them in an order chosen by its algorithm and scheduling constraints. Floating-point addition is not generally associative, so changing that tree can change a gradient even when every thread reads the same valid inputs. Distributed collectives introduce additional grouping choices across ranks and chunks. A changed result deserves investigation, but its existence alone does not prove a race or a broken kernel. The first task is to identify which numerical operations actually changed.
Parentheses select rounded intermediate values
Real addition allows parentheses to move freely. A stored floating-point sum inserts rounding at each internal node of its reduction tree. Different trees therefore expose different intermediate magnitudes, cancellation patterns, and tie cases. For a sum with large positive and negative terms, a small term may survive in one grouping and disappear or be displaced by a rounding increment in another. If products are also involved, fused multiply-add and separate multiplication-plus-addition can introduce another distinction because they round at different points.
A reduction's sensitivity depends on the inputs as well as its order. For a nonzero exact sum s, the sum of absolute input values divided by |s| gives a useful summation condition measure. It is one for nonnegative inputs but can become large when cancellation makes the final sum small. A highly sensitive sum may show a substantial relative difference from a tiny absolute perturbation. When s is zero, that relative measure is undefined and an absolute scale must be stated instead of reporting a misleading infinite percentage as an ordinary accuracy result.
Separate a repeatable path from an accurate path
A deterministic execution repeats the same result under its stated platform, software, and input conditions. It may repeat a biased or inaccurate result perfectly. An execution with several permitted orders may return slightly different values that all satisfy a justified error tolerance. These are distinct properties. Neither setting a random seed nor using a higher output dtype automatically fixes a reduction order, the precision of its internal partial sums, or the numerical effects of a backend's algorithm selection.
For distributed learning, changing rank count can change how many terms are summed locally, which chunks cross rank boundaries, and which collective algorithm combines them. Averaging gradients also introduces scaling operations whose placement can affect rounding or overflow. Compare the same mathematical contribution set before attributing a difference only to order: a changed batch partition, loss normalization, skipped nonfinite step, or random augmentation can change the mathematical problem itself. Preserve and replay a small captured set of partial gradients when isolating the communication reduction.
Investigate drift with controlled replays
Start with a minimal reduction fixture and a documented higher-precision or exact reference, then vary one execution choice at a time: input order, tree, accumulator type, fused operation policy, or collective layout. Record absolute errors, a meaningful scale, exceptional values, and repeatability. A mismatch much larger than a justified error envelope remains a reason to investigate indexing, synchronization, data races, and invalid assumptions. Floating-point nonassociativity explains a class of differences; it is not a blanket exemption from checking correctness.
The matrix lab illustrates conditioning separately from parallel reductions. Reset, set both a=1 and b=0, predict condition number 1, then Play. Reset and set both a=1 and b=2 to predict condition number 3+2√2, about 5.828. Readouts describe the selected final matrix A=[[a,b],[0,1]] while playback interpolates its geometry. This invertible two-dimensional family contains neither gradient reductions nor floating-point error injection. Use it to distinguish sensitivity from an implementation's error, then test actual tree-dependent drift on captured numerical data rather than treating the animation as a backend experiment.
Work it through
Two valid binary32 groupings return five and four
Four exactly represented partial-gradient contributions are [16777216, 3, −16777216, 1]. Sum using binary32 nearest rounding after each addition. Compare the listed sequential order with grouping the two large opposite terms and the two small terms separately. Assume no extra compiler reassociation.
The exact real sum is 4. In binary32, spacing just above 16777216=2²⁴ is 2. Adding 3 gives the halfway value 16777219, which rounds to 16777220 under ties to even.
The sequential continuation subtracts 16777216 to give 4 and then adds 1 to give 5. Every final value is finite; the changed result follows from the first rounded intermediate.
Grouping (16777216−16777216)+(3+1) gives 0+4=4 with exact intermediate additions. The sequential absolute error relative to this exact reference is 1, while the regrouped result is exact for this fixture.
Order alone changed the rounded result. The fixture has severe cancellation, so it demonstrates a sensitive reduction rather than a typical error magnitude for arbitrary training workloads.
The living notebook
Explore the model
Interactive lab · matrix
Conditioning and execution error are separate questions
Reset, set both a=1 and b=0, predict condition number 1, then Play. Reset and set both a=1 and b=2 before predicting 3+2√2≈5.828. The model is only A=[[a,b],[0,1]] with positive a, and its numerical readouts always describe the selected final matrix while geometry interpolates. It has no reduction tree, gradient, random perturbation, or backend rounding mode.
- Area scale · det A
- 1.4
- Singular values · σmax, σmin
- 1.597, 0.876
- Condition number · κ₂(A)
- 1.823
The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forFirst identify the problem's sensitivity, then measure the actual implementation's error and repeatability.
Pause & reason
Check your understanding
Your turn
Try it yourself
A controlled replay has reference sum 0, observed rounded sum 0.0002, and diagnostic scale A=0.01. Compute E_abs and E_scaled from this lesson's definition. Explain why the usual relative error divided by |reference| is unavailable.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use A+|reference| in the diagnostic denominator and keep that definition separate from an acceptance rule.
Compare with the solution
E_abs is 0.0002 and E_scaled is 0.0002/0.01=0.02. Division by the magnitude of the zero reference is undefined, so an ordinary relative-error percentage cannot be reported. The scaled value is meaningful only with the stated A and does not itself prove that a tolerance, training metric, or implementation contract was satisfied.
Keep the idea
Take it with you
- Parallel trees choose different rounded intermediates even for identical represented inputs.
- Determinism, conditioning, and accuracy describe different aspects of a numerical result.
- Use captured contributions, checked references, and controlled execution changes to diagnose drift.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.