首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何打开tensorflow xla

如何打开tensorflow xla
EN

Stack Overflow用户
提问于 2018-10-19 10:00:17
回答 2查看 4.7K关注 0票数 1

我尝试了tensorflow/ example /tutorials/mnist下的示例&尝试将xla应用于加速。然而,我看不到XlaLaunch像https://www.tensorflow.org/performance/xla/jit所说的那样。

此外,我还试图通过以下方法来分析执行时间:

代码语言:javascript
复制
  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.没有区别。

我看到一些文章说我应该“重建”tensorflow源代码来打开xla?我应该吗?

还有其他方法打开它吗?或者默认情况下已打开它,但我使用它的方式是错误的。

是否有基准来描述xla打开后加速的情况?

谢谢~

EN

回答 2

Stack Overflow用户

发布于 2019-02-25 22:53:37

pip中最新可用的TensorFlow二进制文件可能包括已经内置的XLA支持。pip install tensorflow --upgrade --force-reinstallpip install tensorflow-gpu --upgrade --force-reinstall将为您提供此支持(截止TF 1.12)。这是为我在Ubuntu与或不支持NVIDIA GPU支持,但不是在我的MacBook。如果您的二进制程序没有,那么在尝试使用基准测试时,您将了解下面的内容。

如果您正在正确地调用XLA,并且没有内置到二进制文件中的支持,那么您将得到一个异常。有点像

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 (e.g.) 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基准库这里。如果没有下载ImageNet,则可以使用合成数据。您可以使用标志--xla_compile=TrueFalse启用或禁用XLA。

例如:

代码语言:javascript
复制
python tf_cnn_benchmarks.py --num_batches=2000 --xla_compile=True
票数 1
EN

Stack Overflow用户

发布于 2021-06-23 07:38:33

在不使用任何标志安装Tensorflow的情况下启用XLA的一种方法是在运行运行培训的脚本时遵循https://github.com/tensorflow/tensorflow/issues/44683中的说明并设置环境变量:

代码语言:javascript
复制
>>> TF_XLA_FLAGS=--tf_xla_enable_xla_devices python my_training_script.py

然后,您将看到日志消息:

代码语言:javascript
复制
XLA service 0x95522ao initialized for platform Host (this does not guarantee that XLA will be used). Devices:
  StreamExecutor device (0): Host, Default Version
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52890108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档