【发布时间】:2019-03-05 12:52:05
【问题描述】:
如何使用带有估计器的参数服务器策略进行分布式训练?如何在不使用 TF_CONFIG for Estimators 的情况下定义 Cluster Spec?
【问题讨论】:
标签: tensorflow tensorflow-serving
如何使用带有估计器的参数服务器策略进行分布式训练?如何在不使用 TF_CONFIG for Estimators 的情况下定义 Cluster Spec?
【问题讨论】:
标签: tensorflow tensorflow-serving
据我了解,使用环境变量,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)
)
【讨论】: