Пример #1
0
 def testTrace_cannotExportTraceInGraphMode(self):
   with test.mock.patch.object(logging, 'warn') as mock_log:
     with context.graph_mode():
       summary_ops.trace_export(name='foo', step=1)
     self.assertRegexpMatches(
         str(mock_log.call_args),
         'Can only export trace while executing eagerly.')
Пример #2
0
 def testTrace_cannotExportTraceInGraphMode(self):
     with test.mock.patch.object(logging, 'warn') as mock_log:
         with context.graph_mode():
             summary_ops.trace_export(name='foo', step=1)
         self.assertRegexpMatches(
             str(mock_log.call_args),
             'Can only export trace while executing eagerly.')
Пример #3
0
 def _log_trace(self, global_batch_idx):
     with self.summary_writers['train'].as_default(
     ), summary_ops_v2.always_record_summaries():
         summary_ops_v2.trace_export(
             name='batch_{}'.format(global_batch_idx),
             step=global_batch_idx,
             profiler_outdir=self.train_log_dir)
     self.is_tracing = False
    def _log_trace(self):
        if context.executing_eagerly():
            with self.writer.as_default(), \
                 summary_ops_v2.always_record_summaries():
                summary_ops_v2.trace_export(
                    name='batch_%d' % self._total_batches_seen,
                    step=self._total_batches_seen,
                    profiler_outdir=os.path.join(self.log_dir, 'train'))

            self._is_tracing = False
Пример #5
0
 def _log_trace(self):
     if context.executing_eagerly():
         with self._get_writer(self._train_run_name).as_default(), \
             summary_ops_v2.always_record_summaries():
             # TODO(b/126388999): Remove step info in the summary name.
             summary_ops_v2.trace_export(
                 name='batch_%d' % self._total_batches_seen,
                 step=self._total_batches_seen,
                 profiler_outdir=os.path.join(self.log_dir, 'train'))
         self._is_tracing = False
Пример #6
0
 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]
Пример #7
0
 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]
Пример #8
0
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!')
Пример #9
0
 def f():
     x = constant_op.constant(2)
     y = constant_op.constant(3)
     summary_ops.trace_export(name='foo', step=1)
     return x**y
Пример #10
0
 def testTrace_cannotExportTraceWithoutTrace(self):
     with six.assertRaisesRegex(self, ValueError,
                                'Must enable trace before export.'):
         summary_ops.trace_export(name='foo', step=1)
Пример #11
0
 def f():
   x = constant_op.constant(2)
   y = constant_op.constant(3)
   summary_ops.trace_export(name='foo', step=1)
   return x**y
Пример #12
0
 def testTrace_cannotExportTraceWithoutTrace(self):
   with six.assertRaisesRegex(self, ValueError,
                              'Must enable trace before export.'):
     summary_ops.trace_export(name='foo', step=1)