tf.compat.v1.profiler.Profiler

View source on GitHub

TensorFlow multi-step profiler.

tf.compat.v1.profiler.Profiler(
    graph=None, op_log=None
)

https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/README.md

Typical use case:
  # Currently we are only allowed to create 1 profiler per process.
  profiler = Profiler(sess.graph)

  for i in xrange(total_steps):
    if i % 10000 == 0:
      run_meta = tf.compat.v1.RunMetadata()
      _ = sess.run(...,
                   options=tf.compat.v1.RunOptions(
                       trace_level=tf.RunOptions.FULL_TRACE),
                   run_metadata=run_meta)
      profiler.add_step(i, run_meta)

      # Profile the parameters of your model.
      profiler.profile_name_scope(options=(option_builder.ProfileOptionBuilder
          .trainable_variables_parameter()))

      # Or profile the timing of your model operations.
      opts = option_builder.ProfileOptionBuilder.time_and_memory()
      profiler.profile_operations(options=opts)

      # Or you can generate a timeline:
      opts = (option_builder.ProfileOptionBuilder(
              option_builder.ProfileOptionBuilder.time_and_memory())
              .with_step(i)
              .with_timeline_output(filename).build())
      profiler.profile_graph(options=opts)
    else:
      _ = sess.run(...)
  # Auto detect problems and generate advice.
  profiler.advise()

Args:

Methods

add_step

View source

add_step(
    step, run_meta
)

Add statistics of a step.

Args:

advise

View source

advise(
    options
)

Automatically detect problems and generate reports.

Args:

Returns:

A Advise proto that conains the reports from all checkers.

profile_graph

View source

profile_graph(
    options
)

Profile the statistics of graph nodes, organized by dataflow graph.

Args:

Returns:

a GraphNodeProto that records the results.

profile_name_scope

View source

profile_name_scope(
    options
)

Profile the statistics of graph nodes, organized by name scope.

Args:

Returns:

a GraphNodeProto that records the results.

profile_operations

View source

profile_operations(
    options
)

Profile the statistics of the Operation types (e.g. MatMul, Conv2D).

Args:

Returns:

a MultiGraphNodeProto that records the results.

profile_python

View source

profile_python(
    options
)

Profile the statistics of the Python codes.

By default, it shows the call stack from root. To avoid redundant output, you may use options to filter as below options['show_name_regexes'] = ['.*my_code.py.*']

Args:

Returns:

a MultiGraphNodeProto that records the results.

serialize_to_string

View source

serialize_to_string()

Serialize the ProfileProto to a binary string.

Users can write it to file for offline analysis by tfprof commandline or graphical interface.

Returns:

ProfileProto binary string.