check_numerics

paddle.amp.debugging. check_numerics ( tensor, op_type, var_name, debug_mode=DebugMode.CHECK_NAN_INF_AND_ABORT ) [source]

This function is used to debugging a tensor, finding the number of NaNs, Infs and zeros in the tensor.

Parameters
  • tensor (Tensor) – The target tensor to check.

  • op_type (str) – The OP or API name which produce the target tensor.

  • var_name (str) – The name of target tensor.

  • debug_mode (paddle.amp.debugging.DebugMode, optional) – The mode of debugging to be used. Default is DebugMode.CHECK_NAN_INF_AND_ABORT.

Returns

A tuple of tensors containing

  • stats (Tensor): Returns the number of NaNs, Infs and zeros of input tensor. The shape is [3] and dtype is int64.

  • values (Tensor): Returns the maximum, minimum and mean value of input tensor. The shape is [3] and dtype is float.

Return type

(Tensor, Tensor)

Examples

>>> import paddle

>>> checker_config = paddle.amp.debugging.TensorCheckerConfig(
...     enable=True, debug_mode=paddle.amp.debugging.DebugMode.CHECK_NAN_INF)

>>> x = paddle.to_tensor([1, 0, 3], place=paddle.CPUPlace(), dtype='float32')
>>> y = paddle.to_tensor([0.2, 0, 0.5], place=paddle.CPUPlace(), dtype='float32')
>>> res = paddle.pow(x, y)
>>> paddle.amp.debugging.check_numerics(res, "pow", "res")