mindspore/docs/api/api_python/amp/mindspore.amp.LossScaler.rst

33 lines
1.1 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.amp.LossScaler
========================
.. py:class:: mindspore.amp.LossScaler
使用混合精度时用于管理损失缩放系数loss scaler的抽象类。
派生类需要实现该类的所有方法。训练过程中,`scale``unscale` 用于对损失值或梯度进行放大或缩小,以避免数据溢出;`adjust` 用于调整损失缩放系数 `scale_value` 的值。
.. note::
- 这是一个实验性接口,后续可能删除或修改。
.. py:method:: adjust(grads_finite)
根据梯度是否为有效值(无溢出)对 `scale_value` 进行调整。
参数:
- **grads_finite** (Tensor) - bool类型的标量Tensor表示梯度是否为有效值无溢出
.. py:method:: scale(inputs)
对inputs进行scale`inputs \*= scale_value`
参数:
- **inputs** (Union(Tensor, tuple(Tensor))) - 损失值或梯度。
.. py:method:: unscale(inputs)
对inputs进行unscale`inputs /= scale_value`
参数:
- **inputs** (Union(Tensor, tuple(Tensor))) - 损失值或梯度。