# Bfloat16

**Bfloat16**（Brain Floating Point，亦写作 BF16）是一种面向机器学习的 16 位浮点数格式，存储一个符号位、八个指数位和七个尾数位。其名称来自 Google Brain，即该格式诞生地谷歌旗下的人工智能研究团队；该格式最初被引入谷歌的张量处理单元（TPU），用以加速深度学习训练与推理。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>

| 关键事实 | 详情 |
|---|---|
| 位布局 | 1 个符号位、8 个指数位、7 个尾数位（连同隐含的前导位共 8 位有效数字）<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup><sup> • </sup><sup>[2](https://www.cambridge.org/core/services/aop-cambridge-core/content/view/287C4D5F6D4A43FBEEB1ABED2A405AAF/S0962492922000101a.pdf/floating-point-arithmetic.pdf)</sup> |
| 动态范围 | 指数范围与 FP32 相同：emax = +127，emin = −126；最大有限值约为 3.39 × 10<sup>38</sup><sup> • </sup><sup>[2](https://www.cambridge.org/core/services/aop-cambridge-core/content/view/287C4D5F6D4A43FBEEB1ABED2A405AAF/S0962492922000101a.pdf/floating-point-arithmetic.pdf)</sup><sup> • </sup><sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC7015289/)</sup> |
| 精度 | 单位舍入误差为 3.91 × 10<sup>−3</sup>，约合 3 位十进制有效数字，而 FP32 为 5.96 × 10<sup>−8</sup><sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC7015289/)</sup> |
| 标准地位 | 并非 IEEE 754 标准格式，但属于 IEEE 754 所定义的一种合法浮点格式（基数为 2，有效数字 8 位，最大指数 127）<sup>[4](https://github.com/riscv/riscv-bfloat16/blob/main/doc/riscv-bfloat16-format.adoc)</sup> |
| 与 FP32 的相互转换 | 极为简单：扩展时在有效数字后补 16 个零位，缩窄时对有效数字截断并舍入，几乎不会发生上溢或下溢<sup>[5](https://bpb-us-e1.wpmucdn.com/wp.nyu.edu/dist/8/24616/files/2024/01/RevisedBookForStudentsJan24.pdf)</sup> |
| 典型硬件用法 | 以 bfloat16 做乘法、以 FP32 做累加，见于 TPU 矩阵单元、NVIDIA Ampere Tensor Core 及 Intel AVX-512_BF16 指令<sup>[6](https://docs.cloud.google.com/tpu/docs/system-architecture-tpu-vm)</sup><sup> • </sup><sup>[7](https://docs.nvidia.com/cuda/archive/11.0_GA/pdf/Ampere_Tuning_Guide.pdf)</sup><sup> • </sup><sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-deep-learning-boost-new-instruction-bfloat16.html)</sup> |
| 训练证据 | 在五个应用领域内，bfloat16 训练在不改动超参数的情况下达到了与 FP32 同等的最优结果<sup>[9](https://arxiv.org/abs/1905.12322)</sup> |

## 格式与编码

Bfloat16 对其 16 个比特的分配方式与 IEEE binary16（FP16）格式不同：FP16 将 5 位分给指数、10 位分给尾数，而 bfloat16 将 8 位分给指数、7 位分给尾数。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>由于指数字段与 FP32 完全一致，凡能容纳于 FP32 的数值，缩窄为 bfloat16 时都不会上溢；下溢、上溢与 NaN 的行为均与 FP32 相同。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>代价在于精度：bfloat16 携带 8 位有效数字，而非 FP16 的 11 位，因此单位舍入误差为 3.91 × 10<sup>−3</sup>，而非 4.88 × 10<sup>−4</sup>。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC7015289/)</sup>

两个方向的转换都很简单。将 bfloat16 值扩展为 FP32 时，在有效数字后补 16 个零；将 FP32 值缩窄时，对有效数字截断并舍入；几乎在所有情况下，两个方向都不会发生上溢或下溢。<sup>[5](https://bpb-us-e1.wpmucdn.com/wp.nyu.edu/dist/8/24616/files/2024/01/RevisedBookForStudentsJan24.pdf)</sup>在 Cloud TPU 上，舍入方案为就近舍入到偶数，上溢产生无穷大，NaN 与无穷大等特殊值均被保留。<sup>[10](https://docs.cloud.google.com/tpu/docs/bfloat16?hl=es-419)</sup>

次正规数的处理因实现而异。Cloud TPU 的 bfloat16 不支持次正规数，因此在转换过程中，凡绝对值小于最小正规数的数值一律被冲刷为零。<sup>[10](https://docs.cloud.google.com/tpu/docs/bfloat16?hl=es-419)</sup>Intel 的 bfloat16 规范同样不支持次正规数。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC7015289/)</sup>

## 为何这一取舍适合深度学习

谷歌的硬件团队之所以选择这一格式，是因为神经网络对指数大小的敏感程度远高于对尾数大小的敏感程度，而更小的尾数可以造就更廉价的乘法器。硬件乘法器的物理尺寸随尾数宽度的平方增长，因此 bfloat16 乘法器的硅片面积约为 FP16 乘法器的一半，为 FP32 乘法器的八分之一。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>

宽指数范围还免除了 FP16 训练所带来的一项负担。FP16 的最大值约为 6.55 × 10<sup>4</sup>，小到足以让梯度发生上溢，通常需要损失缩放等特殊处理；而 bfloat16 拥有与 FP32 相同的范围，在训练和推理中近乎可以直接替代 FP32。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup><sup> • </sup><sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC7015289/)</sup>以 bfloat16 存储数值还可将内存占用相比 FP32 减半，在 TPU 上这意味着模型可以更深、更宽或使用更大的批大小，并减少受内存带宽制约的运算中的数据搬运。<sup>[10](https://docs.cloud.google.com/tpu/docs/bfloat16?hl=es-419)</sup>

## 硬件采用

**TPU。** Cloud TPU v2 与 v3 在矩阵乘法单元（MXU）中使用 bfloat16，该单元是一个 128 × 128 的乘加脉动阵列（处理器网格在相邻单元间有节奏地传递数据）；每个 MXU 每周期执行 16K 次乘加运算，所有乘法均以 bfloat16 为输入，所有累加均以 FP32 进行。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup><sup> • </sup><sup>[6](https://docs.cloud.google.com/tpu/docs/system-architecture-tpu-vm)</sup>一片 TPU v3 芯片的标称峰值算力为 123 万亿次浮点运算每秒（bf16），一个由 1024 片芯片组成的完整 v3 Pod 则为 126 千万亿次浮点运算每秒（bf16）。<sup>[11](https://docs.cloud.google.com/tpu/docs/v3)</sup>XLA 编译器会自动插入 float32 到 bfloat16 的转换，因此开发者可以用 FP32 编写模型，无需手动转换或损失缩放即可获得性能收益。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>

**CPU 与 GPU。** 第三代 Intel Xeon 可扩展处理器新增了 AVX-512_BF16 扩展，作为 Intel DL Boost 的一部分，其中包括 VDPBF16PS 指令——它计算 BF16 数对的点积并累加到单精度中——以及将打包的 FP32 数据转换为打包 BF16 的转换指令。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-deep-learning-boost-new-instruction-bfloat16.html)</sup>NVIDIA 的 Ampere 架构通过 HMMA 指令加入了对 Bfloat16 Tensor Core 的支持；在 Ampere 上，BFloat16 矩阵指令仅支持以 FP32 作为累加格式。<sup>[7](https://docs.nvidia.com/cuda/archive/11.0_GA/pdf/Ampere_Tuning_Guide.pdf)</sup>RISC-V 已批准 BF16 扩展，该格式在 Armv8-A 架构上也得到支持。<sup>[4](https://github.com/riscv/riscv-bfloat16/blob/main/doc/riscv-bfloat16-format.adoc)</sup><sup> • </sup><sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC7015289/)</sup>

## 训练精度证据

2019 年，Intel 的 Dhiraj Kalamkar 及其同事发表了一项研究，首次对 bfloat16 用于深度学习训练进行了全面的实证研究，涵盖图像分类、语音识别、语言建模、生成网络和工业推荐系统。其结果表明，使用 bfloat16 张量训练在相同迭代次数下、且不改动超参数的情况下，取得了与 FP32 张量相同的最优结果；正是保持了 FP32 的范围，才避免了 FP16 所需的超参数调优。在其混合精度方案中，GEMM 等计算内核以 bfloat16 为输入，而累加和主权重则保持为 FP32。<sup>[9](https://arxiv.org/abs/1905.12322)</sup>

纯 16 位训练——即不对权重更新做 FP32 累加——则更为困难。对小幅权重更新做就近舍入可能将其完全抵消，从而损害收敛。与康奈尔大学相关的研究者 Pedram Zamirai、Jian Zhang、Christopher R. Aberger 和 Christopher De Sa 研究了在 bfloat16 上使用 16 位浮点单元进行训练的问题，并证明两种数值分析技术——随机舍入与 Kahan 求和——最多可挽回 7 个百分点的验证精度，在七项深度学习应用中，其验证精度介于比 32 位训练低 0.1 个百分点至高 0.2 个百分点之间。<sup>[12](https://arxiv.org/abs/2010.06192)</sup>

谷歌报告称，将其 Cloud TPU 参考模型中的大多数针对 bfloat16 混合精度训练进行优化后，性能提升幅度从 4% 到 47% 不等，几何平均为 13.9%。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>

## 实际使用

在 TPU 上，默认路径无需改动代码：矩阵乘法自动以 bfloat16 运行，累加自动以 FP32 进行。<sup>[10](https://docs.cloud.google.com/tpu/docs/bfloat16?hl=es-419)</sup>若需显式使用，谷歌的建议是将权重和梯度保持为 FP32，而将激活值转换为 bfloat16，因为以 bfloat16 表示激活值通常是安全的；同时偶尔运行一次 FP32 基线，以确认模型行为相当。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>由于在 TPU 上参数和激活值可以以完整的 32 位格式存储，在那里训练出的模型检查点无需大量手动转换即可部署到 CPU 或 GPU 上。<sup>[1](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup>

该格式也已走出机器学习领域。在针对离散化非线性扩散问题的混合精度方法中，以 bfloat16 作为低精度，在时间步趋于零时仍能保持一阶或二阶精度，而朴素的混合精度实现则做不到。<sup>[13](https://link.springer.com/article/10.1007/s11227-026-08264-4)</sup>在稀疏线性求解器中，与锥形精度的 posit 和 takum 格式的比较发现，这些替代格式在直接求解器中比 bfloat16 更为精确，而 bfloat16 的低精度则成为该用途的一个限制因素。<sup>[14](https://arxiv.org/abs/2412.20268)</sup>

## References

1. [Shibo Wang and Pankaj Kanwar (2019). BFloat16: The secret to high performance on Cloud TPUs. Google Cloud Blog.](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)
2. [Nicholas J. Higham (2022). Floating-point arithmetic (Acta Numerica), Table 2.1. Cambridge University Press.](https://www.cambridge.org/core/services/aop-cambridge-core/content/view/287C4D5F6D4A43FBEEB1ABED2A405AAF/S0962492922000101a.pdf/floating-point-arithmetic.pdf)
3. [Nicholas J. Higham and Theo Mary (2019). Numerical algorithms for high-performance computational science. PMC.](https://pmc.ncbi.nlm.nih.gov/articles/PMC7015289/)
4. [RISC-V bfloat16 format specification. GitHub, riscv/riscv-bfloat16.](https://github.com/riscv/riscv-bfloat16/blob/main/doc/riscv-bfloat16-format.adoc)
5. [Numerical computing with IEEE arithmetic (course text, New York University, 2024).](https://bpb-us-e1.wpmucdn.com/wp.nyu.edu/dist/8/24616/files/2024/01/RevisedBookForStudentsJan24.pdf)
6. [TPU architecture. Google Cloud Documentation.](https://docs.cloud.google.com/tpu/docs/system-architecture-tpu-vm)
7. [Tuning CUDA Applications for Ampere, NVIDIA CUDA Toolkit 11.0 documentation.](https://docs.nvidia.com/cuda/archive/11.0_GA/pdf/Ampere_Tuning_Guide.pdf)
8. [Intel Deep Learning Boost: new deep learning instruction bfloat16. Intel Developer Zone.](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-deep-learning-boost-new-instruction-bfloat16.html)
9. [Dhiraj Kalamkar et al. (2019). A Study of BFLOAT16 for Deep Learning Training. arXiv:1905.12322.](https://arxiv.org/abs/1905.12322)
10. [Mejora el rendimiento de tu modelo con bfloat16. Cloud TPU, Google Cloud Documentation.](https://docs.cloud.google.com/tpu/docs/bfloat16?hl=es-419)
11. [TPU v3. Google Cloud Documentation.](https://docs.cloud.google.com/tpu/docs/v3)
12. [Pedram Zamirai, Jian Zhang, Christopher R. Aberger, Christopher De Sa (2020). Revisiting BFloat16 Training. arXiv:2010.06192.](https://arxiv.org/abs/2010.06192)
13. [Mixed-precision numerics in scientific applications: survey and perspectives. The Journal of Supercomputing.](https://link.springer.com/article/10.1007/s11227-026-08264-4)
14. [Laslo Hunhold and James Quinlan (2024). Evaluation of Bfloat16, Posit, and Takum Arithmetics in Sparse Linear Solvers. arXiv:2412.20268.](https://arxiv.org/abs/2412.20268)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Arithmetic and number systems › Computational arithmetic › Floating-point and mixed-precision arithmetic

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/bfloat16

English original: https://www.edgepedia.org/bfloat16
