# 半精度浮点格式

半精度浮点格式，又称FP16或binary16，是IEEE 754标准中定义的一种16位二进制浮点编码，由1个符号位、5个指数位和10个存储尾数位组成。它以比32位单精度浮点少一半的内存来存储数字，代价是范围窄得多、精度粗得多；它广泛用于图形学、高动态范围成像和机器学习。<sup>[1](https://developer.nvidia.com/blog/new-features-cuda-7-5/)</sup>

| 关键事实 | 详情 |
|---|---|
| 位布局 | 1个符号位、5个指数位、10个尾数位（含隐含前导位共11位有效精度）；指数偏置为15<sup>[1](https://developer.nvidia.com/blog/new-features-cuda-7-5/)</sup><sup> • </sup><sup>[2](https://openexr.com/en/latest/OpenEXRFileLayout.html)</sup> |
| 最大有限值 | 65504，等于 \( 2^{15} \times (2 - 2^{-10}) \)<sup>[3](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> |
| 最小值 | 最小正规格化数 \( 2^{-14} \approx 6.1 \times 10^{-5} \)；最小正非规格化数 \( 2^{-24} \approx 5.96 \times 10^{-8} \)<sup>[3](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> |
| 机器精度 | \( 2^{-10} \)，约 \( 9.8 \times 10^{-4} \)<sup>[3](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> |
| 标准化 | 原版IEEE 754中未定义；2008年修订版作为binary16加入，并在IEEE 754-2019中保留<sup>[4](https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-26-openexr-image-file-format)</sup><sup> • </sup><sup>[5](https://epubs.siam.org/doi/10.1137/19M1251308)</sup> |
| 实践起源 | 1997年由Silicon Graphics开发；后由工业光魔用于OpenEXR文件格式，于2003年公开发布，与NVIDIA已有的16位GPU格式相吻合<sup>[4](https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-26-openexr-image-file-format)</sup><sup> • </sup><sup>[24](https://lweb.cfa.harvard.edu/sma/miriad/swarm/news/Half-precisionFloating-pointFormat.html)</sup> |
| 现代主要用途 | 深度神经网络的存储与算术运算，通常用于以32位累加的混合精度训练<sup>[6](https://arxiv.org/abs/1710.03740)</sup> |

## 格式与可表示的值

与其他IEEE 754二进制格式一样，半精度值编码一个符号、一个带偏置的指数和一个小数尾数。指数偏置15使规格化范围从 \( 2^{-14} \) 到略低于 \( 2^{16} \)；最大和最小的指数编码保留给零、非规格化数、无穷大和NaN。<sup>[2](https://openexr.com/en/latest/OpenEXRFileLayout.html)</sup><sup> • </sup><sup>[4](https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-26-openexr-image-file-format)</sup> 最大有限值为65504，最小正非规格化数为 \( 2^{-24} \approx 5.96 \times 10^{-8} \)，因此该格式在1以上覆盖约五个半数量级，在1以下覆盖约七个数量级。<sup>[3](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup>

精度是该格式的主要局限。在其指数范围内，FP16对 \( 2^{-14} \) 到 \( 2^{15} \) 之间的每个2的幂可表示1024个值，总共约30720个值；32位单精度在宽广得多的范围内对每个2的幂可表示约800万个值。<sup>[7](https://developer.nvidia.com/blog/mixed-precision-programming-cuda-8/)</sup> 从单精度转换为半精度会将尾数舍入到10位，丢弃最低的13位；而从半精度转换为单精度是无损的，因为每个半精度值都能精确表示为单精度浮点数。<sup>[8](https://download.nvidia.com/developer/GPU_Gems/CD_Image/Image_Processing/OpenEXR/OpenEXR-1.0.6/doc/)</sup>

## 在高动态范围成像中的起源

这种16位格式是通过电影制作而非标准制定进入实际应用的。由于当时的IEEE 754规范没有定义16位格式，工业光魔为其OpenEXR高动态范围图像文件格式创建了`half`类型，于2003年初发布，并设计成与NVIDIA已有的16位GPU格式相匹配。<sup>[4](https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-26-openexr-image-file-format)</sup> 该格式仿照IEEE单精度和双精度，将最小和最大的指数值保留给特殊值。<sup>[4](https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-26-openexr-image-file-format)</sup>

就图像存储而言，该格式的特性与任务高度契合。OpenEXR存储线性光值，16位浮点数提供30档动态范围而不损失精度，在低端还可额外提供10档精度较低的动态范围，每档有1024个颜色阶跃，而大多数8位格式每档只有约20到70个阶跃。<sup>[9](https://openexr.com/en/latest/concepts.html)</sup> OpenEXR文档称由此得到的动态范围达到万亿比一，远远超出大多数图像采集设备所能产生的范围。<sup>[4](https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-26-openexr-image-file-format)</sup> half类型还直接迁移到了硬件：该格式与NVIDIA Cg图形语言中的half数据类型兼容，并在当时的GeForce FX和Quadro FX GPU上获得原生支持。<sup>[10](https://github.com/syoyo/openexr-aarch64)</sup><sup> • </sup><sup>[11](https://download.nvidia.com/developer/GPU_Programming_Guide/GPU_Programming_Guide.pdf)</sup>

## 硬件与软件支持

NVIDIA GPU在FP16成为通用计算类型之前多年就将其作为存储格式支持，主要用于纹理存储和过滤。<sup>[7](https://developer.nvidia.com/blog/mixed-precision-programming-cuda-8/)</sup> CUDA生态中的支持时间线如下：

- GeForce FX、GeForce 6系列和GeForce 7系列GPU支持16位浮点，在精度要求允许的情况下，half类型比32位浮点性能更高。<sup>[11](https://download.nvidia.com/developer/GPU_Programming_Guide/GPU_Programming_Guide.pdf)</sup>
- CUDA 7.5（2015年）在`cuda_fp16.h`头文件中加入了`half`和`half2`数据类型及内建函数，使应用能在GPU内存中存储最多两倍大的模型，并在内存带宽成为瓶颈时获得最高2倍的加速。<sup>[1](https://developer.nvidia.com/blog/new-features-cuda-7-5/)</sup>
- 流多处理器5.3引入了原生half算术，以配对的`half2`形式最为高效，将两个值打包进一个32位字。<sup>[12](https://www.cudahandbook.com/book/ch8/floating-point-support)</sup>
- Pascal代Tesla P100的FP16算术吞吐量是FP32的两倍，在NVLink SXM2模块上达到21.2万亿次半精度浮点运算每秒。<sup>[7](https://developer.nvidia.com/blog/mixed-precision-programming-cuda-8/)</sup>
- 自Volta架构起，张量核心为半精度矩阵运算提供原生支持，包括累加到浮点输出。<sup>[12](https://www.cudahandbook.com/book/ch8/floating-point-support)</sup>

`half2`打包形式对吞吐量很重要：GPU算术指令一次对32位寄存器中的两个FP16值进行运算，而标量half指令只能达到一半的峰值速率。<sup>[7](https://developer.nvidia.com/blog/mixed-precision-programming-cuda-8/)</sup> CUDA的`__half`类型符合IEEE 754-2008的16位格式，位布局与标准的binary16相同。<sup>[3](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> 在CUDA世界之外，苹果的Metal着色语言和Accelerate框架提供16位half类型，苹果芯片GPU针对16位数据类型进行了优化。<sup>[13](https://developer.apple.com/documentation/metal/mtltessellationfactorformat/half?changes=_9)</sup><sup> • </sup><sup>[14](https://developer-rno.apple.com/videos/play/wwdc2020/10632/?time=1275)</sup>

## 混合精度深度学习

现代半精度的最大用户是神经网络训练。Micikevicius及其同事（ICLR 2018）的混合精度训练方法以IEEE半精度格式存储权重、激活和梯度，将内存消耗减少近一半，但它依赖三项技术来弥补FP16较窄的范围。<sup>[6](https://arxiv.org/abs/1710.03740)</sup> 第一，权重的单精度主副本在每次优化器步骤后累加梯度，避免将小的FP16更新加到大的FP16权重上所造成的精度损失。第二，在反向传播前对损失进行缩放，使原本会下溢为零的小梯度值保持在FP16可表示的范围内；缩放因子的选取使其与最大绝对梯度的乘积保持在65504以下，即最大FP16值。第三，FP16乘积在存回half之前累加到单精度输出中。<sup>[6](https://arxiv.org/abs/1710.03740)</sup>

梯度下溢是实际中的失效模式：在训练后期，FP16梯度可能下溢并导致收敛停滞。框架将补救措施自动化。PyTorch的自动混合精度将`torch.autocast`（把运算转换为float16或bfloat16）与`GradScaler`配对使用，后者在反向传播期间动态缩放梯度以防止下溢。<sup>[15](https://docs.pytorch.org/docs/stable/accelerator/amp.html)</sup> 这种缩放是float16特有的；bfloat16混合精度不需要梯度缩放。<sup>[16](https://discuss.pytorch.org/t/whats-the-use-of-scaled-grad-params-in-this-example-of-gradient-penalty-with-scaled-gradients/199741/4)</sup>

## 与bfloat16的比较

Bfloat16是主要的16位替代方案，两种格式做出了相反的取舍。Bfloat16使用1个符号位、8个指数位和7个尾数位，动态范围与FP32相同但精度低得多；FP16保留更多尾数位，但指数范围窄得多。<sup>[17](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup> 谷歌为其Cloud TPU设计了bfloat16，依据是神经网络对指数大小的敏感度远高于对尾数大小的敏感度，其动态范围意味着能放入FP32的值在收窄时不会溢出。<sup>[17](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus)</sup> 对训练的实际影响在一项bfloat16深度学习研究中有所记载：符合IEEE 754的FP16需要调超参数才能收敛，而像bfloat16那样保持FP32范围则免去了这一要求。<sup>[18](https://arxiv.org/abs/1905.12322)</sup> 两种格式都已与binary16一道成为事实上的16位标准。<sup>[19](https://bpb-us-e1.wpmucdn.com/wp.nyu.edu/dist/8/24616/files/2024/01/RevisedBookForStudentsJan24.pdf)</sup>

## 机器学习之外的用途

由机器学习推动的低精度算术已扩展到科学计算，fp16和bfloat16在GPU及其他加速器上日益可用，能为通用数值算法带来速度、能耗和通信成本方面的收益。<sup>[5](https://epubs.siam.org/doi/10.1137/19M1251308)</sup> 应用对格式的安全使用位置有所选择。在天气和气候建模中，一项关于浅水模型中16位格式的研究发现，简单地将所有计算切换为16位会因舍入误差而降低结果质量，但重缩放、重排序和混合精度等缓解方法使16位浮点算术能够在此类模型的部分环节中成功使用。<sup>[20](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2020MS002246)</sup> 在波浪模拟中，半精度的累积舍入误差会降低解的质量，而在具有原生半精度算术的硬件上，补偿求和已被证明是一种补救措施。<sup>[21](https://arxiv.org/abs/2310.00236)</sup> 使用半精度数的混合精度求解器也被应用于A64FX处理器上的格点QCD，并加入了重缩放步骤以保证稳定性。<sup>[22](https://arxiv.org/abs/2602.14450)</sup>

语言支持仍落后于硬件。IEEE 754-2019标准定义了binary16交换格式，但Fortran标准没有提供对应的real16类型，因此Low Precision Fortran等库以普通浮点类型的形式提供binary16、bfloat16和8位类型。<sup>[23](https://arxiv.org/abs/2606.16709)</sup>

## References

1. [New Features in CUDA 7.5, NVIDIA Technical Blog](https://developer.nvidia.com/blog/new-features-cuda-7-5/)
2. [OpenEXR File Layout, OpenEXR Documentation](https://openexr.com/en/latest/OpenEXRFileLayout.html)
3. [5.5. Floating-Point Computation, CUDA Programming Guide](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)
4. [Chapter 26. The OpenEXR Image File Format, GPU Gems, NVIDIA Developer](https://developer.nvidia.com/gpugems/gpugems/part-iv-image-processing/chapter-26-openexr-image-file-format)
5. [Higham, N. J. and Pranesh, S. Simulating Low Precision Floating-Point Arithmetic, SIAM Journal on Scientific Computing](https://epubs.siam.org/doi/10.1137/19M1251308)
6. [Micikevicius, P. et al. Mixed Precision Training, ICLR 2018 / arXiv:1710.03740](https://arxiv.org/abs/1710.03740)
7. [Mixed-Precision Programming with CUDA 8, NVIDIA Technical Blog](https://developer.nvidia.com/blog/mixed-precision-programming-cuda-8/)
8. [OpenEXR 1.0.6 documentation, NVIDIA developer download](https://download.nvidia.com/developer/GPU_Gems/CD_Image/Image_Processing/OpenEXR/OpenEXR-1.0.6/doc/)
9. [OpenEXR Concepts, OpenEXR Documentation](https://openexr.com/en/latest/concepts.html)
10. [openexr-aarch64 README, GitHub](https://github.com/syoyo/openexr-aarch64)
11. [NVIDIA GPU Programming Guide](https://download.nvidia.com/developer/GPU_Programming_Guide/GPU_Programming_Guide.pdf)
12. [The CUDA Handbook, Chapter 8.3 Floating Point Support](https://www.cudahandbook.com/book/ch8/floating-point-support)
13. [MTLTessellationFactorFormat.half, Apple Developer Documentation](https://developer.apple.com/documentation/metal/mtltessellationfactorformat/half?changes=_9)
14. [Optimize Metal Performance for Apple silicon Macs, WWDC20](https://developer-rno.apple.com/videos/play/wwdc2020/10632/?time=1275)
15. [Automatic Mixed Precision, PyTorch documentation](https://docs.pytorch.org/docs/stable/accelerator/amp.html)
16. [PyTorch Forums: scaled_grad_params in gradient penalty with scaled gradients](https://discuss.pytorch.org/t/whats-the-use-of-scaled-grad-params-in-this-example-of-gradient-penalty-with-scaled-gradients/199741/4)
17. [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)
18. [A Study of BFLOAT16 for Deep Learning Training, arXiv:1905.12322](https://arxiv.org/abs/1905.12322)
19. [Numerical Computing with IEEE Floating Point Arithmetic, SIAM (chapter excerpt)](https://bpb-us-e1.wpmucdn.com/wp.nyu.edu/dist/8/24616/files/2024/01/RevisedBookForStudentsJan24.pdf)
20. [Klöwer, M. et al. Number Formats, Error Mitigation, and Scope for 16-Bit Arithmetics in Weather and Climate Modeling, JAMES (2020)](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2020MS002246)
21. [Half precision wave simulation, arXiv:2310.00236](https://arxiv.org/abs/2310.00236)
22. [Mixed precision solvers with half-precision floating point numbers for Lattice QCD on A64FX processor, arXiv:2602.14450](https://arxiv.org/abs/2602.14450)
23. [Low Precision Fortran: Enabling Low Precision Floating Point Arithmetic in Modern Fortran, arXiv:2606.16709](https://arxiv.org/abs/2606.16709)
24. [Half PrecisionFloating PointFormat, lweb.cfa.harvard.edu](https://lweb.cfa.harvard.edu/sma/miriad/swarm/news/Half-precisionFloating-pointFormat.html)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: 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/half-precision-floating-point-format

English original: https://www.edgepedia.org/half-precision-floating-point-format
