tensorflow - 如何为您训练的模型选择半精度(BFLOAT16 与 FLOAT16)?

标签 tensorflow machine-learning deep-learning pytorch half-precision-float

您将如何确定最适合您的推理模型的精度? BF16 和 F16 都占用两个字节,但它们对小数和指数使用的位数不同。

范围会有所不同,但我试图理解为什么人们会选择一个而不是另一个。

谢谢

    |--------+------+----------+----------|
    | Format | Bits | Exponent | Fraction |
    |--------+------+----------+----------|
    | FP32   |   32 |        8 |       23 |
    | FP16   |   16 |        5 |       10 |
    | BF16   |   16 |        8 |        7 |
    |--------+------+----------+----------|

Range
bfloat16: ~1.18e-38 … ~3.40e38 with 3 significant decimal digits.
float16:  ~5.96e−8 (6.10e−5) … 65504 with 4 significant decimal digits precision.

最佳答案

bfloat16 通常更易于使用,因为它可以作为 float32 的直接替代品。如果您的代码不创建 nan/inf 数字或使用 float32 将非 0 转换为 0 ,那么它也不应该用 bfloat16 来做,粗略地说。因此,如果您的硬件支持它,我会选择它。

查看 AMP如果您选择 float16

关于tensorflow - 如何为您训练的模型选择半精度(BFLOAT16 与 FLOAT16)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69399917/

相关文章:

apache-spark - 将经过训练的机器学习模型部署到生产中的步骤

r - R 中的分类/预测

python - 如何使用 Keras 处理 CNN 中可变大小的输入?

c++ - 在 Tensorflow C++ API 中初始化变量

python - 属性错误 : module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'

python - Keras FFT 层没有效果

Azure ML : finding the very similar client/payer

python - 相同的神经网络架构在 tensorflow 和 keras 中提供不同的精度

python - 如何在 TensorFlow 中应用渐变裁剪?

machine-learning - Tensorflow 中的 Dropconnect