Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
4dcf43fd
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4dcf43fd
编写于
12月 07, 2018
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine dist train
上级
8c32619e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
11 deletion
+16
-11
fluid/PaddleCV/image_classification/dist_train/dist_train.py
fluid/PaddleCV/image_classification/dist_train/dist_train.py
+16
-11
未找到文件。
fluid/PaddleCV/image_classification/dist_train/dist_train.py
浏览文件 @
4dcf43fd
...
...
@@ -26,6 +26,7 @@ import six
import
sys
sys
.
path
.
append
(
".."
)
import
models
import
utils
from
reader
import
train
,
val
def
parse_args
():
...
...
@@ -149,13 +150,15 @@ def get_model(args, is_train, main_prog, startup_prog):
lr
=
[]
lr
=
[
base_lr
*
(
0.1
**
i
)
for
i
in
range
(
len
(
bd
)
+
1
)]
# NOTE: we put weight decay in layers config, and remove
# weight decay on bn layers, so don't add weight decay in
# optimizer config.
optimizer
=
fluid
.
optimizer
.
Momentum
(
learning_rate
=
mode
ls
.
learning_rate
.
lr_warmup
(
learning_rate
=
uti
ls
.
learning_rate
.
lr_warmup
(
fluid
.
layers
.
piecewise_decay
(
boundaries
=
bd
,
values
=
lr
),
warmup_steps
,
start_lr
,
end_lr
),
momentum
=
0.9
,
regularization
=
fluid
.
regularizer
.
L2Decay
(
1e-4
))
momentum
=
0.9
)
optimizer
.
minimize
(
avg_cost
)
batched_reader
=
None
...
...
@@ -175,6 +178,7 @@ def append_nccl2_prepare(trainer_id, startup_prog):
for
ip
in
worker_ips
.
split
(
","
):
worker_endpoints
.
append
(
':'
.
join
([
ip
,
port
]))
current_endpoint
=
os
.
getenv
(
"PADDLE_CURRENT_IP"
)
+
":"
+
port
num_trainers
=
len
(
worker_endpoints
)
config
=
fluid
.
DistributeTranspilerConfig
()
config
.
mode
=
"nccl2"
...
...
@@ -182,6 +186,7 @@ def append_nccl2_prepare(trainer_id, startup_prog):
t
.
transpile
(
trainer_id
,
trainers
=
','
.
join
(
worker_endpoints
),
current_endpoint
=
current_endpoint
,
startup_program
=
startup_prog
)
return
num_trainers
,
trainer_id
def
dist_transpile
(
trainer_id
,
args
,
train_prog
,
startup_prog
):
...
...
@@ -281,12 +286,12 @@ def test_single(exe, test_args, args, test_prog):
def
train_parallel
(
train_args
,
test_args
,
args
,
train_prog
,
test_prog
,
startup_prog
,
n
ccl_id_var
,
n
um_trainers
,
trainer_id
):
startup_prog
,
num_trainers
,
trainer_id
):
over_all_start
=
time
.
time
()
place
=
core
.
CPUPlace
()
if
args
.
device
==
'CPU'
else
core
.
CUDAPlace
(
0
)
if
nccl_id_var
and
trainer_id
==
0
:
#FIXME(
wuyi
): wait other trainer to start listening
if
args
.
update_method
==
"nccl2"
and
trainer_id
==
0
:
#FIXME(
typhoonzero
): wait other trainer to start listening
time
.
sleep
(
30
)
startup_exe
=
fluid
.
Executor
(
place
)
...
...
@@ -398,8 +403,8 @@ def main():
# the unique trainer id, starting from 0, needed by trainer
# only
n
ccl_id_var
,
n
um_trainers
,
trainer_id
=
(
None
,
1
,
int
(
os
.
getenv
(
"PADDLE_TRAINER_ID"
,
"0"
)))
num_trainers
,
trainer_id
=
(
1
,
int
(
os
.
getenv
(
"PADDLE_TRAINER_ID"
,
"0"
)))
train_prog
=
fluid
.
Program
()
test_prog
=
fluid
.
Program
()
...
...
@@ -418,7 +423,7 @@ def main():
"Must configure correct environments to run dist train."
)
all_args
.
extend
([
train_prog
,
test_prog
,
startup_prog
])
if
os
.
getenv
(
"PADDLE_TRAINING_ROLE"
)
==
"TRAINER"
:
all_args
.
extend
([
n
ccl_id_var
,
n
um_trainers
,
trainer_id
])
all_args
.
extend
([
num_trainers
,
trainer_id
])
train_parallel
(
*
all_args
)
elif
os
.
getenv
(
"PADDLE_TRAINING_ROLE"
)
==
"PSERVER"
:
# start pserver with Executor
...
...
@@ -431,10 +436,10 @@ def main():
all_args
.
extend
([
train_prog
,
test_prog
,
startup_prog
])
if
args
.
update_method
==
"nccl2"
:
n
ccl_id_var
,
n
um_trainers
,
trainer_id
=
append_nccl2_prepare
(
num_trainers
,
trainer_id
=
append_nccl2_prepare
(
trainer_id
,
startup_prog
)
all_args
.
extend
([
n
ccl_id_var
,
n
um_trainers
,
trainer_id
])
all_args
.
extend
([
num_trainers
,
trainer_id
])
train_parallel
(
*
all_args
)
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录