TensorFlow 运行 可以使用多个 CPU(没有 GPU)吗?

Can TensorFlow run with multiple CPUs (no GPUs)?

我正在尝试学习分布式 TensorFlow。按照解释 here:

尝试了一段代码
with tf.device("/cpu:0"):
    W = tf.Variable(tf.zeros([784, 10]))
    b = tf.Variable(tf.zeros([10]))

with tf.device("/cpu:1"):
    y = tf.nn.softmax(tf.matmul(x, W) + b)
    loss = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

出现以下错误:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation 'MatMul': Operation was explicitly assigned to /device:CPU:1 but available devices are [ /job:localhost/replica:0/task:0/cpu:0 ]. Make sure the device specification refers to a valid device.
     [[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/device:CPU:1"](Placeholder, Variable/read)]]

意思是TensorFlow不识别CPU:1.

我 运行 在 40 CPUs (cat /proc/cpuinfo | grep processor | wc -l) 的 RedHat 服务器上。

有什么想法吗?

首先,仅 运行 它在 "one CPU" 上,然后查看 Tensorflow 是否适当地将线程分配给所有 CPU。它可能会正确地进行多线程处理,您无需执行任何操作。

如果没有,您应该尝试启动多个具有不同 CPU 相似性的 Tensorflow 实例,并执行一个 "distributed" 系统。 Tensorflow 有针对多台机器的分布式服务;它应该在一台机器上与单独的进程一起工作,只要你正确地设置你的文件,这样它们就不会写入相同的位置。您可以从 https://www.tensorflow.org/deploy/distributed . You might want to set the CPU affinities so that it's one process per physical CPU, a-la https://askubuntu.com/questions/102258/how-to-set-cpu-affinity-to-a-process

开始

在评论link之后:

原来应该将会话配置为设备数 > 1:

config = tf.ConfigProto(device_count={"CPU": 8})
with tf.Session(config=config) as sess:
   ...

有点震惊,我错过了一些如此基本的东西,而且没有人能指出一个看起来太明显的错误。

不确定是我的问题还是 TensorFlow 代码示例和文档的问题。既然是Google,就只能说是我了