disable_tensor_checker¶
disable_tensor_checker() 用于禁用精度检查,通常与 enable_tensor_checker(config) 一起使用,通过检查指定范围内所有算子的输出张量来实现模型级别的精度检查。
返回¶
无返回值
注解
如果在 backward() 之前调用 disable_tensor_checker(),则不会检查梯度算子; 如果在 optimizer.step() 之前调用 disable_tensor_checker(),则不会检查优化器和其他与权重更新相关的算子。
代码示例¶
>>> import paddle
>>> checker_config = paddle.amp.debugging.TensorCheckerConfig(enable=True, debug_mode=paddle.amp.debugging.DebugMode.CHECK_NAN_INF)
>>> paddle.amp.debugging.enable_tensor_checker(checker_config)
>>> x = paddle.to_tensor([1, 0, 3], place=paddle.CPUPlace(), dtype='float32', stop_gradient=False)
>>> y = paddle.to_tensor([0.2, 0, 0.5], place=paddle.CPUPlace(), dtype='float32')
>>> res = paddle.pow(x, y)
>>> paddle.autograd.backward(res, retain_graph=True)
>>> paddle.amp.debugging.disable_tensor_checker()
>>> # [PRECISION] [ERROR] in [device=cpu, op=elementwise_pow_grad, tensor=, dtype=fp32], numel=3, num_nan=1, num_inf=0, num_zero=0, max=2.886751e-01, min=2.000000e-01, mean=-nan
>>> # when DebugMode.CHECK_NAN_INF_AND_ABORT and stack_height_limit = 1
>>> # Traceback (most recent call last):
>>> # res = paddle.pow(x, y)
>>> # File "/usr/local/lib/python3.8/dist-packages/paddle/tensor/math.py", line 447, in pow
>>> # return _C_ops.elementwise_pow(x, y)