【问题标题】:How to select half precision (BFLOAT16 vs FLOAT16) for your trained model?如何为您的训练模型选择半精度(BFLOAT16 vs FLOAT16)?
【发布时间】:2021-11-22 17:59:45
【问题描述】:

您将如何确定最适合您的推理模型的精度? 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.

【问题讨论】:

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


【解决方案1】:

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

如果您选择float16,请查看AMP

【讨论】:

  • 谢谢。想知道如果硬件支持两者你会选择什么..
  • @RedFox bfloat16,正如我的回答最后提到的那样。 (你可能在我写那部分之前就读过了)
  • 谢谢。他们确实提供了不同的数字范围。想知道这个范围是否是选择一个而不是另一个的原因。 ps:用范围更新了问题。
猜你喜欢
  • 2019-01-07
  • 1970-01-01
  • 2011-07-27
  • 2021-05-14
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 2017-09-16
  • 2020-05-23
相关资源
最近更新 更多