<br />

<button value="stable" default="">See Stable</button> <button value="nightly">See Nightly</button>

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/summary_ops_v2.py#L1069-L1135) |

Writes a TensorFlow graph summary.

    tf.summary.graph(
        graph_data
    )

Write an instance of [`tf.Graph`](https://www.tensorflow.org/api_docs/python/tf/Graph) or [`tf.compat.v1.GraphDef`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/GraphDef) as summary only
in an eager mode. Please prefer to use the trace APIs ([`tf.summary.trace_on`](https://www.tensorflow.org/api_docs/python/tf/summary/trace_on),
[`tf.summary.trace_off`](https://www.tensorflow.org/api_docs/python/tf/summary/trace_off), and [`tf.summary.trace_export`](https://www.tensorflow.org/api_docs/python/tf/summary/trace_export)) when using
[`tf.function`](https://www.tensorflow.org/api_docs/python/tf/function) which can automatically collect and record graphs from
executions.

#### Usage Example:

    writer = tf.summary.create_file_writer("/tmp/mylogs")

    @tf.function
    def f():
      x = constant_op.constant(2)
      y = constant_op.constant(3)
      return x**y

    with writer.as_default():
      tf.summary.graph(f.get_concrete_function().graph)

    # Another example: in a very rare use case, when you are dealing with a TF v1
    # graph.
    graph = tf.Graph()
    with graph.as_default():
      c = tf.constant(30.0)
    with writer.as_default():
      tf.summary.graph(graph)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `graph_data` | The TensorFlow graph to write, as a [`tf.Graph`](https://www.tensorflow.org/api_docs/python/tf/Graph) or a [`tf.compat.v1.GraphDef`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/GraphDef). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| True on success, or False if no summary was written because no default summary writer was available. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | `graph` summary API is invoked in a graph mode. |

<br />