예제 #1
0
  def testMultiThreadedEagerOpExecution(self):
    # Instrument for the main thread.
    instrument_0 = _NumpyFunctionCallback()

    # Instrument for the to-be-created thread.
    instrument_1 = _NumpyFunctionCallback()

    def thread_1_job():
      op_callbacks.add_op_callback(instrument_1.callback)
      x = constant_op.constant(6.0)
      y = math_ops.square(math_ops.log(x))
      op_callbacks.remove_op_callback(instrument_1.callback)
      return y

    thread_1 = threading.Thread(target=thread_1_job)
    thread_1.start()

    # While thread_1 is ongoing, do something on the main thread.
    op_callbacks.add_op_callback(instrument_0.callback)
    x = constant_op.constant(2.0)
    y = math_ops.cos(x)
    self.assertAllClose(y, np.cos(2.0))
    op_callbacks.remove_op_callback(instrument_0.callback)

    thread_1.join()

    self.assertEqual(instrument_0.eager_op_types, [_COS_OP])
    self.assertEqual(instrument_0.eager_op_names, [None])
    self.assertEqual(instrument_1.eager_op_types, [_LOG_OP, _SQUARE_OP])
    self.assertEqual(instrument_1.eager_op_names, [None, None])
def disable_dumping():
    """Disable the currently-enabled debugging dumping.

  If the `enable_dumping()` method under the same Python namespace has been
  invoked before, calling this method disables it. If no call to
  `enable_dumping()` has been made, calling this method is a no-op.
  Calling this method more than once is idempotent.
  """
    if hasattr(_state, "config"):
        dump_root = _state.config.dump_root
        delattr(_state, "config")
        op_callbacks.remove_op_callback(_dumping_callback)
        logging.info("Disabled dumping callback in thread %s (dump root: %s)",
                     threading.current_thread().name, dump_root)
예제 #3
0
def disable_dumping():
  """Disable the currently-enabled debugging dumping.

  If the `enable_dumping()` method under the same Python namespace has been
  invoked before, calling this method disables it. If no call to
  `enable_dumping()` has been made, calling this method is a no-op.
  Calling this method more than once is idempotent.
  """
  try:
    op_callbacks.remove_op_callback(_dumping_callback)
    logging.info("Disabled dumping callback in thread %s (dump root: %s)",
                 threading.current_thread().name, _state.config.dump_root)
  except KeyError:
    # Tolerate disabling the dumping callback without enable_dumping() being
    # called first.
    pass
예제 #4
0
def disable_dump_debug_info():
    """Disable the currently-enabled debugging dumping.

  If the `enable_dump_debug_info()` method under the same Python namespace
  has been invoked before, calling this method disables it. If no call to
  `enable_dump_debug_info()` has been made, calling this method is a no-op.
  Calling this method more than once is idempotent.
  """
    if hasattr(_state, "dumping_callback"):
        dump_root = _state.dumping_callback.dump_root
        debug_events_writer.DebugEventsWriter(dump_root).Close()
        op_callbacks.remove_op_callback(_state.dumping_callback.callback)
        function_lib.remove_function_callback(
            _state.dumping_callback.function_callback)
        delattr(_state, "dumping_callback")
        logging.info("Disabled dumping callback in thread %s (dump root: %s)",
                     threading.current_thread().name, dump_root)
예제 #5
0
  def testSingleThreadedStack(self):
    ctx = context.context()
    instrument_0 = _NumpyFunctionCallback()
    instrument_1 = _NumpyFunctionCallback()

    op_callbacks.add_op_callback(instrument_0.callback)
    self.assertEqual(1, len(ctx.op_callbacks))
    self.assertIn(instrument_0.callback, ctx.op_callbacks)

    op_callbacks.add_op_callback(instrument_1.callback)
    self.assertEqual(2, len(ctx.op_callbacks))
    self.assertIn(instrument_0.callback, ctx.op_callbacks)
    self.assertIn(instrument_1.callback, ctx.op_callbacks)

    op_callbacks.remove_op_callback(instrument_1.callback)
    self.assertEqual(1, len(ctx.op_callbacks))
    self.assertIn(instrument_0.callback, ctx.op_callbacks)

    op_callbacks.remove_op_callback(instrument_0.callback)
    self.assertEqual(0, len(ctx.op_callbacks))
예제 #6
0
def disable_check_numerics():
    """Disable the eager/graph unified numerics checking mechanism.

  This method can be used after a call to `tf.debugging.enable_check_numerics()`
  to disable the numerics-checking mechanism that catches inifnity and NaN
  values output by ops executed eagerly or in tf.function-compiled graphs.

  This method is idempotent. Calling it multiple times has the same effect
  as calling it once.

  This method takes effect only on the thread in which it is called.
  """
    try:
        op_callbacks.remove_op_callback(_check_numerics_callback)
        logging.info("Disabled check-numerics callback in thread %s",
                     threading.current_thread().name)
    except KeyError:
        # Tolerate disabling the check numerics callback without
        # enable_check_numerics() being called first.
        pass
예제 #7
0
 def testRemovingCallbackTwiceLeadsToError(self):
   instrument = _NumpyFunctionCallback()
   op_callbacks.add_op_callback(instrument.callback)
   op_callbacks.remove_op_callback(instrument.callback)
   with self.assertRaisesRegex(KeyError, r"has not been registered"):
     op_callbacks.remove_op_callback(instrument.callback)
예제 #8
0
 def log_2plus_unique_x(x):
   op_callbacks.add_op_callback(instrument.callback)
   unique_values, _ = array_ops.unique(x)
   y = math_ops.log(2.0 + unique_values)
   op_callbacks.remove_op_callback(instrument.callback)
   return math_ops.sin(y)
예제 #9
0
 def thread_1_job():
   op_callbacks.add_op_callback(instrument_1.callback)
   x = constant_op.constant(6.0)
   y = math_ops.square(math_ops.log(x))
   op_callbacks.remove_op_callback(instrument_1.callback)
   return y
예제 #10
0
 def tearDown(self):
   op_callbacks.remove_op_callback(self._op_callback)
   self.trace_log = None
   self.variables = None
   super().tearDown()
예제 #11
0
 def __exit__(self, *args, **kwargs):
     op_callbacks.remove_op_callback(self.callback)
     logging.info("Disabled tensor dumping")