Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
FluidDoc
提交
be6cf7ed
F
FluidDoc
项目概览
PaddlePaddle
/
FluidDoc
通知
5
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
23
列表
看板
标记
里程碑
合并请求
111
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
FluidDoc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
23
Issue
23
列表
看板
标记
里程碑
合并请求
111
合并请求
111
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
be6cf7ed
编写于
7月 26, 2019
作者:
D
Dong Daxiang
提交者:
GitHub
7月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update cluster_quick_start.rst
上级
fb6d1b5c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
74 addition
and
94 deletion
+74
-94
doc/fluid/user_guides/howto/training/cluster_quick_start.rst
doc/fluid/user_guides/howto/training/cluster_quick_start.rst
+74
-94
未找到文件。
doc/fluid/user_guides/howto/training/cluster_quick_start.rst
浏览文件 @
be6cf7ed
...
@@ -7,120 +7,100 @@
...
@@ -7,120 +7,100 @@
为了让读者快速上手,我们采用点击率预估任务作为示例,相关的源码可以参考 xxxx
为了让读者快速上手,我们采用点击率预估任务作为示例,相关的源码可以参考 xxxx
单机训练代码
为了方便学习,这里给出的示例是单机与多机混合的代码,用户可以通过不同的启动命令进行单机或多机任务的启动。
.. code:: python
.. code:: python
def train():
from __future__ import print_function
args = parse_args()
if not os.path.isdir(args.model_output_dir):
os.mkdir(args.model_output_dir)
dense_input = fluid.layers.data(
name="dense_input", shape=[dense_feature_dim], dtype='float32')
sparse_input_ids = [
fluid.layers.data(name="C" + str(i), shape=[1], lod_level=1, dtype="int64")
for i in range(1, 27)]
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
loss, auc_var, batch_auc_var = ctr_dnn_model_dataset(dense_input, sparse_input_ids, label,
args.embedding_size, args.sparse_feature_dim)
optimizer = fluid.optimizer.SGD(learning_rate=1e-4)
optimizer.minimize(loss)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
dataset = fluid.DatasetFactory().create_dataset()
dataset.set_use_var([dense_input] + sparse_input_ids + [label])
pipe_command = "python criteo_reader.py %d" % args.sparse_feature_dim
dataset.set_pipe_command(pipe_command)
dataset.set_batch_size(100)
thread_num = 10
dataset.set_thread(thread_num)
whole_filelist = ["raw_data/part-%d" % x for x in range(len(os.listdir("raw_data")))]
epochs = 20
for i in range(epochs):
dataset.set_filelist(whole_filelist[:int(0.8*len(whole_filelist))])
exe.train_from_dataset(program=fluid.default_main_program(),
dataset=dataset,
fetch_list=[auc_var],
fetch_info=["auc"],
debug=False)
model_dir = args.model_output_dir + '/epoch' + str(i + 1) + ".model"
sys.stderr.write("epoch%d finished" % (i + 1))
fluid.io.save_inference_model(model_dir, [dense_input.name] + [x.name for x in sparse_input_ids] + [label.name], [loss, auc_var], exe)
使用FleetAPI进行训练的代码
.. code:: python
from args import parse_args
import os
import paddle.fluid as fluid
import sys
from network_conf import ctr_dnn_model_dataset
import paddle.fluid.incubate.fleet.base.role_maker as role_maker
import paddle.fluid.incubate.fleet.base.role_maker as role_maker
from paddle.fluid.incubate.fleet.parameter_server.distribute_transpiler import fleet
from paddle.fluid.incubate.fleet.parameter_server.distribute_transpiler import fleet
from paddle.fluid.transpiler.distribute_transpiler import DistributeTranspilerConfig
def train():
dense_feature_dim = 13
args = parse_args()
sparse_feature_dim = 10000001
if not os.path.isdir(args.model_output_dir):
batch_size = 100
os.mkdir(args.model_output_dir)
thread_num = 10
embedding_size = 10
args = parse_args()
def main_function(is_local):
dense_input = fluid.layers.data(
dense_input = fluid.layers.data(
name="dense_input", shape=[dense_feature_dim], dtype='float32')
name="dense_input", shape=[dense_feature_dim], dtype='float32')
sparse_input_ids = [
sparse_input_ids = [
fluid.layers.data(name="C" + str(i), shape=[1], lod_level=1, dtype="int64")
fluid.layers.data(name="C" + str(i), shape=[1], lod_level=1,
for i in range(1, 27)]
dtype="int64")
for i in range(1, 27)]
label = fluid.layers.data(name=
'label', shape=[1], dtype='int64'
)
label = fluid.layers.data(name=
"label", shape=[1], dtype="int64"
)
loss, auc_var, batch_auc_var = ctr_dnn_model_dataset(dense_input, sparse_input_ids, label,
dataset = fluid.DatasetFactory().create_dataset()
args.embedding_size, args.sparse_feature_dim)
dataset.set_use_var([dense_input] + sparse_input_ids + [label])
pipe_command = "python criteo_reader.py %d" % sparse_feature_dim
dataset.set_pipe_command(pipe_command)
dataset.set_batch_size(batch_size)
dataset.set_thread(thread_num)
whole_filelist = ["raw_data/part-%d" % x
for x in range(len(os.listdir("raw_data")))]
dataset.set_filelist(whole_filelist)
loss, auc_var, batch_auc_var = ctr_dnn_model_dataset(
dense_input, sparse_input_ids, label, embedding_size,
sparse_feature_dim)
role = role_maker.PaddleCloudRoleMaker()
exe = fluid.Executor(fluid.CPUPlace())
exe = fluid.Executor(fluid.CPUPlace())
fleet.init(role)
def train_loop(epoch=20):
optimizer = fluid.optimizer.SGD(learning_rate=1e-4)
for i in range(epoch):
strategy = DistributeTranspilerConfig()
strategy.sync_mode = False
optimizer = fleet.distributed_optimizer(optimizer, strategy)
optimizer.minimize(loss)
if fleet.is_server():
fleet.init_server()
fleet.run_server()
elif fleet.is_worker():
fleet.init_worker()
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
dataset = fluid.DatasetFactory().create_dataset()
dataset.set_use_var([dense_input] + sparse_input_ids + [label])
pipe_command = "python criteo_reader.py %d" % args.sparse_feature_dim
dataset.set_pipe_command(pipe_command)
dataset.set_batch_size(100)
thread_num = 10
dataset.set_thread(thread_num)
whole_filelist = ["raw_data/part-%d" % x for x in range(len(os.listdir("raw_data")))]
epochs = 20
for i in range(epochs):
dataset.set_filelist(whole_filelist[:int(0.8*len(whole_filelist))])
exe.train_from_dataset(program=fluid.default_main_program(),
exe.train_from_dataset(program=fluid.default_main_program(),
dataset=dataset,
dataset=dataset,
fetch_list=[auc_var],
fetch_list=[auc_var],
fetch_info=["auc"],
fetch_info=["auc"],
debug=False)
debug=False)
if fleet.worker_index() == 0:
model_dir = args.model_output_dir + '/epoch' + str(i + 1) + ".model"
sys.stderr.write("epoch%d finished" % (i + 1))
fluid.io.save_inference_model(model_dir,
[dense_input.name] + [x.name for x in sparse_input_ids] + [label.name], [loss, auc_var], exe)
启动命令
def local_train(optimizer):
optimizer = fluid.optimizer.SGD(learning_rate=1e-4)
optimizer.minimize(loss)
exe.run(fluid.default_startup_program())
train_loop()
def dist_train(optimizer):
role = role_maker.PaddleCloudRoleMaker()
fleet.init(role)
strategy = DistributeTranspilerConfig()
strategy.sync_mode = False
optimizer = fluid.optimizer.SGD(learning_rate=1e-4)
optimizer = fleet.distributed_optimizer(optimizer, strategy)
optimizer.minimize(loss)
if fleet.is_server():
fleet.init_server()
fleet.run_server()
elif fleet.is_worker():
fleet.init_worker()
exe.run(fluid.default_startup_program())
train_loop()
if is_local:
local_train(optimizer)
else:
dist_train(optimizer)
if __name__ == '__main__':
main_function(args.is_local)
单机训练启动命令
.. code:: python
python train.py --is_local 1
在单机模拟多机训练的启动命令,这里我们用到了paddle内置的一个启动器launch_ps,用户可以指定worker和server的数量进行参数服务器任务的启动
.. code:: python
.. code:: python
python -m paddle.distributed.launch_ps --worker_num 2 --server_num 2
dist_
train.py
python -m paddle.distributed.launch_ps --worker_num 2 --server_num 2 train.py
运行日志
运行日志
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录