tensorflow: [TF 2.0] tf.estimator.ProfilerHook... is not compatible with eager execution

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Debian 8.8
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): via pip
  • TensorFlow version (use command below): tf.__git_version__ : 'v1.12.0-9492-g2c319fb415', version tensorflow==2.0.0-alpha0
  • Python version: 3.6
  • Bazel version (if compiling from source): NA
  • GCC/Compiler version (if compiling from source): NA
  • CUDA/cuDNN version: NA
  • GPU model and memory: NA

Describe the current behavior When constructing a tf.estimator.ProfilerHook a error is thrown: RuntimeError: tf.summary.FileWriter is not compatible with eager execution. Use tf.contrib.summary instead.

Describe the expected behavior

Code to reproduce the issue

import tensorflow as tf
tf.estimator.ProfilerHook(10)

Other info / logs

I’m not very familiar with tf 2.0, so maybe this is just user error? Is it possible to use tf2 not in eager mode?

Full traceback:

RuntimeError                              Traceback (most recent call last)
<ipython-input-7-4eefc50dcc45> in <module>
----> 1 tf.estimator.ProfilerHook(10)

~/tf2-venv/lib/python3.6/site-packages/tensorflow/python/training/basic_session_run_hooks.py in __init__(self, save_steps,save_secs, output_dir, show_dataflow, show_memory)
   1013     """
   1014     self._output_file = os.path.join(output_dir, "timeline-{}.json")
-> 1015     self._file_writer = SummaryWriterCache.get(output_dir)
   1016     self._show_dataflow = show_dataflow
   1017     self._show_memory = show_memory

~/tf2-venv/lib/python3.6/site-packages/tensorflow/python/summary/writer/writer_cache.py in get(logdir)
     61       if logdir not in FileWriterCache._cache:
     62         FileWriterCache._cache[logdir] = FileWriter(
---> 63             logdir, graph=ops.get_default_graph())
     64       return FileWriterCache._cache[logdir]

~/tf2-venv/lib/python3.6/site-packages/tensorflow/python/summary/writer/writer.py in __init__(self, logdir, graph, max_queue, flush_secs, graph_def, filename_suffix, session)
    358     if context.executing_eagerly():
    359       raise RuntimeError(
--> 360           "tf.summary.FileWriter is not compatible with eager execution. "
    361           "Use tf.contrib.summary instead.")
    362     if session is not None:

RuntimeError: tf.summary.FileWriter is not compatible with eager execution. Use tf.contrib.summary instead.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 22 (11 by maintainers)

Most upvoted comments

The bug still exists in tensorflow==2.0.0-beta1

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution: Ubuntu 18.04
  • TensorFlow installed from (source or binary): via pip
  • TensorFlow version (use command below): tf.git_version : ā€˜v2.0.0-beta0-17-g8e423e3’, version – - tensorflow==2.0.0-beta1
  • Python version: 3.6
  • Bazel version (if compiling from source): NA
  • GCC/Compiler version (if compiling from source): NA
  • CUDA/cuDNN version: 10.0
  • GPU model and memory: NVIDIA Titan XP

Code to reproduce the issue

profiler_hook = tf.estimator.ProfilerHook(save_steps=2000, output_dir=MODEL_DIR + '/profiler/', show_memory=True)
train_spec = tf.estimator.TrainSpec(lambda: train_input_fn(train_raw, BATCH_SIZE, EPOCH, TRAIN_BUFFER_SIZE),  hooks=[profiler_hook])
eval_spec = tf.estimator.EvalSpec(lambda: test_input_fn(test_raw, BATCH_SIZE),
                                  throttle_secs=100)
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
model.summary()

Other Info / Logs

The full traceback is listed as follows:

Traceback (most recent call last):
  File "main.py", line 124, in <module>
    main()
  File "main.py", line 110, in main
    profiler_hook = tf.estimator.ProfilerHook(save_steps=2000, output_dir=MODEL_DIR + '/profiler/', show_memory=True)
  File "/data/wangzejun/anadonda/envs/tf2.0/lib/python3.7/site-packages/tensorflow/python/training/basic_session_run_hooks.py", line 1024, in __init__
    self._file_writer = SummaryWriterCache.get(output_dir)
  File "/data/wangzejun/anadonda/envs/tf2.0/lib/python3.7/site-packages/tensorflow/python/summary/writer/writer_cache.py", line 63, in get
    logdir, graph=ops.get_default_graph())
  File "/data/wangzejun/anadonda/envs/tf2.0/lib/python3.7/site-packages/tensorflow/python/summary/writer/writer.py", line 360, in __init__
    "tf.summary.FileWriter is not compatible with eager execution. "
RuntimeError: tf.summary.FileWriter is not compatible with eager execution. Use tf.contrib.summary instead.

The instruction from compat.v1 still works fine, which makes the code a little bit ugly.
Thank for your attention.

I think we should make it work in TF2. Will take a look what the options are here.

@lendle Could you try this to disable eager execution in 2.0 import tensorflow as tf tf.compat.v1.disable_eager_execution() tf.estimator.ProfilerHook(10)

Thanks!