def run_trace(self, f, step=1): assert context.executing_eagerly() logdir = self.get_temp_dir() writer = summary_ops.create_file_writer(logdir) summary_ops.trace_on(graph=True, profiler=False) with writer.as_default(): f() summary_ops.trace_export(name='foo', step=step) writer.close() events = events_from_logdir(logdir) return events[1]
def run_trace(self, f, step=1): assert context.executing_eagerly() logdir = self.get_temp_dir() writer = summary_ops.create_file_writer(logdir) summary_ops.trace_on(graph=True, profiler=False) with writer.as_default(): f() summary_ops.trace_export(name='foo', step=step) writer.close() events = events_from_logdir(logdir) return events[1]
def log_trace(step, writer, logdir): global is_tracing if step == 1 and not is_tracing: summary_ops_v2.trace_on(graph=True, profiler=True) is_tracing = True print('start tracing...') elif is_tracing: with writer.as_default(): summary_ops_v2.trace_export(name='Default', step=step, profiler_outdir=os.path.join( logdir, 'train')) is_tracing = False print('export trace!')
def testTrace_cannotExportTraceInFunction(self): summary_ops.trace_on(graph=True, profiler=False) @def_function.function def f(): x = constant_op.constant(2) y = constant_op.constant(3) summary_ops.trace_export(name='foo', step=1) return x**y with test.mock.patch.object(logging, 'warn') as mock_log: f() self.assertRegex( str(mock_log.call_args), 'Cannot export trace inside a tf.function.')
def testTrace_cannotExportTraceInFunction(self): summary_ops.trace_on(graph=True, profiler=False) @def_function.function def f(): x = constant_op.constant(2) y = constant_op.constant(3) summary_ops.trace_export(name='foo', step=1) return x**y with test.mock.patch.object(logging, 'warn') as mock_log: f() self.assertRegexpMatches( str(mock_log.call_args), 'Cannot export trace inside a tf.function.')
def testTrace_cannotEnableTraceInGraphMode(self): with test.mock.patch.object(logging, 'warn') as mock_log: with context.graph_mode(): summary_ops.trace_on(graph=True, profiler=False) self.assertRegexpMatches(str(mock_log.call_args), 'Must enable trace in eager mode.')
def f(): summary_ops.trace_on(graph=True, profiler=False) x = constant_op.constant(2) y = constant_op.constant(3) return x**y
def testTrace_cannotEnableTraceInGraphMode(self): with test.mock.patch.object(logging, 'warn') as mock_log: with context.graph_mode(): summary_ops.trace_on(graph=True, profiler=False) self.assertRegexpMatches( str(mock_log.call_args), 'Must enable trace in eager mode.')
def f(): summary_ops.trace_on(graph=True, profiler=False) x = constant_op.constant(2) y = constant_op.constant(3) return x**y
def _enable_trace(self): if context.executing_eagerly(): summary_ops_v2.trace_on(graph=True, profiler=True) self._is_tracing = True
def on_train_begin(self, logs=None): if self._profile_batch == 1: summary_ops_v2.trace_on(graph=True, profiler=True) self._is_tracing = True
def _enable_trace(self): summary_ops_v2.trace_on(graph=True, profiler=True) self.is_tracing = True