【发布时间】:2018-04-21 14:33:20
【问题描述】:
为了了解分布式tensorflow的机制,我用multi-gpus写了一个简单的tensorflow测试代码
def cv_data(SEED):
np.random.seed(SEED)
return np.random.rand(5,2,2)
def test(data):
for i in range(5):
with tf.device('/gpu:%d' %i ):
with tf.name_scope('cv%d' %i):
x = tf.placeholder(tf.float32,[2,2],name='x')
y = tf.matmul(x,x)
init = tf.initialize_all_variables()
sess = tf.Session()
with sess as sess:
writer=tf.summary.FileWriter("test_graph",sess.graph)
sess.run(init)
print("y is ")
print(sess.run(y,feed_dict={'cv0/x:0':np.ones((2,2)),'cv1/x:0':2*np.ones((2,2)),'cv2/x:0':3*np.ones((2,2)),'cv3/x:0':4*np.ones((2,2)),'cv4/x:0':5*np.ones((2,2))))
#tf.train.Saver.save(sess,"./model")
writer.close()
但是 sess.run() 只执行 /gpu:4 的图,如何让所有 gpus 同时运行?
【问题讨论】:
标签: tensorflow deep-learning distributed-computing multi-gpu