mindspore.amp.LossScaler

class mindspore.amp.LossScaler[source]

Loss scaler abstract class when using mixed precision.

Derived class needs to implement all of its methods. During training, scale and unscale is used to scale and unscale the loss value and gradients to avoid overflow, adjust is used to update the loss scale value.

Note

This is an experimental interface that is subject to change or deletion.

abstract adjust(grads_finite)[source]

Adjust the scale_value dependent on whether grads are finite.

Parameters

grads_finite (Tensor) – a scalar bool Tensor indicating whether the grads are finite.

abstract scale(inputs)[source]

Scaling inputs by scale_value.

Parameters

inputs (Union(Tensor, tuple(Tensor))) – the input loss value or gradients.

abstract unscale(inputs)[source]

Unscaling inputs by scale_value.

Parameters

inputs (Union(Tensor, tuple(Tensor))) – the input loss value or gradients.