tensorboard: TensorFlow v2: Graph does not appear on TensorBoard
A graph may not appear if TensorFlow could not trace any graph during the execution. For instance, below code does not use @tf.function and, because it is pure eager, there is no graph TensorFlow used.
# Missing @tf.function
def foo(x, y):
return tf.linalg.cross(x, y)
tf.summary.trace_on()
foo([1,2], [3,4])
with writer.as_default():
tf.summary.trace_export()
Other known issues
- When a function is invoked before trace, the graph does not show up
@tf.function
def foo(x, y):
return tf.linalg.cross(x, y)
foo([1,2], [3,4]) # this is not traced.
tf.summary.trace_on()
foo([1,2], [3,4])
with writer.as_default():
tf.summary.trace_export()
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 24
- Comments: 42 (15 by maintainers)
@cottrell Yup correct. Pure eager builds no graph. Keras always has built some graph underneath (the details escape me at the moment but IIRC, in v1, it built a graph using its own session and, in v2, it constructs graph with FuncGraph) and is able to show some graph unless you pass
run_eagerlyto its compile method.I have the same problem
Device: macbook pro 2018 , macOS Mojave 10.14.5 tensorflow version: tensorflow==2.0.0a0 tensorflow-estimator-2.0-preview==1.14.0.dev2019052100
I have the same issues too, i followed the code shows in https://tensorflow.org/tensorboard/r2/graphs the most below method.
# The function to be traced. @tf.function def my_func(x, y): # A simple hand-rolled layer. return tf.nn.relu(tf.matmul(x, y)) # Set up logging. stamp = datetime.now().strftime("%Y%m%d-%H%M%S") logdir = 'logs/func/%s' % stamp writer = tf.summary.create_file_writer(logdir) # Sample data for your function. x = tf.random.uniform((3, 3)) y = tf.random.uniform((3, 3)) # Bracket the function call with # tf.summary.trace_on() and tf.summary.trace_export(). tf.summary.trace_on(graph=True, profiler=True) # Call only one tf.function when tracing. z = my_func(x, y) with writer.as_default(): tf.summary.trace_export( name="my_func_trace", step=0, profiler_outdir=logdir)in the tutorials, it shows the graphs, however when i ran this code in my environment it doesn’t shows the graph in the tensorboard
So to clarify, if you use eager only code, you can not debug with tensorboard graphs? I’m confused as to how the keras writer does this. Maybe that is a tf.function under the hood now.
Hi @stephanwlee,
Thanks for your answer and your insights, I’ve been able to change my code a little bit and make tit work. 👍🏻 Just in case other people stumble upon this, the following is a small script that highlights one of the differences between
autograph.to_graphandtf.functionWhich outputs
Ok now we have a ticket at https://github.com/tensorflow/profiler/issues/503. I hope that we don’t need to do too much forth and back and that for the ownership between repos 😸
/cc @MarkDaoust This bug it is very annoying and it is confusing new users especially cause we still have the same example in the official documentation on the TF website and that this was submitted in 2019.
I am running into a graph not appearing on TensorBoard after wrapping one of the
tf.keras.applicationsmodels (Namely MobileNet) withtf.functionand then following the suggested code snippets.Does anyone have an idea on why does this happen?
FYI, I am running
tensorflow==2.1.0andtensorboard==2.1.1(latest stable builds installed withpip install tensorflow), andtf.executing_eagerly()is certainlyFalsefor theoptimized_modelfunction.When using a model which inherits from
tensorflow.python.keras.Model, there is a graph which can be visualized! This even works withrun_eagerly=True. The trick is to save the graph at the right moment. Such a moment occurs, when keras/tensorflow builds the model, because it invokes model.call in non-eager mode (not exactly sure why). The resulting tensor holds the model graph (without losses afaik), which can be written using the “old”FileWriter. Example code that works for me with Tensorflow 1.13.1 and enabled eager execution:Latter is a bug of TensorFlow’s and former is working as intended; if your code is purely eager, there is absolutely no computational graphs and thus the graph plugin cannot do anything about it.