Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
989e8358
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看板
提交
989e8358
编写于
9月 14, 2017
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reuse the output of mul when there is only one input in FCOp.
上级
fe2ab2ee
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
25 addition
and
28 deletion
+25
-28
paddle/operators/fc_op.cc
paddle/operators/fc_op.cc
+13
-10
python/paddle/v2/framework/tests/op_test.py
python/paddle/v2/framework/tests/op_test.py
+8
-6
python/paddle/v2/framework/tests/test_fc_op.py
python/paddle/v2/framework/tests/test_fc_op.py
+4
-12
未找到文件。
paddle/operators/fc_op.cc
浏览文件 @
989e8358
...
...
@@ -66,22 +66,25 @@ class FCOp : public NetOp {
}
// sum_out = X[0] * W[0] + ... + X[n-1] * W[n-1]
auto
sum_out
=
mul_out
[
0
];
if
(
n
>
1
)
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"sum"
,
{{
"X"
,
{
mul_out
}}},
{{
"Out"
,
{
Output
(
"SumOut"
)}}},
{}));
sum_out
=
Output
(
"SumOut"
);
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"sum"
,
{{
"X"
,
{
mul_out
}}},
{{
"Out"
,
{
sum_out
}}},
{}));
}
else
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"identity"
,
{{
"X"
,
{
mul_out
[
0
]}}},
{{
"Y"
,
{
Output
(
"SumOut"
)}}},
{}));
if
(
Output
(
"SumOut"
)
!=
framework
::
kEmptyVarName
)
{
this
->
Rename
(
Output
(
"SumOut"
),
framework
::
kEmptyVarName
);
}
}
// add_out = sum_out + b
auto
b
=
Input
(
"B"
);
std
::
string
add_out
=
"SumOut"
;
auto
add_out
=
sum_out
;
if
(
b
!=
framework
::
kEmptyVarName
)
{
add_out
=
"AddOut"
;
add_out
=
Output
(
"AddOut"
)
;
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"rowwise_add"
,
{{
"X"
,
{
Output
(
"SumOut"
)
}},
{
"b"
,
{
Input
(
"B"
)}}},
{{
"Out"
,
{
Output
(
add_out
)
}}},
{}));
"rowwise_add"
,
{{
"X"
,
{
sum_out
}},
{
"b"
,
{
Input
(
"B"
)}}},
{{
"Out"
,
{
add_out
}}},
{}));
}
else
{
if
(
Output
(
"AddOut"
)
!=
framework
::
kEmptyVarName
)
{
this
->
Rename
(
Output
(
"AddOut"
),
framework
::
kEmptyVarName
);
...
...
@@ -89,8 +92,8 @@ class FCOp : public NetOp {
}
auto
activation
=
Attr
<
std
::
string
>
(
"activation"
);
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
activation
,
{{
"X"
,
{
Output
(
add_out
)}}},
{{
"Y"
,
{
Output
(
"Out"
)}}},
{}));
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
activation
,
{{
"X"
,
{
add_out
}}},
{{
"Y"
,
{
Output
(
"Out"
)}}},
{}));
CompleteAddOp
(
false
);
}
};
...
...
python/paddle/v2/framework/tests/op_test.py
浏览文件 @
989e8358
...
...
@@ -193,7 +193,9 @@ class OpTest(unittest.TestCase):
actual
,
expect
,
atol
=
1e-05
),
"output name: "
+
out_name
+
" has diff"
)
else
:
actual
=
np
.
array
(
self
.
scope
.
find_var
(
out_name
).
get_tensor
())
var
=
self
.
scope
.
find_var
(
out_name
)
if
var
is
not
None
:
actual
=
np
.
array
(
var
.
get_tensor
())
expect
=
self
.
outputs
[
out_name
]
self
.
assertTrue
(
np
.
allclose
(
...
...
python/paddle/v2/framework/tests/test_fc_op.py
浏览文件 @
989e8358
...
...
@@ -7,27 +7,19 @@ class TestFCOp1(OpTest):
def
setUp
(
self
):
x0
=
np
.
random
.
random
((
16
,
32
)).
astype
(
"float32"
)
w0
=
np
.
random
.
random
((
32
,
10
)).
astype
(
"float32"
)
b
=
np
.
random
.
random
(
10
).
astype
(
"float32"
)
mul_out0
=
np
.
dot
(
x0
,
w0
)
sum_out
=
mul_out0
add_out
=
sum_out
+
b
identity_out
=
add_out
identity_out
=
mul_out0
self
.
op_type
=
"fc"
self
.
inputs
=
{
"X"
:
[(
"X0"
,
x0
)],
"W"
:
[(
"W0"
,
w0
)],
"B"
:
b
}
self
.
outputs
=
{
"MulOut"
:
[(
"MulOut0"
,
mul_out0
)],
"SumOut"
:
sum_out
,
"AddOut"
:
add_out
,
"Out"
:
identity_out
}
self
.
inputs
=
{
"X"
:
[(
"X0"
,
x0
)],
"W"
:
[(
"W0"
,
w0
)]}
self
.
outputs
=
{
"MulOut"
:
[(
"MulOut0"
,
mul_out0
)],
"Out"
:
identity_out
}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
"X0"
,
"W0"
,
"B"
],
"Out"
,
max_relative_error
=
0.01
)
self
.
check_grad
([
"X0"
,
"W0"
],
"Out"
,
max_relative_error
=
0.01
)
class
TestFCOp2
(
OpTest
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录