import json
import tensorflow as tf
num_devices=3
with open('clusterspec.json', 'r') as f:
clusterspec = json.load(f)
cluster = tf.train.ClusterSpec(clusterspec)
a = tf.constant(3)
b = tf.constant(2)
for i in range(num_devices):
with tf.device("/job:worker/task:%d"%i):
if( i == 0):
x = tf.mul(a,b)
if( i == 1):
y = tf.mul(a,b)
if( i == 2):
z = tf.mul(a,b)
server = tf.train.Server(cluster, job_name="master", task_index=0)
with tf.Session(server.target) as sess:
print "here"
print(sess.run([x,y,z]))
有人可以建议在多台机器上运行这个简单示例的更好方法。我不希望有三个不同的张量x
,y
和z
。相反,我只想要一个张量,而根本不使用图中的分支。