Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
马赛克医院
Paddle
提交
8939f17d
P
Paddle
项目概览
马赛克医院
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8939f17d
编写于
6月 01, 2018
作者:
Y
Yancey1989
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sppedup test_listen_and_serv_op
上级
9503dbb1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
35 deletion
+30
-35
python/paddle/fluid/tests/unittests/CMakeLists.txt
python/paddle/fluid/tests/unittests/CMakeLists.txt
+4
-2
python/paddle/fluid/tests/unittests/test_listen_and_serv_op.py
...n/paddle/fluid/tests/unittests/test_listen_and_serv_op.py
+26
-33
未找到文件。
python/paddle/fluid/tests/unittests/CMakeLists.txt
浏览文件 @
8939f17d
...
...
@@ -48,5 +48,7 @@ foreach(TEST_OP ${TEST_OPS})
endforeach
(
TEST_OP
)
py_test_modules
(
test_warpctc_op MODULES test_warpctc_op ENVS FLAGS_warpctc_dir=
${
WARPCTC_LIB_DIR
}
SERIAL
)
py_test_modules
(
test_dist_train MODULES test_dist_train SERIAL
)
# tests that need to be done in fixed timeout
set_tests_properties
(
test_listen_and_serv_op PROPERTIES TIMEOUT 20
)
# FIXME(Yancey1989): this test would cost much more time on CUDAPlace
# since load cudnn libraries, so we use a longer timeout to make this
# unit test stability.
set_tests_properties
(
test_listen_and_serv_op PROPERTIES TIMEOUT 30
)
python/paddle/fluid/tests/unittests/test_listen_and_serv_op.py
浏览文件 @
8939f17d
...
...
@@ -23,7 +23,7 @@ from multiprocessing import Process
from
op_test
import
OpTest
def
run_pserver
(
use_cuda
,
sync_mode
,
ip
,
port
,
trainer
_count
,
trainer_id
):
def
run_pserver
(
use_cuda
,
sync_mode
,
ip
,
port
,
trainer
s
,
trainer_id
):
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
1
],
dtype
=
'float32'
)
y_predict
=
fluid
.
layers
.
fc
(
input
=
x
,
size
=
1
,
act
=
None
)
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
1
],
dtype
=
'float32'
)
...
...
@@ -39,15 +39,8 @@ def run_pserver(use_cuda, sync_mode, ip, port, trainer_count, trainer_id):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
port
=
os
.
getenv
(
"PADDLE_INIT_PORT"
,
port
)
pserver_ips
=
os
.
getenv
(
"PADDLE_INIT_PSERVERS"
,
ip
)
# ip,ip...
eplist
=
[]
for
ip
in
pserver_ips
.
split
(
","
):
eplist
.
append
(
':'
.
join
([
ip
,
port
]))
pserver_endpoints
=
","
.
join
(
eplist
)
# ip:port,ip:port...
trainers
=
int
(
os
.
getenv
(
"TRAINERS"
,
trainer_count
))
current_endpoint
=
os
.
getenv
(
"POD_IP"
,
ip
)
+
":"
+
port
trainer_id
=
int
(
os
.
getenv
(
"PADDLE_INIT_TRAINER_ID"
,
trainer_id
))
pserver_endpoints
=
ip
+
":"
+
port
current_endpoint
=
ip
+
":"
+
port
t
=
fluid
.
DistributeTranspiler
()
t
.
transpile
(
trainer_id
,
...
...
@@ -62,47 +55,47 @@ def run_pserver(use_cuda, sync_mode, ip, port, trainer_count, trainer_id):
class
TestListenAndServOp
(
OpTest
):
def
setUp
(
self
):
self
.
sleep_time
=
5
self
.
ps_timeout
=
5
self
.
ip
=
"127.0.0.1"
self
.
port
=
"6173"
self
.
trainer
_count
=
1
self
.
trainer
s
=
1
self
.
trainer_id
=
1
def
_raise_signal
(
self
,
parent_pid
,
raised_signal
):
time
.
sleep
(
self
.
sleep_time
)
ps_command
=
subprocess
.
Popen
(
"ps -o pid --ppid %d --noheaders"
%
parent_pid
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
)
ps_output
=
ps_command
.
stdout
.
read
()
retcode
=
ps_command
.
wait
()
assert
retcode
==
0
,
"ps command returned %d"
%
retcode
for
pid_str
in
ps_output
.
split
(
"
\n
"
)[:
-
1
]:
try
:
os
.
kill
(
int
(
pid_str
),
raised_signal
)
except
Exception
:
continue
def
_start_pserver
(
self
,
use_cuda
,
sync_mode
):
p
=
Process
(
target
=
run_pserver
,
args
=
(
use_cuda
,
sync_mode
,
self
.
ip
,
self
.
port
,
self
.
trainer
_count
,
args
=
(
use_cuda
,
sync_mode
,
self
.
ip
,
self
.
port
,
self
.
trainer
s
,
self
.
trainer_id
))
p
.
start
()
return
p
.
pid
def
_wait_ps_ready
(
self
,
pid
):
retry_times
=
self
.
ps_timeout
while
True
:
time
.
sleep
(
1
)
assert
retry_times
>=
0
,
"wait ps ready failed"
try
:
# the listen_and_serv_op would touch a file which contains the listen port
# on the /tmp directory until it was ready to process all the RPC call.
os
.
stat
(
"/tmp/paddle.%d.port"
%
pid
)
return
except
os
.
error
:
retry_times
-=
1
def
test_handle_signal_in_serv_op
(
self
):
# run pserver on CPU in sync mode
self
.
_start_pserver
(
False
,
True
)
pid
=
self
.
_start_pserver
(
False
,
True
)
self
.
_wait_ps_ready
(
pid
)
# raise SIGINT to pserver
self
.
_raise_signal
(
os
.
getpid
()
,
signal
.
SIGINT
)
os
.
kill
(
pid
,
signal
.
SIGINT
)
# run pserver on CPU in async mode
self
.
_start_pserver
(
False
,
False
)
pid
=
self
.
_start_pserver
(
False
,
False
)
self
.
_wait_ps_ready
(
pid
)
# raise SIGTERM to pserver
self
.
_raise_signal
(
os
.
getpid
(),
signal
.
SIGTERM
)
os
.
kill
(
pid
,
signal
.
SIGINT
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录