|TensorFlow 2 version||View source on GitHub|
Loss scale that dynamically adjusts itself.
Dynamic loss scaling works by adjusting the loss scale as training progresses. The goal is to keep the loss scale as high as possible without overflowing the gradients. As long as the gradients do not overflow, raising the loss scale never hurts.
The algorithm starts by setting the loss scale to an initial value. Every N steps that the gradients are finite, the loss scale is increased by some factor. However, if a NaN or Inf gradient is found, the gradients for that step are not applied, and the loss scale is decreased by the factor. This process tends to keep the loss scale as high as possible without gradients overflowing.
__init__( initial_loss_scale=(2 ** 15), increment_period=2000, multiplier=2.0 )
Creates the dynamic loss scale.
initial_loss_scale: A Python float. The loss scale to use at the beginning. It's better to start this at a very high number, because a loss scale that is too high gets lowered far more quickly than a loss scale that is too low gets raised. The default is 2 ** 15, which is approximately half the maximum float16 value.
increment_period: Increases loss scale every
increment_periodconsecutive steps that finite gradients are encountered. If a nonfinite gradient is encountered, the count is reset back to zero.
multiplier: The multiplier to use when increasing or decreasing the loss scale.
Returns the current loss scale as a scalar
from_config( cls, config )
Creates the LossScale from its config.
Returns the config of this loss scale.
Updates loss scale based on if gradients are finite in current step.