저는 분산 컴퓨팅 세계에 다소 새로운 점이 있습니다. 나는 공식 텐서 흐름 튜토리얼에서 following을 읽었지 만, 튜토리얼의 주요 예에서 무슨 일이 벌어지고 있는지에 대해서는 상당히 혼란 스러웠다.배포 된 Tensorflow 자습서 예제를 설명 할 수 있습니까?
특히 ps 작업과 근로자는 어떻게 상호 작용합니까? ps 작업의 역할은 정확히 무엇입니까? 코드에서 해당 부분이 상당히 제한되어 있으며 많은 작업을 수행하지 않는 것으로 보입니다. 따라서 용도는 무엇입니까? 분산 시스템의 여러 부분이 어떻게 함께 작동하는지 이해하지 못합니다.
다른 프로세스와 동작의 측면에서 셸 명령을 실행할 때 정확히 무슨 일이 일어날 지 설명 할 수 있다면 좋을 것입니다. 여기
import argparse
import sys
import tensorflow as tf
FLAGS = None
def main(_):
ps_hosts = FLAGS.ps_hosts.split(",")
worker_hosts = FLAGS.worker_hosts.split(",")
# Create a cluster from the parameter server and worker hosts.
cluster = tf.train.ClusterSpec({"ps": ps_hosts, "worker": worker_hosts})
# Create and start a server for the local task.
server = tf.train.Server(cluster,
job_name=FLAGS.job_name,
task_index=FLAGS.task_index)
if FLAGS.job_name == "ps":
server.join()
elif FLAGS.job_name == "worker":
# Assigns ops to the local worker by default.
with tf.device(tf.train.replica_device_setter(
worker_device="/job:worker/task:%d" % FLAGS.task_index,
cluster=cluster)):
# Build model...
loss = ...
global_step = tf.contrib.framework.get_or_create_global_step()
train_op = tf.train.AdagradOptimizer(0.01).minimize(
loss, global_step=global_step)
# The StopAtStepHook handles stopping after running given steps.
hooks=[tf.train.StopAtStepHook(last_step=1000000)]
# The MonitoredTrainingSession takes care of session initialization,
# restoring from a checkpoint, saving to a checkpoint, and closing when done
# or an error occurs.
with tf.train.MonitoredTrainingSession(master=server.target,
is_chief=(FLAGS.task_index == 0),
checkpoint_dir="/tmp/train_logs",
hooks=hooks) as mon_sess:
while not mon_sess.should_stop():
# Run a training step asynchronously.
# See `tf.train.SyncReplicasOptimizer` for additional details on how to
# perform *synchronous* training.
# mon_sess.run handles AbortedError in case of preempted PS.
mon_sess.run(train_op)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.register("type", "bool", lambda v: v.lower() == "true")
# Flags for defining the tf.train.ClusterSpec
parser.add_argument(
"--ps_hosts",
type=str,
default="",
help="Comma-separated list of hostname:port pairs"
)
parser.add_argument(
"--worker_hosts",
type=str,
default="",
help="Comma-separated list of hostname:port pairs"
)
parser.add_argument(
"--job_name",
type=str,
default="",
help="One of 'ps', 'worker'"
)
# Flags for defining the tf.train.Server
parser.add_argument(
"--task_index",
type=int,
default=0,
help="Index of task within the job"
)
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
는 쉘 명령입니다 : 여기
참조를위한 주요 코드
내 이해에 따르면, PS 작업이 다른 작업 사이의 모든 공유 데이터를 포함
$ python trainer.py\
--ps_hosts = ps0.example.com: 2222, ps1.example.com: 2222\
--worker_hosts = worker0.example.com: 2222, worker1.example.com: 2222\
--job_name = ps--task_index = 0# On ps1.example.com:
$ python trainer.py\
--ps_hosts = ps0.example.com: 2222, ps1.example.com: 2222\
--worker_hosts = worker0.example.com: 2222, worker1.example.com: 2222\
--job_name = ps--task_index = 1# On worker0.example.com:
$ python trainer.py\
--ps_hosts = ps0.example.com: 2222, ps1.example.com: 2222\
--worker_hosts = worker0.example.com: 2222, worker1.example.com: 2222\
--job_name = worker--task_index = 0# On worker1.example.com:
$ python trainer.py\
--ps_hosts = ps0.example.com: 2222, ps1.example.com: 2222\
--worker_hosts = worker0.example.com: 2222, worker1.example.com: 2222\
--job_name = worker--task_index = 1
값을 업데이트합니다. ps 코드의 작업. 왜 두 개가 있어야합니까? 예를 들어 동일한 코드를 실행했지만 ps 태스크 중 하나를 제거하면 어떻게됩니까? ps 작업이 동기화 용으로 만 존재하는 경우 왜 두 가지가 필요한지 알 수 없습니다. – moxox