亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Session.run 在 Tensorflow 代碼中進行并行編程

使用 Session.run 在 Tensorflow 代碼中進行并行編程

梵蒂岡之花 2023-06-27 16:21:28
我正在嘗試在我的 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()

查看完整回答
反對 回復 2023-06-27
  • 1 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號