【问题标题】:TensorFlow: minimalist program fails on distributed modeTensorFlow:极简程序在分布式模式下失败
【发布时间】:2017-03-28 17:25:33
【问题描述】:

我编写了一个非常简单的程序,它无需分发即可正常运行,但在分发模式下挂在CheckpointSaverHook 上(不过我的本地主机上的所有内容!)。我看到有一些关于在分布式模式下挂起的问题,但似乎没有一个与我的问题相符。

这是脚本(使用新图层 API 制作的玩具):

import numpy as np
import tensorflow as tf
from tensorflow.contrib.learn.python.learn import learn_runner
from tensorflow.contrib import layers

DATA_SIZE=10
DIMENSION=5
FEATURES='features'

def generate_input_fn():
    def _input_fn():
        mid = int(DATA_SIZE/2)

        data = np.array([np.ones(DIMENSION) if x < mid else -np.ones(DIMENSION) for x in range(DATA_SIZE)])
        labels = ['0' if x < mid else '1' for x in range(DATA_SIZE)]

        table = tf.contrib.lookup.string_to_index_table_from_tensor(tf.constant(['0', '1']))
        label_tensor = table.lookup(tf.convert_to_tensor(labels, dtype=tf.string))

        return dict(zip([FEATURES], [tf.convert_to_tensor(data, dtype=tf.float32)])), label_tensor
    return _input_fn

def build_estimator(model_dir):
    features = layers.real_valued_column(FEATURES, dimension=DIMENSION)
    return tf.contrib.learn.DNNLinearCombinedClassifier(
        model_dir=model_dir,
        dnn_feature_columns=[features],
        dnn_hidden_units=[20,20])

def generate_exp_fun():
    def _exp_fun(output_dir):
        return tf.contrib.learn.Experiment(
            build_estimator(output_dir),
            train_input_fn=generate_input_fn(),
            eval_input_fn=generate_input_fn(),
            train_steps=100
        )
    return _exp_fun

if __name__ == '__main__':
    tf.logging.set_verbosity(tf.logging.DEBUG)
    learn_runner.run(generate_exp_fun(), 'job_dir')

为了测试分布式模式,我简单地用环境变量TF_CONFIG={"cluster": {"ps":["localhost:5040"], "worker":["localhost:5041"]}, "task":{"type":"worker","index":0}, "environment": "local"}启动它(这是给worker的,和ps一样类型用于启动参数服务器。

我在 windows-64 上使用 tensorflow-1.0.1(但与 1.0.0 具有相同的行为),只有 CPU。我实际上从来没有收到任何错误,它只是在INFO:tensorflow:Create CheckpointSaverHook. 之后永远挂起......我试图将 VisualStudio C++ 调试器附加到该进程但到目前为止收效甚微,所以我无法打印堆栈中发生的事情原生部分。

P.S.:DNNLinearCombinedClassifier 不是问题,因为简单的tf.contrib.learn.LinearClassifier 也会失败。正如 cmets 中所指出的,这不是因为两个进程都在 localhost 上运行,因为它在单独的 VM 上运行时也会失败。

编辑:我认为服务器启动实际上存在问题。当您处于本地模式(无论是否分布式)时,看起来服务器没有启动,参见。 tensorflow/contrib/learn/python/learn/experiment.py l.250-258:

# Start the server, if needed. It's important to start the server before
# we (optionally) sleep for the case where no device_filters are set.
# Otherwise, the servers will wait to connect to each other before starting
# to train. We might as well start as soon as we can.
config = self._estimator.config
if (config.environment != run_config.Environment.LOCAL and
    config.environment != run_config.Environment.GOOGLE and
    config.cluster_spec and config.master):
  self._start_server()

这将阻止服务器以本地模式为工作人员启动...有人知道这是错误还是我遗漏了什么?

【问题讨论】:

  • 请注意,如果我在两个单独的虚拟机中运行相同的脚本,它们也无法运行它......所以这不是因为两者都生活在本地主机上。
  • 在 TensorFlow 存储库上打开了一个 github 问题:github.com/tensorflow/tensorflow/issues/8796

标签: python tensorflow


【解决方案1】:

所以这个问题已经回答了:https://github.com/tensorflow/tensorflow/issues/8796。最后,任何分布式操作都应该使用CLOUD

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多