Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
bd2b6d7f
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bd2b6d7f
编写于
10月 17, 2018
作者:
Q
Qiao Longfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sum_op support inplace
上级
b4a32eaf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
13 deletion
+36
-13
paddle/fluid/operators/sum_op.h
paddle/fluid/operators/sum_op.h
+22
-5
python/paddle/fluid/tests/unittests/test_sum_op.py
python/paddle/fluid/tests/unittests/test_sum_op.py
+14
-8
未找到文件。
paddle/fluid/operators/sum_op.h
浏览文件 @
bd2b6d7f
...
...
@@ -69,16 +69,33 @@ class SumKernel : public framework::OpKernel<T> {
}
}
}
else
if
(
out_var
->
IsType
<
framework
::
SelectedRows
>
())
{
PADDLE_ENFORCE
(
!
in_place
,
"SelectedRows not support inplace sum now"
);
auto
*
out
=
context
.
Output
<
SelectedRows
>
(
"Out"
)
;
out
->
mutable_rows
()
->
clear
();
if
(
in_place
&&
in_vars
.
size
()
<
2
)
{
return
;
}
std
::
vector
<
const
paddle
::
framework
::
SelectedRows
*>
inputs
;
SelectedRows
temp_in0
;
for
(
auto
&
in_var
:
in_vars
)
{
inputs
.
push_back
(
&
in_var
->
Get
<
SelectedRows
>
());
if
(
in_place
)
{
auto
&
in0
=
in_vars
[
0
]
->
Get
<
SelectedRows
>
();
temp_in0
.
set_height
(
in0
.
height
());
temp_in0
.
set_rows
(
in0
.
rows
());
framework
::
TensorCopy
(
in0
.
value
(),
in0
.
place
(),
context
.
device_context
(),
temp_in0
.
mutable_value
());
inputs
.
push_back
(
&
temp_in0
);
for
(
size_t
i
=
1
;
i
<
in_vars
.
size
();
++
i
)
{
inputs
.
push_back
(
&
in_vars
[
i
]
->
Get
<
SelectedRows
>
());
}
}
else
{
for
(
auto
&
in_var
:
in_vars
)
{
inputs
.
push_back
(
&
in_var
->
Get
<
SelectedRows
>
());
}
}
auto
*
out
=
context
.
Output
<
SelectedRows
>
(
"Out"
);
out
->
mutable_rows
()
->
clear
();
math
::
scatter
::
MergeAdd
<
DeviceContext
,
T
>
merge_add
;
merge_add
(
context
.
template
device_context
<
DeviceContext
>(),
inputs
,
out
);
}
else
if
(
out_var
->
IsType
<
framework
::
LoDTensorArray
>
())
{
...
...
python/paddle/fluid/tests/unittests/test_sum_op.py
浏览文件 @
bd2b6d7f
...
...
@@ -45,17 +45,17 @@ class TestSumOp(OpTest):
class
TestSelectedRowsSumOp
(
OpTest
):
def
check_with_place
(
self
,
place
):
def
check_with_place
(
self
,
place
,
inplace
):
scope
=
core
.
Scope
()
self
.
height
=
10
self
.
row_numel
=
12
self
.
rows
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]
self
.
check_input_and_optput
(
scope
,
place
,
True
,
True
,
True
)
self
.
check_input_and_optput
(
scope
,
place
,
False
,
True
,
True
)
self
.
check_input_and_optput
(
scope
,
place
,
False
,
False
,
True
)
self
.
check_input_and_optput
(
scope
,
place
,
False
,
False
,
False
)
self
.
check_input_and_optput
(
scope
,
place
,
inplace
,
True
,
True
,
True
)
self
.
check_input_and_optput
(
scope
,
place
,
inplace
,
False
,
True
,
True
)
self
.
check_input_and_optput
(
scope
,
place
,
inplace
,
False
,
False
,
True
)
self
.
check_input_and_optput
(
scope
,
place
,
inplace
,
False
,
False
,
False
)
def
_get_array
(
self
,
row_num
,
row_numel
):
array
=
np
.
ones
((
row_num
,
row_numel
)).
astype
(
"float32"
)
...
...
@@ -66,6 +66,7 @@ class TestSelectedRowsSumOp(OpTest):
def
check_input_and_optput
(
self
,
scope
,
place
,
inplace
,
w1_has_data
=
False
,
w2_has_data
=
False
,
w3_has_data
=
False
):
...
...
@@ -75,10 +76,14 @@ class TestSelectedRowsSumOp(OpTest):
self
.
create_selected_rows
(
scope
,
place
,
"W3"
,
w3_has_data
)
# create Out Variable
out
=
scope
.
var
(
'Out'
).
get_selected_rows
()
if
inplace
:
out_var_name
=
"W1"
else
:
out_var_name
=
"Out"
out
=
scope
.
var
(
out_var_name
).
get_selected_rows
()
# create and run sum operator
sum_op
=
Operator
(
"sum"
,
X
=
[
"W1"
,
"W2"
,
"W3"
],
Out
=
'Out'
)
sum_op
=
Operator
(
"sum"
,
X
=
[
"W1"
,
"W2"
,
"W3"
],
Out
=
out_var_name
)
sum_op
.
run
(
scope
,
place
)
has_data_w_num
=
0
...
...
@@ -121,7 +126,8 @@ class TestSelectedRowsSumOp(OpTest):
places
=
[
core
.
CPUPlace
()]
# currently only support CPU
for
place
in
places
:
self
.
check_with_place
(
place
)
for
inplace
in
[
True
,
False
]:
self
.
check_with_place
(
place
,
inplace
)
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录