class_docstr: Wrapper for the numerics-checking callback for thread locality.
class_docstr_tok: ["Wrapper","for","the","numerics-checking","callback","for","thread","locality","."]
docstr: Eager-function unified callback for checking numerics.
docstr_tok: ["Eager-function","unified","callback","for","checking","numerics","."]
code: def callback(
      self, op_type, inputs, attrs, outputs, op_name=None, graph=None
  ):
      """Eager-function unified callback for checking numerics."""
      del attrs, op_name  # Unused
      op_type_bytes = compat.as_bytes(op_type)
      is_v1_graph_mode = not ops.executing_eagerly_outside_functions()
      if (
          op_type_bytes in op_callbacks_common.OP_CALLBACK_SKIP_OPS
          or op_type_bytes in SAFE_OPS
      ):
          return None
      if graph:
          # Under graph mode. Insert check_numerics op.
          instrumented_outputs = []
          if is_v1_graph_mode:
              for input_tensor in inputs:
                  if (
                      input_tensor in self._placeholder_to_debug_tensor
                      and outputs
                  ):
                      outputs[
                          0
                      ].op._add_control_input(  # pylint: disable=protected-access
                          self._placeholder_to_debug_tensor[
                              input_tensor
                          ].op
                      )
          for slot, output in enumerate(outputs):
              if (
                  output.dtype.is_floating
                  and (op_type_bytes, slot) not in IGNORE_OP_OUTPUTS
              ):
                  checked_output = array_ops.check_numerics_v2(
                      # TF v2 has automatic control dependencies added to stateful async
                      # ops, which allows us to run check_numerics asynchronously.
                      # In the above case we use debug_summary to reduce all output
                      # tensors asynchronously from the op being checked and then
                      # process the tensor summary with check_numerics.
                      output
                      if is_v1_graph_mode
                      else _debug_summary(output),
                      get_check_numerics_error_message(
                          slot,
                          len(outputs),
                          op_type,
                          output,
                          inputs,
                          graph=graph,
                          traceback=output.op.traceback,
                          stack_height_limit=self._stack_height_limit,
                          path_length_limit=self._path_length_limit,
                      ),
                  )
                  _CHECK_NUMERICS_INPUT_LOOKUP[graph][
                      checked_output.name
                  ] = output
                  instrumented_outputs.append(
                      self._get_output_tensor(
                          op_type_bytes,
                          output,
                          checked_output,
                          is_v1_graph_mode,
                      )
                  )
              else:
                  instrumented_outputs.append(output)
          return instrumented_outputs
      else:
          if op_type_bytes == b"CheckNumericsV2":
              # TODO(b/140334369): Remove this special casing logic once op_callback.
              # automatically prevents infinite recursion in eager mode.
              return None
          # Under eager mode. Eagerly execute check_numerics op.
          for slot, output in enumerate(outputs):
              if (
                  output.dtype.is_floating
                  and (op_type_bytes, slot) not in IGNORE_OP_OUTPUTS
              ):
                  array_ops.check_numerics_v2(
                      output,
                      get_check_numerics_error_message(
                          slot,
                          len(outputs),
                          op_type,
                          output,
                          inputs,
                          stack_height_limit=self._stack_height_limit,
                          path_length_limit=self._path_length_limit,
                      ),
                  )
  
imports: import collections
  import threading
  import numpy
  from tensorflow.core.protobuf import debug_event_pb2
  from tensorflow.python.debug.lib import op_callbacks_common
  from tensorflow.python.debug.lib import source_utils
  from tensorflow.python.eager import monitoring
  from tensorflow.python.framework import op_callbacks
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gen_debug_ops
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.util import compat
  from tensorflow.python.util import object_identity
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 2 for calling the CheckNumericsCallback obj's underlying member method code with example usage: obj.callback(op_type, inputs, attrs, outputs, op_name, graph) and returns: None, instrumented_outputs, None