Stochastic rounding is conditionally unbiased only under a precise rule
Derive neighboring-value probabilities and distinguish a locally unbiased rounding operation from independence, reproducibility, and final-model accuracy.
On this page
The question for today
What you’ll understand
- Choose probabilities proportional to distances between adjacent finite representable values.
- Compute the conditional mean and variance of one rounding operation.
- State why local unbiasedness does not imply an unbiased nonlinear training result.
Nearest rounding can repeatedly discard a small update in the same direction. Stochastic rounding instead randomizes between adjacent representable values using probabilities chosen to preserve the exact value in conditional expectation. That is a mathematical property of a specified operation within a specified range. It does not mean fifty-fifty rounding everywhere, independent noise throughout a training run, or an unbiased final loss. The probability mechanism and the conditioning information matter as much as the name of the method.
Derive the probabilities from neighboring values
Let a and b be adjacent finite representable values with a<x<b. Choose b with probability equal to the distance from a to x divided by the gap b−a, and choose a with the remaining probability. Values closer to a therefore round down more often. Multiplying each destination by its probability gives an expected result exactly equal to x. A value already represented should remain unchanged under this rule. A midpoint happens to use equal probabilities, but moving away from the midpoint changes them.
The expectation should be conditional on the current exact operation result and the relevant prior computation history. Otherwise a correlation between random choices and previous errors can invalidate a claimed zero conditional mean. The stated construction assumes the finite neighbors exist and the chosen probabilities are implemented correctly. An overflow case is outside this bounded-neighbor derivation. A flush-to-zero policy, restricted random bit budget, or altered probability generator must be analyzed as the operation actually implemented rather than silently inheriting the ideal rule's guarantee.
Local variance is real even when the mean is right
The rounding error has two possible values, a−x and b−x. Squaring them and weighting by their probabilities gives variance equal to the product of the two distances from x to its neighbors. Thus unbiased does not mean exact on an individual operation or small compared with every application tolerance. Near a neighbor, one outcome is common and the other is rare; across many repeated operations, occasional larger stored moves can preserve the mean contribution that nearest rounding would always discard.
A conditional zero-mean error can support useful martingale-style analyses, but it does not automatically supply independent errors. Nor does it make every nonlinear function of the rounded values unbiased. Squaring a random rounded value adds its variance to the squared mean, for example. In a learning computation, activations, clipping, adaptive optimizer moments, and later parameter-dependent gradients can all change the relationship between local rounding and final output. Distinguish a bound or expectation for a specific numerical quantity from a claim about task accuracy or convergence.
Make reproducibility and experimental claims explicit
A practical implementation needs random bits at a particular operation granularity. Reusing a random word across lanes, changing thread assignment, or selecting a different reduction can alter correlations even when each marginal probability appears plausible. A seed alone does not document those choices. For a controlled comparison, record the stochastic-rounding algorithm, random stream assignment, arithmetic modes, backend version, and accumulator types. Compare repeated seeds and report variability alongside mean behavior, because one favorable run is not evidence of a general improvement.
The sampling lab can display a separate idealized repeated-choice model. Reset, set both p=0.25 and n=100, predict the mean upward-choice fraction 0.25 and variance 0.001875, then Play or Step. Its bars are exact binomial probabilities for independent Bernoulli trials; playback highlights outcomes and does not draw random samples or execute floating-point operations. The displayed normal comparison is an approximation, and its Berry–Esseen number bounds a standardized CDF error rather than each bar. Interpret the model as repeated fixed-probability choices under independence, not as the distribution of an adaptive training trajectory.
Work it through
A quarter-ulp update has a quarter chance to move upward
Consider adjacent binary16 values a=1.5 and b=1.5009765625. An exact intermediate result is x=1.500244140625. Apply ideal stochastic rounding to these finite neighbors and compare with nearest rounding.
The gap is b−a=2⁻¹⁰, while x−a=2⁻¹² is one quarter of that gap. Choose b with probability 1/4 and a with probability 3/4; nearest rounding always chooses a in this non-midpoint case.
The weighted result is 0.75×1.5+0.25×1.5009765625=1.500244140625=x. Nearest rounding instead has the fixed error −2⁻¹² for this repeated exact input.
The conditional variance is (2⁻¹²)(3×2⁻¹²)=3×2⁻²⁴, approximately 0.0000001788139343. Each realized stochastic result is still one of the two neighbors rather than x itself.
The ideal rule preserves this exact intermediate value in expectation while introducing variance. It neither reconstructs a discarded earlier input nor guarantees an unbiased nonlinear downstream loss.
The living notebook
Explore the model
Interactive lab · sampling
Exact repeated-choice probabilities, not a rounding simulator
Reset, set both p=0.25 and n=100, predict mean fraction 0.25 and variance p(1−p)/n=0.001875, then Play or Step. The model uses exact binomial masses for independent fixed-probability choices; playback only highlights outcomes. It does not generate random samples or perform stochastic arithmetic. n is capped at 100. The normal overlay is approximate and the Berry–Esseen bound concerns standardized CDFs, not individual bars.
- Mean sample proportion
- 0.5
- Sample-mean variance
- 0.0125
- Uniform CDF error bound
- ≤ 0.1062
Exact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). 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 forA distribution for independent rounding choices is an explicit model, separate from an adaptive learning computation.
Pause & reason
Check your understanding
Your turn
Try it yourself
A toy finite representation has adjacent values 2 and 2.25, with no other represented value between them. For x=2.1, find the ideal upward probability, conditional mean, and conditional rounding variance. This toy grid is not the binary16 grid near two.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Divide the distance from the lower neighbor by the full gap, then use the product of distances for the variance.
Compare with the solution
The upward probability is (2.1−2)/0.25=0.4, leaving probability 0.6 for 2. The mean is 0.6×2+0.4×2.25=2.1. The conditional variance is 0.1×0.15=0.015 in squared value units. Equal probabilities would instead give mean 2.125 and would not implement the stated unbiased rule for this input.
Keep the idea
Take it with you
- Ideal stochastic rounding uses distance-based probabilities between existing finite neighbors.
- Conditional unbiasedness of one rounded value does not imply independence or an unbiased nonlinear result.
- Evaluate implemented probability quality, range behavior, random stream assignment, and experimental variability.
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.