Using the Tensorflow profiler with tf.Estimator

Viewed 3657

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?

3 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

Related