Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0941e3e0
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0941e3e0
编写于
6月 16, 2019
作者:
G
guru4elephant
提交者:
GitHub
6月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add class name and timeline for test_dist_base.py (#18122)
* add class name and timeline for test_dist_base.py
上级
90897741
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
43 addition
and
28 deletion
+43
-28
python/paddle/fluid/tests/unittests/test_dist_base.py
python/paddle/fluid/tests/unittests/test_dist_base.py
+43
-28
未找到文件。
python/paddle/fluid/tests/unittests/test_dist_base.py
浏览文件 @
0941e3e0
...
...
@@ -24,7 +24,7 @@ import six
import
argparse
import
pickle
import
numpy
as
np
import
time
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
import
paddle.fluid.dygraph
as
dygraph
...
...
@@ -35,11 +35,13 @@ RUN_STEP = 5
DEFAULT_BATCH_SIZE
=
2
def
my_print
(
log_str
):
def
my_print
(
class_name
,
log_str
):
localtime
=
time
.
asctime
(
time
.
localtime
(
time
.
time
()))
print_str
=
localtime
+
"
\t
"
+
class_name
+
"
\t
"
+
log_str
if
six
.
PY2
:
sys
.
stderr
.
write
(
pickle
.
dumps
(
log
_str
))
sys
.
stderr
.
write
(
pickle
.
dumps
(
print
_str
))
else
:
sys
.
stderr
.
buffer
.
write
(
pickle
.
dumps
(
log
_str
))
sys
.
stderr
.
buffer
.
write
(
pickle
.
dumps
(
print
_str
))
class
TestDistRunnerBase
(
object
):
...
...
@@ -90,9 +92,9 @@ class TestDistRunnerBase(object):
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
startup_prog
)
my_print
(
"run pserver startup program done."
)
my_print
(
type
(
self
).
__name__
,
"run pserver startup program done."
)
exe
.
run
(
pserver_prog
)
my_print
(
"run pserver main program done."
)
my_print
(
type
(
self
).
__name__
,
"run pserver main program done."
)
def
run_trainer
(
self
,
args
):
self
.
lr
=
args
.
lr
...
...
@@ -107,23 +109,29 @@ class TestDistRunnerBase(object):
self
.
get_model
(
batch_size
=
args
.
batch_size
)
if
args
.
mem_opt
:
my_print
(
"begin to run memory optimize"
)
my_print
(
type
(
self
).
__name__
,
"begin to run memory optimize"
)
fluid
.
memory_optimize
(
fluid
.
default_main_program
(),
skip_grads
=
True
)
my_print
(
"trainer run memory optimize done."
)
my_print
(
type
(
self
).
__name__
,
"trainer run memory optimize done."
)
if
args
.
update_method
==
"pserver"
:
my_print
(
"begin to run transpile on trainer with pserver mode"
)
my_print
(
type
(
self
).
__name__
,
"begin to run transpile on trainer with pserver mode"
)
t
=
self
.
get_transpiler
(
args
.
trainer_id
,
fluid
.
default_main_program
(),
args
.
endpoints
,
args
.
trainers
,
args
.
sync_mode
,
args
.
dc_asgd
)
trainer_prog
=
t
.
get_trainer_program
()
my_print
(
"get trainer program done with pserver mode."
)
my_print
(
type
(
self
).
__name__
,
"get trainer program done with pserver mode."
)
elif
args
.
update_method
==
"nccl2"
or
args
.
update_method
==
"nccl2_reduce_layer"
:
# transpile for nccl2
config
=
fluid
.
DistributeTranspilerConfig
()
config
.
mode
=
"nccl2"
config
.
nccl_comm_num
=
args
.
nccl_comm_num
my_print
(
"begin to run transpile on trainer with nccl2 mode"
)
my_print
(
type
(
self
).
__name__
,
"begin to run transpile on trainer with nccl2 mode"
)
nccl2_t
=
fluid
.
DistributeTranspiler
(
config
=
config
)
nccl2_t
.
transpile
(
args
.
trainer_id
,
...
...
@@ -131,7 +139,9 @@ class TestDistRunnerBase(object):
startup_program
=
fluid
.
default_startup_program
(),
trainers
=
args
.
endpoints
,
current_endpoint
=
args
.
current_endpoint
)
my_print
(
"get trainer program done. with nccl2 mode"
)
my_print
(
type
(
self
).
__name__
,
"get trainer program done. with nccl2 mode"
)
trainer_prog
=
fluid
.
default_main_program
()
else
:
trainer_prog
=
fluid
.
default_main_program
()
...
...
@@ -144,7 +154,7 @@ class TestDistRunnerBase(object):
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
my_print
(
"run worker startup program done."
)
my_print
(
type
(
self
).
__name__
,
"run worker startup program done."
)
exec_strategy
=
fluid
.
ExecutionStrategy
()
exec_strategy
.
num_threads
=
1
...
...
@@ -177,12 +187,12 @@ class TestDistRunnerBase(object):
build_stra
.
num_trainers
=
1
build_stra
.
trainer_id
=
0
my_print
(
"begin to compile with data parallel"
)
my_print
(
type
(
self
).
__name__
,
"begin to compile with data parallel"
)
binary
=
compiler
.
CompiledProgram
(
trainer_prog
).
with_data_parallel
(
loss_name
=
avg_cost
.
name
,
build_strategy
=
build_stra
,
exec_strategy
=
exec_strategy
)
my_print
(
"program compiled with data parallel"
)
my_print
(
type
(
self
).
__name__
,
"program compiled with data parallel"
)
if
args
.
use_cuda
and
args
.
update_method
==
"nccl2"
:
# it just for test share_vars_from feature.
...
...
@@ -212,7 +222,7 @@ class TestDistRunnerBase(object):
else
:
return
origin_batch
my_print
(
"begin to train on trainer"
)
my_print
(
type
(
self
).
__name__
,
"begin to train on trainer"
)
out_losses
=
[]
for
_
in
six
.
moves
.
xrange
(
RUN_STEP
):
loss
,
=
exe
.
run
(
binary
,
...
...
@@ -265,19 +275,23 @@ class TestParallelDyGraphRunnerBase(object):
strategy
.
local_rank
=
args
.
trainer_id
strategy
.
trainer_endpoints
=
args
.
endpoints
.
split
(
","
)
strategy
.
current_endpoint
=
args
.
current_endpoint
my_print
(
"begin to prepare context in dygraph with nccl2"
)
my_print
(
type
(
self
).
__name__
,
"begin to prepare context in dygraph with nccl2"
)
dygraph
.
parallel
.
prepare_context
(
strategy
)
model
=
dygraph
.
parallel
.
DataParallel
(
model
,
strategy
)
my_print
(
"model built in dygraph"
)
my_print
(
type
(
self
).
__name__
,
"model built in dygraph"
)
out_losses
=
[]
my_print
(
"begin to run dygraph training"
)
my_print
(
type
(
self
).
__name__
,
"begin to run dygraph training"
)
for
step_id
,
data
in
enumerate
(
train_reader
()):
data
=
_get_data
(
data
)
if
step_id
==
RUN_STEP
:
break
loss
=
self
.
run_one_loop
(
model
,
opt
,
data
)
if
step_id
%
10
==
0
:
my_print
(
"loss at step %d: %f"
%
(
step_id
,
loss
))
my_print
(
type
(
self
).
__name__
,
"loss at step %d: %f"
%
(
step_id
,
loss
))
out_losses
.
append
(
loss
.
numpy
())
# FIXME(Yancey1989): scale the loss inplace
...
...
@@ -290,7 +304,7 @@ class TestParallelDyGraphRunnerBase(object):
opt
.
minimize
(
loss
)
model
.
clear_gradients
()
my_print
(
pickle
.
dumps
(
out_losses
))
my_print
(
type
(
self
).
__name__
,
pickle
.
dumps
(
out_losses
))
def
runtime_main
(
test_class
):
...
...
@@ -395,7 +409,8 @@ class TestDistBase(unittest.TestCase):
with
closing
(
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
))
as
s
:
s
.
bind
((
''
,
0
))
my_print
(
"socket name: %s"
%
s
.
getsockname
()[
1
])
my_print
(
type
(
self
).
__name__
,
"socket name: %s"
%
s
.
getsockname
()[
1
])
return
s
.
getsockname
()[
1
]
while
True
:
...
...
@@ -426,13 +441,13 @@ class TestDistBase(unittest.TestCase):
ps0_pipe
=
open
(
"/tmp/ps0_err.log"
,
"wb"
)
ps1_pipe
=
open
(
"/tmp/ps1_err.log"
,
"wb"
)
my_print
(
"going to start pserver process 0"
)
my_print
(
type
(
self
).
__name__
,
"going to start pserver process 0"
)
ps0_proc
=
subprocess
.
Popen
(
ps0_cmd
.
strip
().
split
(
" "
),
stdout
=
subprocess
.
PIPE
,
stderr
=
ps0_pipe
,
env
=
required_envs
)
my_print
(
"going to start pserver process 1"
)
my_print
(
type
(
self
).
__name__
,
"going to start pserver process 1"
)
ps1_proc
=
subprocess
.
Popen
(
ps1_cmd
.
strip
().
split
(
" "
),
stdout
=
subprocess
.
PIPE
,
...
...
@@ -538,13 +553,13 @@ class TestDistBase(unittest.TestCase):
tr0_pipe
=
open
(
"/tmp/tr0_err.log"
,
"wb"
)
tr1_pipe
=
open
(
"/tmp/tr1_err.log"
,
"wb"
)
my_print
(
"going to start trainer process 0"
)
my_print
(
type
(
self
).
__name__
,
"going to start trainer process 0"
)
tr0_proc
=
subprocess
.
Popen
(
tr0_cmd
.
strip
().
split
(
" "
),
stdout
=
subprocess
.
PIPE
,
stderr
=
tr0_pipe
,
env
=
env0
)
my_print
(
"going to start trainer process 1"
)
my_print
(
type
(
self
).
__name__
,
"going to start trainer process 1"
)
tr1_proc
=
subprocess
.
Popen
(
tr1_cmd
.
strip
().
split
(
" "
),
stdout
=
subprocess
.
PIPE
,
...
...
@@ -662,13 +677,13 @@ class TestDistBase(unittest.TestCase):
tr0_pipe
=
open
(
"/tmp/tr0_err.log"
,
"wb"
)
tr1_pipe
=
open
(
"/tmp/tr1_err.log"
,
"wb"
)
my_print
(
"going to start process 0 with nccl2"
)
my_print
(
type
(
self
).
__name__
,
"going to start process 0 with nccl2"
)
tr0_proc
=
subprocess
.
Popen
(
tr0_cmd
.
strip
().
split
(
" "
),
stdout
=
subprocess
.
PIPE
,
stderr
=
tr0_pipe
,
env
=
env0
)
my_print
(
"going to start process 1 with nccl2"
)
my_print
(
type
(
self
).
__name__
,
"going to start process 1 with nccl2"
)
tr1_proc
=
subprocess
.
Popen
(
tr1_cmd
.
strip
().
split
(
" "
),
stdout
=
subprocess
.
PIPE
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录