【问题标题】:Parameter Server Strategy with estimators(Tensorflow)带有估计器的参数服务器策略(Tensorflow)
【发布时间】:2019-03-05 12:52:05
【问题描述】:

如何使用带有估计器的参数服务器策略进行分布式训练?如何在不使用 TF_CONFIG for Estimators 的情况下定义 Cluster Spec?

【问题讨论】:

    标签: tensorflow tensorflow-serving


    【解决方案1】:

    据我了解,使用环境变量,TF_CONFIG 是必须的,以便使用参数服务器分布式策略,其中我们定义了集群规范、PS 信息和关于任务的信息,以 json 格式。

    请在下面找到代码 sn-p,它演示了使用带有估计器的参数服务器策略进行分布式训练:

        # Configuring the Workers, Parameter Servers and Tasks
        NUM_WORKERS = 1
        IP_ADDRS = ['localhost']
        PORTS = [12345]
    
        os.environ['TF_CONFIG'] = json.dumps({
                'cluster': {
                    'worker': ['%s:%d' % (IP_ADDRS[w], PORTS[w]) for w in range(NUM_WORKERS)],
                    'ps': ['%s:%d' % (IP_ADDRS[w], PORTS[w]) for w in range(NUM_WORKERS)]
                },
                'task': {'type': 'worker', 'index': 0}
            })
    
        # Method for using ParamterServerStrategy
        strategy = tf.distribute.experimental.ParameterServerStrategy()
    
        config = tf.estimator.RunConfig(train_distribute=strategy)
    
        classifier = tf.estimator.Estimator(
            model_fn=model_fn, model_dir='/tmp/multiworker', config=config)
        tf.estimator.train_and_evaluate(
            classifier,
            train_spec=tf.estimator.TrainSpec(input_fn=input_fn),
            eval_spec=tf.estimator.EvalSpec(input_fn=input_fn)
        )
    

    【讨论】:

      猜你喜欢
      • 2011-11-05
      • 2011-09-30
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 2020-10-27
      • 2018-05-06
      相关资源
      最近更新 更多