Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
2412f2f4
P
Paddle
项目概览
BaiXuePrincess
/
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看板
提交
2412f2f4
编写于
1月 10, 2018
作者:
Y
Yang Yu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish Unittest for ParallelFor
上级
52ed1038
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
44 addition
and
6 deletion
+44
-6
python/paddle/v2/fluid/tests/test_parallel_op.py
python/paddle/v2/fluid/tests/test_parallel_op.py
+44
-6
未找到文件。
python/paddle/v2/fluid/tests/test_parallel_op.py
浏览文件 @
2412f2f4
...
...
@@ -12,9 +12,34 @@ class BaseParallelForTest(unittest.TestCase):
fetch
=
fetch
,
place
=
cpu
,
use_parallel
=
False
)
print
result_cpu
result_cpu_parallel
=
self
.
_main_impl_
(
callback
=
callback
,
feed
=
feed
,
fetch
=
fetch
,
place
=
cpu
,
use_parallel
=
True
)
if
fluid
.
core
.
is_compile_gpu
():
gpu
=
fluid
.
CUDAPlace
(
0
)
result_gpu
=
self
.
_main_impl_
(
callback
=
callback
,
feed
=
feed
,
fetch
=
fetch
,
place
=
gpu
,
use_parallel
=
False
)
result_gpu_parallel
=
self
.
_main_impl_
(
callback
=
callback
,
feed
=
feed
,
fetch
=
fetch
,
place
=
gpu
,
use_parallel
=
True
)
self
.
_assert_same_
(
fetch
,
result_cpu
,
result_cpu_parallel
,
result_gpu
,
result_gpu_parallel
)
else
:
self
.
_assert_same_
(
fetch
,
result_cpu
,
result_cpu_parallel
)
def
_main_impl_
(
self
,
callback
,
feed
,
fetch
,
place
,
use_parallel
=
False
):
if
isinstance
(
fetch
,
basestring
):
fetch
=
[
fetch
]
main
=
fluid
.
Program
()
startup
=
fluid
.
Program
()
# Fix seed
...
...
@@ -31,20 +56,19 @@ class BaseParallelForTest(unittest.TestCase):
if
isinstance
(
data
,
fluid
.
Variable
):
data
=
[
data
]
with
pd
.
do
():
ins
=
map
(
pd
.
read_input
,
data
)
if
len
(
ins
)
==
1
:
ins
=
ins
[
0
]
generator
.
send
(
ins
)
# patch input
loss
=
next
(
generator
)
loss
=
generator
.
send
(
ins
)
# patch input
pd
.
write_output
(
loss
)
loss
=
pd
()
else
:
data
=
next
(
generator
)
generator
.
send
(
data
)
loss
=
next
(
generator
)
loss
=
generator
.
send
(
data
)
self
.
assertIsNotNone
(
loss
)
avg_loss
=
fluid
.
layers
.
mean
(
x
=
loss
)
fluid
.
backward
.
append_backward
(
loss
=
avg_loss
)
...
...
@@ -52,11 +76,25 @@ class BaseParallelForTest(unittest.TestCase):
exe
.
run
(
startup
)
return
exe
.
run
(
main
,
feed
=
feed
,
fetch_list
=
fetch
)
def
_assert_same_
(
self
,
fetch
,
*
args
):
def
_impl_
(
a
,
b
,
fetch_id
,
item_id
):
item_str
=
[
'CPU'
,
'ParallelCPU'
,
'GPU'
,
'ParallelGPU'
]
flag
=
numpy
.
allclose
(
a
,
b
,
rtol
=
0.1
)
self
.
assertTrue
(
flag
,
"The {0} are different in {1}"
.
format
(
fetch
[
fetch_id
],
item_str
[
item_id
]))
for
i
,
items
in
enumerate
(
zip
(
*
args
)):
self
.
assertGreater
(
len
(
items
),
0
)
for
j
in
range
(
1
,
len
(
items
)):
_impl_
(
items
[
0
],
items
[
j
],
fetch_id
=
i
,
item_id
=
j
)
class
ParallelOpTest
(
BaseParallelForTest
):
def
test_simple_fc
(
self
):
def
__network__
():
x
=
fluid
.
layers
.
data
(
shape
=
[
784
],
dtype
=
'float32'
,
name
=
'img'
)
# FIXME: This is a bug of parallel.do
x
.
stop_gradient
=
False
x
=
yield
x
hidden
=
fluid
.
layers
.
fc
(
input
=
x
,
size
=
200
,
param_attr
=
'fc1.w'
)
loss
=
fluid
.
layers
.
mean
(
x
=
hidden
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录