【问题标题】:Distributed tensorflow of Between-graph replication?图间复制的分布式张量流?
【发布时间】:2017-10-10 13:17:58
【问题描述】:

看我写的代码:

import tensorflow as tf 


tf.flags.DEFINE_string('job_name', 'ps', 'worker or ps')
tf.flags.DEFINE_integer('task_index', 0, 'task id')
FLAGS = tf.flags.FLAGS

host = '127.0.0.1:'
cluster = {"ps": [host+'2222'],
           "worker": [host+'2223', host+'2224']}
clusterspec = tf.train.ClusterSpec(cluster)

server = tf.train.Server(cluster,
                         job_name=FLAGS.job_name,
                         task_index=FLAGS.task_index)

def print_fn():
    print('job_name: %s, task_index: %d' % (FLAGS.job_name, FLAGS.task_index))


if FLAGS.job_name == 'ps':
    server.join()
elif FLAGS.job_name == 'worker':
    with tf.device(tf.train.replica_device_setter(
        worker_device="/job:worker/task:%d" % FLAGS.task_index,
        cluster=cluster)):

      a = tf.Variable(tf.zeros([]), name='a')
      b = tf.Variable(tf.zeros([]), name='b')
      op = tf.add(a, b)
      print(a.device)
      print(b.device)
      print(op.device)
      print(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
print_fn()

当我在cmd 中运行python distributed_replicas.py --job_name=worker --task_index=0,但之前没有运行python distributed_replicas.py --job_name=ps --task_index=0 时,程序也可以运行。 a.deviceb.device 都是 /job:ps/task:0,但是 ps server 不启动,变量 ab 是如何存储在 ps server 上的?而tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)还包含变量ab,也就是说ab是在/job:worker/task:0上创建的,虽然它们的设备是/job:ps/task:0,那怎么了? ab 是在哪里创建的?

【问题讨论】:

    标签: python tensorflow distributed-computing grpc


    【解决方案1】:

    这是预期的行为。到目前为止,在您的代码中,您只创建了一个图表,它不需要/关心作业的启动和运行。

    您将在创建 Session(或任何 Session 变体)后遇到问题。

    更多信息在这里: https://www.tensorflow.org/extend/architecture

    【讨论】:

    • 哪些代码创建distributed master 并对图进行分区?这是否意味着每个worker server 上的图形都会被分区?这是否意味着每个worker server 都将保留接收节点,而所有worker servers 将从ps server 接收相同的参数?
    • 一般来说,Master(创建 Session 时客户端连接的服务器)将创建分区图并将其发送到其他服务器(服务器由新的 Session 或 tf.train 创建.服务器)。
    • 当使用 PS 架构时,所有工作人员在 Forward pass 开始时都有一个 Recv Op 从一个或多个 PS 读取数据,在 Backward pass 期间有一个 Send Op 将更新发送回 PS .
    • 请注意,在图间样式中,有 N 个客户端和 N 个主控。
    猜你喜欢
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-12
    • 1970-01-01
    相关资源
    最近更新 更多