arXiv(opens in a new tab)cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.01889

Stochastic Rounding in Low-Precision Transformer Inference: A Variable-Precision Emulation Study of a Small GPT-2

Yohan Chatelain, Pablo de Oliveira Castro

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Should low-precision transformer inference use stochastic rounding (SR) or round-to-nearest (RN)? The answer depends on where in the network you look. We isolate this effect by holding the numerical format fixed and varying only the rounding rule at individual operation sites.

To enable experiments at freely chosen precisions, we extend PRISM, a vectorized CPU rounding library, to arbitrary virtual precision via a new variable-precision stochastic rounding (VPSR) algorithm, and prove that the rounding decision is evaluated exactly in hardware floating point.

We develop two analyses that offer complementary insight into the site-level trade-off, without fully modelling end-to-end error propagation. First, a probabilistic forward-error bound for linear projections shows that SR's error envelope grows as O(nu)\mathcal{O}(\sqrt{n}u) in the reduction length nn, against O(nu)\mathcal{O}(nu) for RN, a gap that widens rapidly at low precision and is most pronounced in the long multilayer perceptron (MLP) down-projection. Second, a second-order decomposition of the expected cross-entropy loss change at the output softmax into signed drift, drift curvature, and a variance penalty weighted by the Fisher information matrix reveals why the two sites behave oppositely: MLP noise is predominantly a uniform logit shift, to which the softmax is insensitive, so SR's variance is largely discounted; head noise is genuinely non-uniform across the vocabulary and is not.

These analyses are consistent with the observations. On DistilGPT-2 at t = 6 significant bits, SR in the MLP raises the perplexity to ×1.15\times 1.15 the full-precision reference, compared with ×2.21\times 2.21 for RN. At the language-model head, the ordering reverses: SR's excess loss is driven by its non-uniform variance penalty, whereas deterministic RN carries zero variance penalty. In a mixed-precision configuration (with MLP output at t = 6), assigning SR to the MLP and RN to the head brings perplexity within ×1.10\times 1.10 of the full-precision reference, a 28% reduction over matched-bit RN.

Keywords: stochastic rounding, low-precision arithmetic, transformer inference, floating-point emulation, large language models

1 Introduction

Transformer inference increasingly uses formats narrower than the binary64 arithmetic for which much of classical numerical analysis was developed. The dominant response is

*. Equal contribution.

©2026 Yohan Chatelain and Pablo de Oliveira Castro.

License: CC-BY 4.0, see https://creativecommons.org/licenses/by/4.0/.

quantization: choose a target format, map weights and activations onto it, and recover accuracy through calibration, outlier handling, or per-channel scaling (Dettmers et al., 2022; Xiao et al., 2023; Lin et al., 2024; Gong et al., 2024). In that program, the rounding operator is usually fixed by the underlying hardware format. In post-training quantization, offline weight-rounding methods such as AdaRound (Nagel et al., 2020) optimize the rounding direction of static weights via a local second-order task loss surrogate. However, the rounding rule used for intermediate calculations during inference has received less attention. In contrast, dynamic rounding is already becoming explicit in low-precision training: NVIDIA's microscaled NVFP4 recipe, for example, selectively uses stochastic rounding for gradient casts to reduce quantization bias (Abecassis et al., 2025). Whether this same selectivity is useful during inference remains an open question.

This paper isolates that question by holding the numerical format fixed and varying only the rounding rule. Round-to-nearest (Muller et al., 2018) (RN) returns the closer representable neighbor, whereas stochastic rounding (Forsythe, 1959; Croci et al., 2022) (SR), proposed by Forsythe for controlling accumulated roundoff and pioneered in deep learning by Gupta et al. (2015) to prevent gradient stagnation in low-precision training, selects either neighbor with probability proportional to proximity, making each rounding error zero in expectation. RN errors, by contrast, are deterministic functions of their operands and may align; sufficiently small addends can be absorbed by a large accumulator or repeated operations can drift away from the exact result. SR therefore trades systematic local drift for higher variance.

Whether stochastic rounding improves inference accuracy depends first on the operation. A long reduction is more exposed to accumulated RN drift than a short one. In a GPT-2-style block (Radford et al., 2019), the multilayer perceptron (MLP) down-projection reduces over dff=3072d_{ff} = 3072 terms, while an attention-head score reduces over dhead=64d_{head} = 64. At the same accumulator precision, these operations can therefore have very different exposure to accumulated roundoff.

The outcome also depends on the operation’s location, both because local input distributions affect how errors initially accumulate, and because downstream layers transform the resulting perturbations. A perturbation in an attention score passes through the softmax before changing the weighted value sum, whereas a perturbation from the MLP down-projection enters the residual stream and is transformed by later blocks. The same change of rounding rule can therefore reduce perplexity at one site and increase it at another. This leads to the research question of this paper: when and where does stochastic rounding improve transformer inference accuracy over round-to-nearest at low fixed precision?

We study this question in the GPT-2 architecture, using DistilGPT-2 as a six-block instance, and compare the two rounding rules site by site. Hardware SR is tied to particular formats, operations, and accelerators, so experiments at freely selected precisions require software emulation at every instrumented operation, and the arithmetic intensity of transformer inference requires that emulator to be fast and to vary precision and rounding rule at run time. The contributions of this paper are as follows:

• We present the variable-precision stochastic rounding (VPSR) algorithm (Section 3), prove its correctness, and implement it in PRISM (Chatelain, 2026), where it runs up to 70×70\times faster than Verificarlo's Monte Carlo Arithmetic (MCA) random rounding (Section 4.3).

• We analyze SR in transformer layers (Section 5): we establish a vector Bienaymé–Chebyshev bound that extends prior scalar probabilistic forward-error analysis to the full matrix multiplication of the MLP projection. We also analyze softmax error propagation by deriving an exact decomposition of the cross-entropy loss change into signed target shift (D) and Kullback–Leibler (KL) distortion, and perform a second-order Taylor expansion of the KL term into drift curvature (Q) and variance penalty (V) terms, characterizing the site-level trade-offs between SR and RN.

• We evaluate on DistilGPT-2 and WikiText-2 (Section 6) by lowering t site by site. SR is better in the MLP and RN at the language-model head, and the MLP gap widens as more down-projections are affected. At t = 6 in the MLP, SR holds perplexity degradation to 15% over the full-precision reference against 121% for RN, and comes within 0.3% of the reference by t = 8.

Disclaimer on AI usage. AI tools (specifically Anthropic Claude, Google Gemini, and OpenAI Codex) were used during the preparation of this manuscript to assist with prose drafting, editing, and checking the mathematical proofs. All derivations, empirical evaluations, and final text were independently verified by the authors, who take full responsibility for the contents of this work.

References (37)