tensorflow:有没有办法用 tensorflow 指定 XLA_GPU?

数据挖掘 Python 张量流
2022-02-18 13:27:00

以下代码用于指定运行 tf 节点的设备

with tf.device('/gpu:0'):
  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')

我已经知道: 这篇文章tensorflow docxla demo

我想知道的是:

有没有办法将 XLA_GPU 指定为运行 tf 节点的设备

with tf.device('/XLA_GPU:0'):
  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')

执行上面的代码给出ValueError: Unknown attribute: 'device' in '/job:localhost/replica:0/task:0/device:/XLA_GPU:0'

这在 google colab 上是 100% 可重现的。

1个回答

尝试“设备:XLA_GPU:0”

with tf.device('device:XLA_GPU:0'):
  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')