首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >tensorflow:如何利用tf.estimator.train_and_evaluate进行分布式训练

tensorflow:如何利用tf.estimator.train_and_evaluate进行分布式训练
EN

Stack Overflow用户
提问于 2018-06-13 02:52:01
回答 2查看 1.2K关注 0票数 0

请参阅tf.estimator.train_and_evaluate evaluate示例--我想让这个示例以分布式方式运行,但培训过程似乎没有在分布式模式下启动,这是行不通的。

我的问题是:我能做些什么来使源代码分布式运行?

平台:系统: Ubuntu 18 tensorflow: v1.8

以下日志是我的源代码和操作步骤:

1源代码:

代码语言:javascript
运行
复制
import tensorflow as tf
import os
import sys
import json
import logging
import numpy as np
x = np.random.rand(1000)
y = np.random.choice([0,1],1000)
def data_input():
    ret={}
    ret['x'] = x   
    y_batch = y 
    print "data"
    return ret,y_batch  
tf.logging.set_verbosity(tf.logging.DEBUG)
my_feature_columns=[]
v_feature_column = tf.feature_column.numeric_column(key="x",shape=[])
my_feature_columns.append(v_feature_column)

estimator = tf.estimator.DNNClassifier(
    feature_columns=my_feature_columns,
    hidden_units=[1024, 512, 256],
    model_dir='/home/clxman/tf/')


train_spec = tf.estimator.TrainSpec(input_fn=lambda:data_input(), max_steps=1000)
eval_spec = tf.estimator.EvalSpec(input_fn=lambda:data_input())

tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

2在列车运行良好的单模式下运行。查看以下日志

clxman@:~/test$ python test_c.py

代码语言:javascript
运行
复制
/home/clxman/.local/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

INFO:tensorflow:Using default config.

INFO:tensorflow:Using config: {'_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_task_type': 'worker', '_train_distribute': None, '_is_chief': True, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7f4e37077890>, '_evaluation_master': '', '_save_checkpoints_steps': None, '_keep_checkpoint_every_n_hours': 10000, '_service': None, '_num_ps_replicas': 0, '_tf_random_seed': None, '_master': '', '_num_worker_replicas': 1, '_task_id': 0, '_log_step_count_steps': 100, '_model_dir': '/home/clxman/tf/', '_global_id_in_cluster': 0, '_save_summary_steps': 100}

INFO:tensorflow:Running training and evaluation locally (non-distributed).

INFO:tensorflow:Start train and evaluate loop. The evaluate will happen after 600 secs (eval_spec.throttle_secs) or training is finished.
data
INFO:tensorflow:Calling model_fn.

DEBUG:tensorflow:Transforming feature_column _NumericColumn(key='x', shape=(), default_value=None, dtype=tf.float32, normalizer_fn=None).

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Create CheckpointSaverHook.

INFO:tensorflow:Graph was finalized.

2018-06-12 23:50:25.702344: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2


INFO:tensorflow:Running local_init_op.

INFO:tensorflow:Done running local_init_op.

**INFO:tensorflow:Saving checkpoints for 1 into /home/clxman/tf/model.ckpt**.

**INFO:tensorflow:loss = 693.219, step = 1**


INFO:tensorflow:global_step/sec: 8.12489


**INFO:tensorflow:loss = 691.08575, step = 101 (12.309 sec)**

INFO:tensorflow:global_step/sec: 8.11321

INFO:tensorflow:loss = 690.9834, step = 201 (12.325 sec)

3配置TF_CONFIG和通过命令行分别启动脚本

代码语言:javascript
运行
复制
**chief session command line:**

clxman@clxman-VirtualBox:~/test$ TF_CONFIG='{
    "cluster": {
        "chief": ["192.168.6.99.123:2222"],
        "worker": ["192.168.6.99.123:2300"],
        "ps": ["192.168.6.99.123:2400"]
    },
    "task": {"type": "chief", "index": 0}
}'  python test_c.py

**ps session comand line:**

clxman@clxman-VirtualBox:~/test$ TF_CONFIG='{
    "cluster": {
        "chief": ["192.168.6.99.123:2222"],
        "worker": ["192.168.6.99.123:2300"],
        "ps": ["192.168.6.99.123:2400"]
    },
    "task": {"type": "ps", "index": 0}
}'  python test_c.py

**worker session comand line:**

clxman@clxman-VirtualBox:~/test$ TF_CONFIG='{
    "cluster": {
        "chief": ["192.168.6.99.123:2222"],
        "worker": ["192.168.6.99.123:2300"],
        "ps": ["192.168.6.99.123:2400"]
    },
    "task": {"type": "worker", "index": 0}
}'  python test_c.py

**evaluator session command line:**

clxman@clxman-VirtualBox:~/test$ TF_CONFIG='{
    "cluster": {
        "chief": ["192.168.6.99.123:2222"],
        "worker": ["192.168.6.99.123:2300"],
        "ps": ["192.168.6.99.123:2400"]
    },
    "task": {"type": "evaluator", "index": 0}
}'  python test_c.py

4下面的日志是从主会话开始的,我们可以看到培训过程没有启动。字符串"data“意味着培训过程调用了data_input函数,该函数为列车数据提供信息。

代码语言:javascript
运行
复制
INFO:tensorflow:Using default config.

INFO:tensorflow:Using config: {'_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_task_type': u'chief', '_train_distribute': None, '_is_chief': True, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7fc0024f18d0>, '_evaluation_master': '', '_save_checkpoints_steps': None, '_keep_checkpoint_every_n_hours': 10000, '_service': None, '_num_ps_replicas': 1, '_tf_random_seed': None, '_master': u'grpc://192.168.6.99.123:2222', '_num_worker_replicas': 2, '_task_id': 0, '_log_step_count_steps': 100, '_model_dir': '/home/clxman/tf/', '_global_id_in_cluster': 0, '_save_summary_steps': 100}

INFO:tensorflow:Start Tensorflow server.

2018-06-12 23:23:25.694865: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

2018-06-12 23:23:25.697065: I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:215] Initialize GrpcChannelCache for job chief -> {0 -> localhost:2222}

2018-06-12 23:23:25.697159: I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:215] Initialize GrpcChannelCache for job ps -> {0 -> 192.168.6.99.123:2400}

2018-06-12 23:23:25.697180: I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:215] Initialize GrpcChannelCache for job worker -> {0 -> 192.168.6.99.123:2300}

2018-06-12 23:23:25.698882: I tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc:332] Started server with target: grpc://localhost:2222

**data**

INFO:tensorflow:Calling model_fn.

DEBUG:tensorflow:Transforming feature_column _NumericColumn(key='x', shape=(), default_value=None, dtype=tf.float32, normalizer_fn=None).

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Create CheckpointSaverHook.

INFO:tensorflow:Graph was finalized.
EN

Stack Overflow用户

发布于 2018-11-12 21:41:41

您必须在您的估值器的RunConfig中指定一个分发策略,如本文档所述:

https://github.com/tensorflow/tensorflow/tree/r1.8/tensorflow/contrib/distribute

但是,恐怕您正在寻找一个参数服务器策略(因为您有一个'ps‘任务),这在TF 1.8中是不可用的。

请注意,在TF的最新版本中,这个API已经更改,并且文档要完整得多:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/distribute/README.md#example

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50828432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档