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

Red*_*Fox 9 machine-learning deep-learning tensorflow pytorch half-precision-float

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

\n

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

\n

谢谢

\n
    |--------+------+----------+----------|\n    | Format | Bits | Exponent | Fraction |\n    |--------+------+----------+----------|\n    | FP32   |   32 |        8 |       23 |\n    | FP16   |   16 |        5 |       10 |\n    | BF16   |   16 |        8 |        7 |\n    |--------+------+----------+----------|\n\nRange\nbfloat16: ~1.18e-38 \xe2\x80\xa6 ~3.40e38 with 3 significant decimal digits.\nfloat16:  ~5.96e\xe2\x88\x928 (6.10e\xe2\x88\x925) \xe2\x80\xa6 65504 with 4 significant decimal digits precision.\n\n
Run Code Online (Sandbox Code Playgroud)\n

Max*_*axB 2

bfloat16通常更容易使用,因为它可以作为float32. 如果您的代码不创建nan/inf数字或将 non- 转换00with float32,那么粗略地说,它不应该使用bfloat16其中任何一个来执行此操作。所以,如果你的硬件支持它,我会选择它。

如果您选择,请查看AMPfloat16