# 噪声整形（计算）

数值计算中的噪声整形，若按音频意义上的理解，会通过过采样和反馈改变量化误差的频谱分布，使其大多位于信号频谱之外；而这里讨论的技术——随机舍入——则把舍入随机化，使舍入在期望上无偏，也就是说每个舍入结果的期望值等于精确值，而不是像就近舍入那样可能把系统性偏差带入长计算——尽管就近舍入并非总会如此。<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup><sup> • </sup><sup>[22](https://arxiv.org/abs/1502.05807)</sup> 计算文献中处理的技术是随机舍入（SR），它把一个实数随机映射到有限精度数系中两个最近值之一，选择其中任一值的概率等于 1 减去该值与精确值之间的相对距离。<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup> 其效果是，在 \( n \) 次运算中，舍入误差按约 \( \sqrt{n} \cdot u \) 累积，而不是按 \( n \cdot u \) 累积，其中 \( u \) 是单位舍入误差（某一格式最大相对舍入误差的一半）；并且对一个大数值进行的一连串微小更新不再丢失。<sup>[2](https://www.arxiv.org/pdf/2410.10517)</sup> 这个术语与数字信号处理中的噪声整形有重叠；在那里，抖动和 ΔΣ 调制把量化噪声推入危害较小的频带；计算文献大多说随机舍入，并把好处表述为零均值误差，而非频谱整形。<sup>[3](https://eusipco2025.org/wp-content/uploads/pdfs/0002707.pdf)</sup> 硬件支持现已覆盖 Graphcore IPU、[英特尔 Loihi](https://www.edgepedia.org/zh/intel-loihi)、SpiNNaker2、特斯拉 D1、AWS Trainium 和英伟达 Blackwell GPU。<sup>[4](https://ar5iv.labs.arxiv.org/html/2408.03069)</sup>

| 关键事实 | 详情 |
|---|---|
| 舍入规则 | 将 \( x \) 舍入到两个最近可表示值之一，概率与相对距离成正比<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup> |
| 无偏性 | \( \mathrm{E}[\mathrm{sr}(x)] = x \)，因此期望舍入误差为零<sup>[5](https://www.arxiv.org/pdf/2010.16225v1)</sup> |
| 误差增长 | 对 \( n \) 个数求和时，以高概率为 \( \sqrt{n} \cdot u \)，而就近舍入为 \( n \cdot u \)<sup>[2](https://www.arxiv.org/pdf/2410.10517)</sup> |
| 停滞 | 不会像就近舍入那样丢失对一个大数值进行的一连串微小更新<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup> |
| 最坏情况 | 误差界比就近舍入大一个因子 2，因此 SR 并非有益于所有计算<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup> |
| 训练收益 | 在 ImageNet 上，FP8 就近舍入损失 2% 到 4% 的 Top-1 准确率；SR 保持基线<sup>[6](https://proceedings.neurips.cc/paper/2018/file/335d3d1cd7ef05ec77714a215134914c-Paper.pdf)</sup> |
| 硬件 | Graphcore IPU、IBM 加法器、AMD MI300、特斯拉 D1、AWS Trainium、英特尔 Loihi、SpiNNaker2、英伟达 Blackwell<sup>[4](https://ar5iv.labs.arxiv.org/html/2408.03069)</sup> |

## 工作原理

随机舍入用随机抽取取代确定性的就近舍入决策。对于介于可表示值 \( \lfloor x \rfloor \) 与 \( \lceil x \rceil \) 之间的实数 \( x \)，SR-就近模式以概率

\[ p(x) = \frac{x - \lfloor x \rfloor}{\lceil x \rceil - \lfloor x \rfloor} \]

向上舍入，以概率 \( 1 - p(x) \) 向下舍入。<sup>[7](https://ar5iv.labs.arxiv.org/html/2207.03837)</sup> 结果在期望意义下是精确的，\( \mathrm{E}[\mathrm{sr}(x)] = x \)。<sup>[5](https://www.arxiv.org/pdf/2010.16225v1)</sup> 一个算例：将 0.7 舍入到单比特时，以概率 0.7 得到 1，以概率 0.3 得到 0，因此舍入值是精确数的无偏估计量。<sup>[2](https://www.arxiv.org/pdf/2410.10517)</sup>

由于单个误差是零均值且均值独立的，求和的总误差表现得像随机游走，而不是系统性漂移。对于两个长度为 \( n \) 的向量的内积，SR 以高概率给出常数因子为 \( \sqrt{n} \cdot u \) 的误差界，而就近舍入的最坏情况为 \( n \cdot u \)；证明使用伯恩斯坦（Bernstein）、切尔诺夫（Chernoff）和霍夫丁（Hoeffding）等集中不等式。<sup>[2](https://www.arxiv.org/pdf/2410.10517)</sup> 康诺利（Connolly）、海厄姆（Higham）和玛丽（Mary）证明，SR 的舍入误差是零均值的均值独立随机变量，并给出形式为 \( \tilde{\gamma}_n(\lambda) = \lambda \cdot \sqrt{n \cdot u} + O(u^2) \) 的概率后向误差界，该界至少以概率 \( 1 - 2n \cdot \exp(-\lambda^2/2) \) 成立。<sup>[8](https://eprints.maths.manchester.ac.uk/2778/1/paper.pdf)</sup> SR 还不受停滞影响；停滞是指对相对较大的量进行的一连串微小更新丢失。在就近舍入中，任何小于半个 ulp 的参数更新总会被舍入为零，而 SR 会保留该更新存活下来的非零概率。<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup>

## 实现方式

在软件中，SR 既需要随机数，也需要被舍入结果的精确值，这使得高效实现并非易事。<sup>[9](https://eprints.maths.manchester.ac.uk/2758/1/fami20.pdf)</sup> 已有算法仅使用符合 [IEEE 754](https://www.edgepedia.org/zh/ieee-754) 的算术来模拟随机舍入的加法、乘法和除法，无需更高精度计算，并在双精度实验中报告相对于基于 MPFR 的多精度方法超过 5 倍的加速。<sup>[9](https://eprints.maths.manchester.ac.uk/2758/1/fami20.pdf)</sup> 海厄姆和普拉内什（Pranesh）的 MATLAB chop 函数用 SR 模拟低精度算术。<sup>[10](https://nhigham.com/2020/07/07/what-is-stochastic-rounding/)</sup>

第二条实现路线是抖动：临时提升到 FP32，在尾数位上加均匀噪声，并移出小数部分；这样执行 SR 几乎没有吞吐开销。<sup>[11](https://proceedings.mlr.press/v258/ozkara25b.html)</sup> 在硬件中，一个用于深度学习的 SR 现场可编程门阵列（FPGA）实现占用 28 个 DSP 单元，不到硬件资源的 4%。<sup>[12](https://arxiv.org/pdf/1502.02551)</sup>

## 起源

最早的线索是[约翰·冯·诺依曼](https://www.edgepedia.org/zh/john-von-neumann)（John von Neumann）和 H. H. 戈德斯坦（H. H. Goldstine）在《高阶矩阵的数值求逆》中把舍入误差作为随机变量进行概率建模，发表于《美国数学会公报》，1947 年。<sup>[13](https://doi.org/10.1090/s0002-9904-1947-08909-6)</sup> T. E. 赫尔（T. E. Hull）和 J. R. 斯文森（J. R. Swenson）后来在《ACM通讯》1966 年检验了舍入误差传播的概率模型。<sup>[14](https://doi.org/10.1145/365170.365212)</sup> 在信号处理方面，L. 舒克曼（L. Schuchman）1964 年的论文《抖动信号及其对量化噪声的影响》确立了抖动作为一种使量化误差去相关的方法。<sup>[15](https://doi.org/10.1109/tcom.1964.1088973)</sup> 现代分析建立在尼古拉斯·J·海厄姆（Nicholas J. Higham）和西奥·玛丽（Theo Mary）2019 年发表于《SIAM科学计算杂志》的《概率舍入误差分析的新方法》之上，<sup>[16](https://doi.org/10.1137/18m1226312)</sup> 也建立在迈克尔·霍普金斯（Michael Hopkins）、曼塔斯·米凯蒂斯（Mantas Mikaitis）、戴夫·R·莱斯特（Dave R. Lester）和[史蒂夫·弗伯](https://www.edgepedia.org/zh/steve-furber)（Steve Furber）2020 年发表于《皇家学会哲学汇刊A辑》的《求解神经常微分方程的随机舍入与降精度定点算术》之上。<sup>[17](https://doi.org/10.1098/rsta.2019.0052)</sup>

## 变体

可以区分两种 SR 模式。SR-就近模式是上文描述的无偏模式。SR-上下模式以概率 \( p(x)=1/2 \) 独立于 \( x \) 向上或向下舍入；它是有偏的，均值为 \( 1/2 - \theta(x) \)，标准差为 \( 1/\sqrt{12} \)，并且在前向欧拉法中，它会在迭代间累积舍入误差，而 SR-就近模式不会。<sup>[7](https://ar5iv.labs.arxiv.org/html/2207.03837)</sup> 有限精度随机舍入只使用 \( r \) 个随机位；其偏差是 \( r \) 的函数，随 \( r \) 增大而消失；对于递归求和与内积，一个经验法则是 \( r = \lceil (\log_2 n)/2 \rceil \)。<sup>[4](https://ar5iv.labs.arxiv.org/html/2408.03069)</sup> 以零偏差换取更快收敛的有偏变体是 ε偏置随机舍入（SR-ε）和带符号SR-ε；它们为远离零的舍入概率设定下界，以保留小梯度；在 8 位浮点实验中，它们通常比就近舍入和无偏 SR 都收敛得更快。<sup>[18](https://export.arxiv.org/pdf/2202.12276v3.pdf)</sup> 在抖动传统中，三角概率密度函数非减性抖动使均匀量化器的输出在均值意义下线性化，并使误差方差与输入无关。<sup>[3](https://eusipco2025.org/wp-content/uploads/pdfs/0002707.pdf)</sup>

## 应用

**低精度神经网络训练**。古普塔（Gupta）、阿格拉沃尔（Agrawal）、戈帕拉克里希南（Gopalakrishnan）和纳拉亚南（Narayanan）表明，深度网络使用 SR 以 16 位定点训练，在 MNIST 和 CIFAR-10 上准确率几乎不降或完全不降；并且使用 SR 时，网络仅用 8 位就能学习；而低于 8 位时，即使 SR 也无法防止梯度信息损失。<sup>[12](https://arxiv.org/pdf/1502.02551)</sup> 王（Wang）及其同事使用分块累加和 SR 以 8 位浮点训练，在就近舍入于 ImageNet 上损失 2% 到 4% Top-1 准确率的情况下，仍保持 FP32 基线的准确率。<sup>[6](https://proceedings.neurips.cc/paper/2018/file/335d3d1cd7ef05ec77714a215134914c-Paper.pdf)</sup> 对于大语言模型（LLM）预训练，在参数量最高达 67 亿的模型上，带 SR 的 BF16 优于（BF16、FP32）混合精度，吞吐量最高达到原来的 1.54 倍，内存占用降低 30%。<sup>[11](https://proceedings.mlr.press/v258/ozkara25b.html)</sup> 一种近乎无损的 MXFP4 方案将 SR 与随机哈达玛变换结合，以约束块级离群值引起的 SR 方差，并在 MXFP4 中完成超过一半的训练 FLOPs。<sup>[19](https://arxiv.org/html/2502.20586v2)</sup>

**科学计算**同样受益：在气候模拟中，带 SR 的降精度是 binary64 的有效替代方案；对于用有限差分解的热方程，时间步长足够小时，就近舍入解总会停滞，而 SR 误差在一维仅为 \( O(u \cdot \Delta t^{-1/4}) \)，在更高维中基本有界。<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup> SR 还支撑了用于神经常微分方程的降精度定点求解器。<sup>[17](https://doi.org/10.1098/rsta.2019.0052)</sup>

**硬件**实现包括 Graphcore IPU、IBM 浮点加法器、AMD 混合精度加法器、特斯拉 D1、AWS Trainium，以及神经形态的英特尔 Loihi 和 SpiNNaker2 处理器。<sup>[2](https://www.arxiv.org/pdf/2410.10517)</sup> 从 Blackwell 架构开始，英伟达 GPU 支持从 binary32 到 16、8、6 和 4 位值的 SR 降位转换；在英伟达的 NVFP4 方案中，SR 用于无偏梯度估计，而不是用于所有将缩放值转换为 NVFP4 的转换；权重和激活用就近舍入量化。<sup>[20](https://docs.nvidia.com/deeplearning/transformer-engine-releases/release-2.16/user-guide/features/low_precision_training/nvfp4/nvfp4.html)</sup>

## 局限与替代方案

SR 有三项主要代价。第一，最坏情况误差界比就近舍入大一个因子 2，因为可能朝远离最近值的方向舍入，所以 SR 并非有益于所有计算。<sup>[1](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)</sup> 第二，它需要生成随机数，这很可能比确定性舍入更昂贵。<sup>[5](https://www.arxiv.org/pdf/2010.16225v1)</sup> 第三，随机性使结果在不同运行之间不确定，给逐位可复现性带来挑战；建议实践者设置全局随机种子，并且仅在训练中使用 SR，在需要一致输出的推理中坚持使用就近舍入。<sup>[21](https://cloud.google.com/blog/topics/developers-practitioners/why-stochastic-rounding-is-essential-for-modern-generative-ai)</sup> 在可能发生停滞的地方，SR 能得到比就近舍入甚至补偿算法更准确的结果；在其他情形下，更宽尾数的浮点格式和确定性补偿算术仍是替代方案。<sup>[9](https://eprints.maths.manchester.ac.uk/2758/1/fami20.pdf)</sup> 一个实际失败案例是：带 SR 但没有随机[哈达玛变换](https://www.edgepedia.org/zh/hadamard-transform)的 MXFP4 初始收敛比 BF16 慢，似乎是因为小值被随机冲刷为零，损失了梯度信息。<sup>[19](https://arxiv.org/html/2502.20586v2)</sup>

## References

1. [Stochastic rounding: implementation, error analysis and applications (Croci, Fasi, Higham, Mary, Mikaitis, R. Soc. Open Sci. 2022)](https://royalsocietypublishing.org/doi/10.1098/rsos.211631)
2. [Advocating stochastic rounding in complexity analysis (arXiv 2410.10517, 2024)](https://www.arxiv.org/pdf/2410.10517)
3. [Optimised Spectral Density Shaping of Quantisation Error Using Adaptive Dithering (EUSIPCO 2025)](https://eusipco2025.org/wp-content/uploads/pdfs/0002707.pdf)
4. [Probabilistic error analysis of limited-precision stochastic rounding (arXiv 2408.03069, 2024)](https://ar5iv.labs.arxiv.org/html/2408.03069)
5. [Rounding error accumulation in the solution of the heat equation with round-to-nearest and stochastic rounding (Croci et al.)](https://www.arxiv.org/pdf/2010.16225v1)
6. [Training Deep Neural Networks with 8-bit Floating Point Numbers (Wang et al., NeurIPS 2018)](https://proceedings.neurips.cc/paper/2018/file/335d3d1cd7ef05ec77714a215134914c-Paper.pdf)
7. [The Positive Effects of Stochastic Rounding in Numerical Algorithms (El Arar, Sohier, de Oliveira Castro, Petit)](https://ar5iv.labs.arxiv.org/html/2207.03837)
8. [Stochastic Rounding and Its Probabilistic Backward Error Analysis (Connolly, Higham, Mary; SIAM J. Sci. Comput. 43(1), A566-A585, 2021)](https://eprints.maths.manchester.ac.uk/2778/1/paper.pdf)
9. [Algorithms for stochastically rounded elementary arithmetic operations in IEEE 754 floating-point arithmetic (Fasi & Mikaitis)](https://eprints.maths.manchester.ac.uk/2758/1/fami20.pdf)
10. [What Is Stochastic Rounding? – Nick Higham](https://nhigham.com/2020/07/07/what-is-stochastic-rounding/)
11. [Stochastic Rounding for LLM Training: Theory and Practice (Ozkara, Yu, Park, AISTATS 2025; extended arXiv 2502.20566)](https://proceedings.mlr.press/v258/ozkara25b.html)
12. [Training Deep Neural Networks with Low Precision Multiplications (Gupta et al., ICLR 2015)](https://arxiv.org/pdf/1502.02551)
13. [John von Neumann, H. H. Goldstine (1947). Numerical inverting of matrices of high order. Bulletin of the American Mathematical Society.](https://doi.org/10.1090/s0002-9904-1947-08909-6)
14. [T. E. Hull, J. R. Swenson (1966). Tests of probabilistic models for propagation of roundoff errors. Communications of the ACM.](https://doi.org/10.1145/365170.365212)
15. [L. Schuchman (1964). Dither Signals and Their Effect on Quantization Noise. IRE Transactions on Communications Systems.](https://doi.org/10.1109/tcom.1964.1088973)
16. [Nicholas J. Higham, Theo Mary (2019). A New Approach to Probabilistic Rounding Error Analysis. SIAM Journal on Scientific Computing.](https://doi.org/10.1137/18m1226312)
17. [Michael Hopkins and colleagues (2020). Stochastic rounding and reduced-precision fixed-point arithmetic for solving neural ordinary differential equations. Philosophical Transactions of the Royal Society A Mathematical Physical and Engineering Sciences.](https://doi.org/10.1098/rsta.2019.0052)
18. [Stochastic rounding schemes for gradient descent in low precision (SR-epsilon and signed-SR-epsilon)](https://export.arxiv.org/pdf/2202.12276v3.pdf)
19. [Training LLMs with MXFP4 (Tseng et al., 2025; PMLR v258)](https://arxiv.org/html/2502.20586v2)
20. [NVFP4, Transformer Engine 2.16.0 documentation](https://docs.nvidia.com/deeplearning/transformer-engine-releases/release-2.16/user-guide/features/low_precision_training/nvfp4/nvfp4.html)
21. [Why Stochastic Rounding is Essential for Modern Generative AI (Google Cloud Blog)](https://cloud.google.com/blog/topics/developers-practitioners/why-stochastic-rounding-is-essential-for-modern-generative-ai)
22. [Noise-shaping Quantization Methods for Frame-based and Compressive Sampling Systems](https://arxiv.org/abs/1502.05807)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 算法与计算方法 › 数值、字符串与几何算法 › 数值方法与近似

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/noise-shaping-computation

English original: https://www.edgepedia.org/noise-shaping-computation
