我正在嘗試在我的 Tensorflow 代碼中實現分布式執行。我創建了一個簡單的例子。當我運行它時,該程序不會產生任何結果。我的猜測是我的 Linux 系統的主機位置設置不正確。import tensorflow as tfcluster = tf.train.ClusterSpec({"local": ["localhost:2222", "localhost:2223"]})x = tf.constant(2)with tf.device("/job:local/task:1"): y2 = x - 66with tf.device("/job:local/task:0"): y1 = x + 300 y = y1 + y2with tf.Session("grpc://localhost:2222") as sess: result = sess.run(y) print(result)
1 回答

牛魔王的故事
TA貢獻1830條經驗 獲得超3個贊
在運行上面的會話之前,需要使用另一個腳本(python tfserver.py 0& python tfserver.py 1)啟動 2 個工作進程。localhost此外,由于集群中的一些限制,我必須替換為實際的服務器名稱。
# Get task number from command line
import sys
task_number = int(sys.argv[1])
import tensorflow as tf
cluster = tf.train.ClusterSpec({"local": ["localhost:2222", "localhost:2223"]})
server = tf.train.Server(cluster, job_name="local", task_index=task_number)
print("Starting server #{}".format(task_number))
server.start()
server.join()
添加回答
舉報
0/150
提交
取消