最近安装了分布式处理的tensorflow版本。 来自trend ,我试着在多台电脑上用多个GPU实现,也发现了一个white paper一些额外的规范。 我可以在分别具有 2 个和 1 个 gpus 的 2 台不同计算机上运行服务器和 worker,并使用 session grpc,在远程或本地模式下分配和运行程序。
我在远程计算机上本地运行了 tensorflow:
bazel-bin/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server \
--cluster_spec='local|localhost:2500' --job_name=local --task_id=0 &
在服务器上使用
bazel-bin/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server \
--cluster_spec='worker|192.168.170.193:2500,prs|192.168.170.226:2500' --job_name=worker --task_id=0 \
--job_name=prs --task_id=0 &
但是,当我尝试指定同时在 2 台计算机上运行的设备时,python 向我显示错误:
Could not satisfy explicit device specification '/job:worker/task:0'
当我使用
with tf.device("/job:prs/task:0/device:gpu:0"):
x = tf.placeholder(tf.float32, [None, 784], name='x-input')
W = tf.Variable(tf.zeros([784, 10]), name='weights')
with tf.device("/job:prs/task:0/device:gpu:1"):
b = tf.Variable(tf.zeros([10], name='bias'))
# Use a name scope to organize nodes in the graph visualizer
with tf.device("/job:worker/task:0/device:gpu:0"):
with tf.name_scope('Wx_b'):
y = tf.nn.softmax(tf.matmul(x, W) + b)
甚至更改工作名称。所以我想知道是否需要 Add a New Device或者可能是我在初始化集群时做错了什么。
请您参考如下方法:
worker其实就是集群的名字。
您的第一个 bazel 调用应该是这样的:
bazel-bin/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server\ --cluster_spec='worker|192.168.170.193:2500;192.168.170.226:2501' --job_name=worker --task_id=0 &
您在第一个节点 192.168.170.193 上运行
您的集群名称是worker,其中包括两个节点的IP地址。然后任务引用两个运行节点。您必须在两个节点上启动协议(protocol),为每个节点指定不同的任务 ID,即。然后运行:
bazel-bin/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server \
--cluster_spec='worker|192.168.170.193:2500;192.168.170.226:2501' --job_name=worker --task_id=1 &`
在你的第二个节点上,192.168.170.226
然后运行:
with tf.device("/job:worker/task:0/device:gpu:0"):
x = tf.placeholder(tf.float32, [None, 784], name='x-input')
W = tf.Variable(tf.zeros([784, 10]), name='weights')
with tf.device("/job:worker/task:0/device:gpu:1"):
b = tf.Variable(tf.zeros([10], name='bias'))
# Use a name scope to organize nodes in the graph visualizer
with tf.device("/job:worker/task:1/device:gpu:0"):
with tf.name_scope('Wx_b'):
y = tf.nn.softmax(tf.matmul(x, W) + b)
