Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the Tensorflow profiler with tf.Estimator

I need to use the Tensorflow profiler to profile some code that is running slowly for some reason. Unfortunately, the code in question uses tf.Estimator, so I can't figure out how to inject the run metadata object into the session run() call in order to get the information that the profiler needs.

What should I do?

like image 300
forefinger Avatar asked Nov 10 '17 01:11

forefinger


People also ask

What kind of estimator model does TensorFlow recommend using for classification?

It is recommended using pre-made Estimators when just getting started. To write a TensorFlow program based on pre-made Estimators, you must perform the following tasks: Create one or more input functions. Define the model's feature columns.

What is TensorFlow profiler?

The TensorFlow Profiler (or the Profiler) provides a set of tools that you can use to measure the training performance and resource consumption of your TensorFlow models. This new version of the Profiler is integrated into TensorBoard, and builds upon existing capabilities such as the Trace Viewer.


2 Answers

tf.estimator use tf.train.ProfilerHook works!

just add a ProfilerHook in TrainSpec hooks!

hook = tf.train.ProfilerHook(
    save_steps=20,
    output_dir=os.path.join(args.model_dir, "tracing"),
    show_dataflow=True,
    show_memory=True)
hooks = [hook]
train_spec = tf.estimator.TrainSpec(
    hooks=hooks,
    input_fn=lambda: input_fn())

then, you could get the tracing file like timeline-{}.json in model_dir/tracing, and open chrome chrome://tracing to visual!

refs: https://stackoverflow.com/a/48278275/6494418

like image 143
Colin Wang Avatar answered Sep 26 '22 01:09

Colin Wang


with tf.contrib.tfprof.ProfileContext('/tmp/train_dir', dump_steps=[10]) as pctx: estimator.train() # any thing you want to profile

Then you will get a file at /tmp/train_dir/profile_10

Arguments are defined in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/profiler/profile_context.py

like image 29
Jason Liu Avatar answered Sep 22 '22 01:09

Jason Liu