MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _detect_nan_inf

Method _detect_nan_inf

tensorflow/python/tpu/tensor_tracer.py:541–555  ·  view source on GitHub ↗

Trace function for detecting any NaN/Inf in the tensor.

(tensor)

Source from the content-addressed store, hash-verified

539 """
540
541 def _detect_nan_inf(tensor):
542 """Trace function for detecting any NaN/Inf in the tensor."""
543
544 if tensor.dtype.is_floating:
545 mask = math_ops.reduce_any(
546 gen_math_ops.logical_or(
547 gen_math_ops.is_nan(tensor), gen_math_ops.is_inf(tensor)))
548 output_tensor = control_flow_ops.cond(mask,
549 lambda: constant_op.constant(1.0),
550 lambda: constant_op.constant(0.0))
551 else:
552 output_tensor = constant_op.constant(0.0)
553 # The shape has to be 1. Set it if it does not have the information.
554 output_tensor = array_ops.reshape(output_tensor, [1])
555 return output_tensor
556
557 def _compute_signature(tensor, tf_op, cast_to_f32=True):
558 if cast_to_f32:

Callers

nothing calls this directly

Calls 3

reshapeMethod · 0.80
condMethod · 0.45
constantMethod · 0.45

Tested by

no test coverage detected