is_grad_enabled

paddle. is_grad_enabled ( ) [source]

Returns whether current dygraph gradient calculation mode is enabled.

Returns

True if current dygraph gradient calculation mode is enabled, otherwise false.

Return type

bool

Examples

>>> import paddle

>>> # Dygraph gradient calculation mode is enabled by default.
>>> paddle.is_grad_enabled()
True

>>> with paddle.set_grad_enabled(False):
...     paddle.is_grad_enabled()
False

>>> paddle.enable_static()
>>> paddle.is_grad_enabled()
False