Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用tf的TensorFlow分布式训练。主管在运行init_op时暂停_Python_Tensorflow_Distributed Computing - Fatal编程技术网

Python 使用tf的TensorFlow分布式训练。主管在运行init_op时暂停

Python 使用tf的TensorFlow分布式训练。主管在运行init_op时暂停,python,tensorflow,distributed-computing,Python,Tensorflow,Distributed Computing,我正在尝试使用基于的TensorFlow r0.12.1获得一些简单的分布式训练代码。但是,我的分布式会话出现问题,无法返回 我的群集规范如下所示,我正在同一台服务器上运行ps和worker进程: cluster = tf.train.ClusterSpec({ 'ps': ['localhost:2222'], 'worker': ['localhost:2223', 'localhost:2224'] }) 使用此方法,我的ps流程如下所示: server = tf.tra

我正在尝试使用基于的TensorFlow r0.12.1获得一些简单的分布式训练代码。但是,我的分布式会话出现问题,无法返回

我的群集规范如下所示,我正在同一台服务器上运行ps和worker进程:

cluster = tf.train.ClusterSpec({
    'ps': ['localhost:2222'],
    'worker': ['localhost:2223', 'localhost:2224']
})
使用此方法,我的ps流程如下所示:

server = tf.train.Server(cluster, job_name="ps")
server.join()
我的两名员工尝试使用MNIST训练一个简单的网络,并使用
CUDA\u VISIBLE\u DEVICES=0
CUDA\u VISIBLE\u DEVICES=1
启动:

TASK_INDEX = <0 or 1>
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)

server = tf.train.Server(cluster, job_name="worker", task_index=TASK_INDEX)

with tf.device(tf.train.replica_device_setter(
        worker_device="/job:worker/task:%d" % task_index,
        cluster=cluster)):
    x = tf.placeholder(tf.float32, shape=[None, 784])
    y_ = tf.placeholder(tf.float32, shape=[None, 10])
    W = tf.Variable(tf.zeros([784, 10]))
    b = tf.Variable(tf.zeros([10]))
    y = tf.matmul(x, W) + b
    cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))
    global_step = tf.Variable(0)

    train_op = tf.train.AdagradOptimizer(0.01).minimize(
          cross_entropy, global_step=global_step)
    summary_op = tf.summary.merge_all()
    init_op = tf.global_variables_initializer()

sv = tf.train.Supervisor(is_chief=(task_index == 0),
                         init_op=init_op,
                         summary_op=summary_op,
                         global_step=global_step)

with sv.managed_session(server.target) as sess:
    step = 0
    batch_sz = 50
    iters = 55000 / batch_sz
    while not sv.should_stop() and step < iters:
        _, step = sess.run([train_op, global_step], feed_dict={x: mnist.train.images[step*batch_sz:(step+1)*batch_sz],
                                                               y_: mnist.train.labels[step*batch_sz:(step+1)*batch_sz]})

# Ask for all the services to stop.
sv.stop()
因此,在尝试运行初始化操作时,整个过程似乎都在暂停,但不会产生任何错误消息。定期培训(不是通过tf.Supervisor)在同一系统上运行良好,因此不太可能是安装/驱动问题


在运行
init_op
时,是否有任何原因导致进程暂停?关于如何正确使用
tf.Supervisor
,我是否缺少一些东西?

后续:这里有一个稍微清理过的版本,在我的系统上具有相同的行为(在初始化时冻结):这通常发生在无法连接到参数服务器时。它将无限期挂起,直到能够建立连接。我将检查是否可以建立到目标主机/端口的连接(使用netcat或telnet)。另外,
GRPC\u VERBOSITY=DEBUG
也可能有用,非常感谢!这似乎确实是一个很好的假设。不过,我正在本地主机上运行,并且已经确认在运行时端口是使用netcat打开的。更重要的是,如果我使用
GRPC\u VERBOSITY=DEBUG
GRPC\u TRACE=all
运行,看起来在参数服务器和工作者之间来回发送消息。。。关于如何更深入地检查代码中哪些地方出现了问题,还有其他想法吗?
init_op
在做什么?你可以尝试通过一个例子来缩小范围,其中
init_op
是一个no op(在没有变量的网络上尝试),或者传递一个自定义init_op,它什么都不做。这是一个很棒的建议@YaroslavBulatov–非常感谢!但不知怎么的,代码开始运行了,这表明它可能毕竟是RPC问题。我很想让RPC的失败行为更透明一点——也许这是一个可以转移到TF回购的讨论!
sess.run(init_op, feed_dict=init_feed_dict)