我正在尝试使用JIT编译运行一个简单的tensorflow示例,如https://www.tensorflow.org/versions/master/experimental/xla/jit所示。我使用以下代码代替mnist_softmax_xla示例:
def main(_):
config = tf.ConfigProto(log_device_placement=True)
jit_level = 0
if FLAGS.xla:
# Turns on XLA JIT compilation.
jit_level = tf.OptimizerOptions.ON_1
config.graph_options.optimizer_options.global_jit_level = jit_level
# Creates a session with log_device_placement set to True.
with tf.Session(config=config) as sess:
# Creates a graph.
with tf.device('/job:localhost/replica:0/task:0/device:XLA_CPU:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Runs the op.
print(sess.run(c))
我收到了一个错误:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device to node 'MatMul': Could not satisfy explicit device specification '/job:localhost/replica:0/task:0/device:XLA_CPU:0' because no devices matching that specification are registered in this process; available devices: /job:localhost/replica:0/task:0/cpu:0
[[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:XLA_CPU:0"](a, b)]]
我做错了什么?
答案 0 :(得分:1)
原来我正在运行Python2。它现在在使用Python3
运行时有效