所有 TF1 損失量表的基類。
用法
tf.mixed_precision.experimental.LossScale()
警告:此類已棄用,並且在 TensorFlow 的未來版本中不會從 TF 2 命名空間中公開。一旦發生這種情況,這個類將隻能作為 tf.compat.v1.mixed_precision.LossScale
訪問。此類中的所有函數都已合並到 tf.keras.mixed_precision.LossScaleOptimizer
中,因此不再需要此類。
這是一個抽象基類,所以不能直接實例化它。相反,使用它的具體子類之一:
損失縮放是將損失乘以稱為損失比例的乘數的過程,並將每個梯度除以相同的乘數。這個過程的偽代碼是:
loss = ...
loss *= loss_scale
grads = gradients(loss, vars)
grads /= loss_scale
在數學上,損失縮放沒有影響,但是當 float16 張量用於混合精度訓練時,可以幫助避免中間梯度中的數值下溢。通過乘以損失,每個中間梯度將應用相同的乘數。
此類的實例表示損失量表。調用此類的實例將損失比例返回為標量 float32 張量,而方法 update()
根據梯度的值更新損失比例。優化器使用此類的實例來縮放損失和梯度。
在大多數接受 LossScale 的函數中,您還可以傳遞一個 int(例如
8) 創建FixedLossScale
或字符串"dynamic"
以創建動態損失比例。
相關用法
- Python tf.math.special.fresnel_cos用法及代碼示例
- Python tf.math.polyval用法及代碼示例
- Python tf.math.is_finite用法及代碼示例
- Python tf.math.special.bessel_k0e用法及代碼示例
- Python tf.math.acosh用法及代碼示例
- Python tf.math.invert_permutation用法及代碼示例
- Python tf.math.segment_prod用法及代碼示例
- Python tf.math.bincount用法及代碼示例
- Python tf.math.bessel_i0e用法及代碼示例
- Python tf.math.unsorted_segment_min用法及代碼示例
- Python tf.math.conj用法及代碼示例
- Python tf.math.scalar_mul用法及代碼示例
- Python tf.math.zero_fraction用法及代碼示例
- Python tf.math.reduce_max用法及代碼示例
- Python tf.math.special.fresnel_sin用法及代碼示例
- Python tf.math.segment_mean用法及代碼示例
- Python tf.math.xlog1py用法及代碼示例
- Python tf.math.less_equal用法及代碼示例
- Python tf.mlir.experimental.convert_function用法及代碼示例
- Python tf.math.reduce_min用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.mixed_precision.experimental.LossScale。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。