[英]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.我需要使用 Tensorflow 分析器来分析一些由于某种原因运行缓慢的代码。 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.
不幸的是,有问题的代码使用了 tf.Estimator,所以我无法弄清楚如何将运行元数据对象注入会话 run() 调用中以获取分析器需要的信息。
What should I do?我该怎么办?
tf.estimator
use tf.train.ProfilerHook
works! tf.estimator
使用tf.train.ProfilerHook
工作!
just add a ProfilerHook
in TrainSpec
hooks!只需在
TrainSpec
钩子中添加一个ProfilerHook
!
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!然后,您可以在
model_dir/tracing
获取诸如timeline-{}.json
类的跟踪文件,并打开 chrome chrome://tracing
以进行可视化!
refs: https://stackoverflow.com/a/48278275/6494418参考文献: https : //stackoverflow.com/a/48278275/6494418
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
然后你会在
/tmp/train_dir/profile_10
得到一个文件
Arguments are defined in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/profiler/profile_context.py参数在https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/profiler/profile_context.py中定义
Use ProfileContext, as described here: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler .使用 ProfileContext,如下所述: https : //github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler 。 This allows you to profile without needing to get access to the session.
这使您无需访问会话即可进行概要分析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.