[英]How to open tensorflow xla
我在tensorflow / examples / tutorials / mnist下尝试了该示例,并尝试应用xla进行加速。 但是,我看不到XlaLaunch如https://www.tensorflow.org/performance/xla/jit所述。
另外,我尝试通过以下方式分析执行时间:
train_loops = 100000
t_start = time.time()
for i in range(train_loops):
batch_xs, batch_ys = mnist.train.next_batch(100)
# Create a timeline for the last loop and export to json to view with
# chrome://tracing/.
if i == train_loops - 1:
sess.run(train_step,
feed_dict={x: batch_xs,
y_: batch_ys},
options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
run_metadata=run_metadata)
trace = timeline.Timeline(step_stats=run_metadata.step_stats)
with open('timeline.ctf.json', 'w') as trace_file:
trace_file.write(trace.generate_chrome_trace_format())
else:
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
tdiff = time.time() - t_start
print("tdiff", tdiff, " i = ", i)
使用xla和不使用xla之间似乎没有区别。
我看到一些文章说我应该“重建” tensorflow源来打开xla? 我是不是该?
还有其他打开方式吗? 或默认情况下已将其打开,但我使用它的方式有误。
一旦打开xla,是否有基准可以描述提速?
谢谢〜
pip中可用的最新TensorFlow二进制文件可能包括已内置的XLA支持。 pip install tensorflow --upgrade --force-reinstall
或pip install tensorflow-gpu --upgrade --force-reinstall
将为您提供此支持(从TF 1.12开始)。 这对我适用于具有或不具有NVIDIA GPU支持的Ubuntu,但不适用于我的MacBook。 如果您的二进制文件没有,则在尝试使用基准测试时会在下面知道。
如果您正确地调用XLA JIT,并且二进制文件中没有内置的支持,则会出现异常。 就像是
ValueError: Op type not registered 'XlaClusterOutput' in binary running on localhost. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (eg) tf.contrib.resampler should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed. while building NodeDef 'tower_0/v/output0'
如果明白了,尝试安装最新的tensorflow,甚至每晚进行一次tf。 如果这不起作用,请花些时间从源头上构建自己。
您在代码中的哪个位置启用了XLA?
对于测试基准,您可以在此处尝试进入官方TensorFlow Benchmarks存储库。 如果未下载ImageNet,则可以使用合成数据。 您可以使用--xla_compile=True
或False
标志启用或禁用XLA。
例如:
python tf_cnn_benchmarks.py --num_batches=2000 --xla_compile=True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.