class_docstr: Test for cases in which enable_check_numerics() catches infs or nans.
class_docstr_tok: ["Test","for","cases","in","which","enable_check_numerics","(",")","catches","infs","or","nans","."]
docstr: Test catching bfloat16 NaNs in a control-flow-v2 FuncGraph.
docstr_tok: ["Test","catching","bfloat16","NaNs","in","a","control-flow-v2","FuncGraph","."]
code: def testControlFlowGraphWithNaNBFloat16(self):
      """Test catching bfloat16 NaNs in a control-flow-v2 FuncGraph."""
      check_numerics_callback.enable_check_numerics()
  
      @def_function.function
      def my_conditional(x):
          if math_ops.less(math_ops.reduce_sum(x), 0.0):
              return math_ops.log(x)
          else:
              return math_ops.log(-x)
  
      x = constant_op.constant([1.0, 2.0, 3.0], dtype=dtypes.bfloat16)
      message = self._assertRaisesInvalidArgumentErrorAndGetMessage(
          lambda: self.evaluate(my_conditional(x))
      )
      # Check the content of the error message.
      self.assertTrue(re.search(r"graph op.*\"Log\"", message))
      self.assertTrue(re.search(r"dtype.*bfloat16", message))
      self.assertIn("shape: (3,)\n", message)
      # Check that the correct input op is printed.
      self.assertTrue(re.search(r"Input tensor.*Tensor.*Neg", message))
      # Check that the correct line for op creation is printed.
      self.assertTrue(
          re.search(r"Stack trace of op's creation", message)
      )
      self.assertIn("my_conditional", message)
  
imports: import re
  import numpy
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.debug.lib import check_numerics_callback
  from tensorflow.python.eager import backprop
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_grad
  from tensorflow.python.ops import custom_gradient
  from tensorflow.python.ops import gen_nn_ops
  from tensorflow.python.ops import gradient_checker_v2
  from tensorflow.python.ops import math_grad
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import googletest
  from tensorflow.python.platform import test
label_desc: Use image node_id 8 for calling the CheckNumericsCallbackUnhealthyTest obj's underlying member method code with example usage: obj.testControlFlowGraphWithNaNBFloat16() and returns: math_ops, math_ops