is_autocast_enabled

paddle. is_autocast_enabled ( device_type: PlaceLike | None = None ) bool [source]

Check whether auto-mixed-precision is enabled in the current context.

Parameters

device_type (PlaceLike, optional) – The device type to check. This argument is ignored for all devices sharing the same AMP state in paddlepaddle.

Returns

True if auto-mixed-precision is enabled, False otherwise.

Return type

bool

Examples

>>> 
>>> # Demo1: Check if auto-mixed-precision is enabled by default
>>> import paddle
>>> paddle.device.set_device('gpu')
>>> print(paddle.is_autocast_enabled())
False

>>> # Demo2: Enable auto-mixed-precision and check again
>>> with paddle.amp.auto_cast():
...     print(paddle.is_autocast_enabled())
True