【问题标题】:Distributed Tensorflow is getting stuck at sess.run()分布式 Tensorflow 卡在 sess.run()
【发布时间】:2017-01-09 08:42:06
【问题描述】:

我想在多台机器、多个 GPU 上运行 tensorflow。作为第一步,在单机上尝试分布式张量流(遵循张量流教程https://www.tensorflow.org/how_tos/distributed/

下面是 sess.run() 卡住的行

import tensorflow as tf
cluster = tf.train.ClusterSpec({"local": ["localhost:2222", "localhost:2223"]})
server = tf.train.Server(cluster, job_name="local", task_index=0)
a = tf.constant(8)
b = tf.constant(9)
sess = tf.Session('grpc://localhost:2222')

到目前为止一切正常,但是当我运行 sess.run() 时,它卡住了。

    sess.run(tf.mul(a,b))

如果有人已经研究过分布式张量流,请告诉我解决方案或其他可以正常工作的教程。

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    默认情况下,分布式 TensorFlow 将阻塞,直到 tf.train.ClusterSpec 中命名的所有服务器都已启动。这发生在与服务器的第一次交互期间,这通常是第一次sess.run() 调用。因此,如果您还没有启动服务器侦听 localhost:2223,那么 TensorFlow 将一直阻塞,直到您启动为止。

    这个问题有几个解决方案,取决于你以后的目标:

    1. localhost:2223 上启动服务器。在另一个进程中,运行以下脚本:

       import tensorflow as tf
       cluster = tf.train.ClusterSpec({"local": ["localhost:2222", "localhost:2223"]})
       server = tf.train.Server(cluster, job_name="local", task_index=1)
       server.join()  # Wait forever for incoming connections.
      
    2. 从原来的tf.train.ClusterSpec中删除任务1:

       import tensorflow as tf
       cluster = tf.train.ClusterSpec({"local": ["localhost:2222"]})
       server = tf.train.Server(cluster, job_name="local", task_index=0)
       # ...
      
    3. 在创建tf.Session 时指定“设备过滤器”,以便会话仅使用任务 0。

       # ...
       sess = tf.Session("grpc://localhost:2222",
                         config=tf.ConfigProto(device_filters=["/job:local/task:0"]))
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多