Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
ce723af0
P
Paddle
项目概览
机器未来
/
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看板
提交
ce723af0
编写于
8月 22, 2017
作者:
Y
Yu Yang
提交者:
GitHub
8月 22, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3585 from reyoung/feature/rename_to_append_op
Rename `Net::AddOp` to `Net::AppendOp`
上级
7443b2e4
f1e55335
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
37 addition
and
35 deletion
+37
-35
paddle/framework/backward.cc
paddle/framework/backward.cc
+5
-4
paddle/framework/backward_test.cc
paddle/framework/backward_test.cc
+15
-15
paddle/framework/pybind.cc
paddle/framework/pybind.cc
+2
-2
paddle/operators/net_op.h
paddle/operators/net_op.h
+4
-3
paddle/operators/net_op_test.cc
paddle/operators/net_op_test.cc
+5
-5
python/paddle/v2/framework/tests/test_net.py
python/paddle/v2/framework/tests/test_net.py
+5
-5
python/paddle/v2/framework/tests/test_recurrent_op.py
python/paddle/v2/framework/tests/test_recurrent_op.py
+1
-1
未找到文件。
paddle/framework/backward.cc
浏览文件 @
ce723af0
...
...
@@ -110,7 +110,7 @@ static std::unique_ptr<OperatorBase> BackwardRecursive(
dup_output_ops
[
out
].
emplace_back
(
local_op_id
);
return
false
;
});
net
->
A
d
dOp
(
std
::
move
(
bwd
));
net
->
A
ppen
dOp
(
std
::
move
(
bwd
));
}
// Get unique ID for this method.
auto
uid
=
uniq_id
++
;
...
...
@@ -163,8 +163,9 @@ static std::unique_ptr<OperatorBase> BackwardRecursive(
// If part of input gradient of that operator is not calculated, fill
// zero variables to that input gradient.
net
->
AddOp
(
OpRegistry
::
CreateOp
(
"fill_zeros_like"
,
{{
"Src"
,
{
prefix
}}},
{{
"Dst"
,
{
grad_input
}}},
{}));
net
->
AppendOp
(
OpRegistry
::
CreateOp
(
"fill_zeros_like"
,
{{
"Src"
,
{
prefix
}}},
{{
"Dst"
,
{
grad_input
}}},
{}));
}
return
false
;
});
...
...
@@ -195,7 +196,7 @@ static std::unique_ptr<OperatorBase> BackwardRecursive(
if
(
net
->
ops_
.
empty
())
{
// Current no aux op is added to network
return
grad_op
;
}
net
->
A
d
dOp
(
std
::
move
(
grad_op
));
net
->
A
ppen
dOp
(
std
::
move
(
grad_op
));
}
net
->
SetType
(
"@GENERATED_BACKWARD@"
);
net
->
CompleteAddOp
();
...
...
paddle/framework/backward_test.cc
浏览文件 @
ce723af0
...
...
@@ -75,13 +75,13 @@ class FcOp : public operators::NetOp {
FcOp
(
const
std
::
string
&
type
,
const
VarNameMap
&
inputs
,
const
VarNameMap
&
outputs
,
const
AttributeMap
&
attrs
)
:
NetOp
(
type
,
inputs
,
outputs
,
attrs
)
{
A
d
dOp
(
OpRegistry
::
CreateOp
(
"mul"
,
{{
"X"
,
{
Input
(
"X"
)}},
{
"Y"
,
{
Input
(
"W"
)}}},
{{
"Out"
,
{
Output
(
"mul_result"
)}}},
{}));
A
ppen
dOp
(
OpRegistry
::
CreateOp
(
"mul"
,
{{
"X"
,
{
Input
(
"X"
)}},
{
"Y"
,
{
Input
(
"W"
)}}},
{{
"Out"
,
{
Output
(
"mul_result"
)}}},
{}));
auto
input_b
=
Inputs
(
"b"
);
std
::
string
before_act
=
"mul_result"
;
if
(
input_b
.
size
()
!=
0
)
{
A
d
dOp
(
OpRegistry
::
CreateOp
(
A
ppen
dOp
(
OpRegistry
::
CreateOp
(
"rowwise_add"
,
{{
"X"
,
{
Output
(
"mul_result"
)}},
{
"b"
,
{
input_b
[
0
]}}},
{{
"Out"
,
{
Output
(
"add_result"
)}}},
{}));
before_act
=
"add_result"
;
...
...
@@ -92,8 +92,8 @@ class FcOp : public operators::NetOp {
}
}
A
d
dOp
(
OpRegistry
::
CreateOp
(
"sigmoid"
,
{{
"X"
,
{
Output
(
before_act
)}}},
{{
"Out"
,
{
Output
(
"Out"
)}}},
{}));
A
ppen
dOp
(
OpRegistry
::
CreateOp
(
"sigmoid"
,
{{
"X"
,
{
Output
(
before_act
)}}},
{{
"Out"
,
{
Output
(
"Out"
)}}},
{}));
CompleteAddOp
(
false
);
}
};
...
...
@@ -234,13 +234,13 @@ TEST(Backward, net_fc_backward_not_have_b) {
TEST
(
Backward
,
net_input_of_network_not_need_grad
)
{
ops
::
NetOp
net
;
net
.
A
d
dOp
(
f
::
OpRegistry
::
CreateOp
(
net
.
A
ppen
dOp
(
f
::
OpRegistry
::
CreateOp
(
"fc"
,
{{
"X"
,
{
"x"
}},
{
"W"
,
{
"W1"
}},
{
"b"
,
{
"b1"
}}},
{{
"mul_result"
,
{
"mul_tmp_0"
}},
{
"add_result"
,
{
"add_tmp_0"
}},
{
"Out"
,
{
"hidden0"
}}},
{}));
net
.
A
d
dOp
(
f
::
OpRegistry
::
CreateOp
(
net
.
A
ppen
dOp
(
f
::
OpRegistry
::
CreateOp
(
"fc"
,
{{
"X"
,
{
"hidden0"
}},
{
"W"
,
{
"W2"
}},
{
"b"
,
{
"b2"
}}},
{{
"mul_result"
,
{
"mul_tmp_1"
}},
{
"add_result"
,
{
"add_tmp_1"
}},
...
...
@@ -273,10 +273,10 @@ TEST(Backward, net_input_of_network_not_need_grad) {
TEST
(
Backward
,
net_shared_weight
)
{
ops
::
NetOp
net
;
net
.
A
d
dOp
(
f
::
OpRegistry
::
CreateOp
(
"mul"
,
{{
"X"
,
{
"x"
}},
{
"Y"
,
{
"w"
}}},
{{
"Out"
,
{
"out"
}}},
{}));
net
.
A
d
dOp
(
f
::
OpRegistry
::
CreateOp
(
"mul"
,
{{
"X"
,
{
"out"
}},
{
"Y"
,
{
"w"
}}},
{{
"Out"
,
{
"FinalOut"
}}},
{}));
net
.
A
ppen
dOp
(
f
::
OpRegistry
::
CreateOp
(
"mul"
,
{{
"X"
,
{
"x"
}},
{
"Y"
,
{
"w"
}}},
{{
"Out"
,
{
"out"
}}},
{}));
net
.
A
ppen
dOp
(
f
::
OpRegistry
::
CreateOp
(
"mul"
,
{{
"X"
,
{
"out"
}},
{
"Y"
,
{
"w"
}}},
{{
"Out"
,
{
"FinalOut"
}}},
{}));
net
.
CompleteAddOp
();
auto
bwd
=
f
::
Backward
(
net
,
{});
...
...
@@ -357,19 +357,19 @@ TEST(Backward, op_part_of_input_are_not_need) {
TEST
(
Backward
,
linear_net_intermediate_variable_has_no_grad
)
{
ops
::
NetOp
net
;
net
.
A
d
dOp
(
f
::
OpRegistry
::
CreateOp
(
net
.
A
ppen
dOp
(
f
::
OpRegistry
::
CreateOp
(
"fc"
,
{{
"X"
,
{
"x1"
}},
{
"W"
,
{
"w1"
}},
{
"b"
,
{
"b1"
}}},
{{
"mul_result"
,
{
"mul_out1"
}},
{
"add_result"
,
{
"add_out1"
}},
{
"Out"
,
{
"out1"
}}},
{}));
net
.
A
d
dOp
(
f
::
OpRegistry
::
CreateOp
(
net
.
A
ppen
dOp
(
f
::
OpRegistry
::
CreateOp
(
"fc"
,
{{
"X"
,
{
"out1"
}},
{
"W"
,
{
"w2"
}},
{
"b"
,
{
"b2"
}}},
{{
"mul_result"
,
{
"mul_out2"
}},
{
"add_result"
,
{
"tmp_out2"
}},
{
"Out"
,
{
"out2"
}}},
{}));
net
.
A
d
dOp
(
f
::
OpRegistry
::
CreateOp
(
net
.
A
ppen
dOp
(
f
::
OpRegistry
::
CreateOp
(
"fc"
,
{{
"X"
,
{
"out2"
}},
{
"W"
,
{
"w3"
}},
{
"b"
,
{
"b3"
}}},
{{
"mul_result"
,
{
"mul_out3"
}},
{
"add_result"
,
{
"tmp_out3"
}},
...
...
paddle/framework/pybind.cc
浏览文件 @
ce723af0
...
...
@@ -222,8 +222,8 @@ All parameter, weight, gradient are variables in Paddle.
retv
->
SetType
(
"plain_net"
);
return
retv
;
})
.
def
(
"a
d
d_op"
,
[](
operators
::
NetOp
&
self
,
const
OperatorBase
&
op
)
{
self
.
Ad
dOp
(
op
);
})
.
def
(
"a
ppen
d_op"
,
[](
operators
::
NetOp
&
self
,
const
OperatorBase
&
op
)
{
self
.
Appen
dOp
(
op
);
})
.
def
(
"complete_add_op"
,
&
operators
::
NetOp
::
CompleteAddOp
)
.
def
(
"complete_add_op"
,
[](
std
::
shared_ptr
<
operators
::
NetOp
>
&
self
)
{
self
->
CompleteAddOp
();
...
...
paddle/operators/net_op.h
浏览文件 @
ce723af0
...
...
@@ -84,13 +84,14 @@ class NetOp : public framework::OperatorBase {
return
true
;
}
void
A
ddOp
(
const
framework
::
OperatorBase
&
op
)
{
Ad
dOp
(
op
.
Clone
());
}
void
A
ppendOp
(
const
framework
::
OperatorBase
&
op
)
{
Appen
dOp
(
op
.
Clone
());
}
/**
* @brief Add an operator by ptr
*/
void
AddOp
(
std
::
unique_ptr
<
framework
::
OperatorBase
>
op
)
{
PADDLE_ENFORCE
(
!
add_op_done_
,
"Cannot AddOp when this network is sealed"
);
void
AppendOp
(
std
::
unique_ptr
<
framework
::
OperatorBase
>
op
)
{
PADDLE_ENFORCE
(
!
add_op_done_
,
"Cannot AppendOp when this network is sealed"
);
PADDLE_ENFORCE_NOT_NULL
(
op
,
"Cannot Insert Null op"
);
ops_
.
push_back
(
std
::
move
(
op
));
}
...
...
paddle/operators/net_op_test.cc
浏览文件 @
ce723af0
...
...
@@ -38,10 +38,10 @@ TEST(OpKernel, all) {
auto
net
=
std
::
make_shared
<
NetOp
>
();
ASSERT_NE
(
net
,
nullptr
);
net
->
A
d
dOp
(
std
::
unique_ptr
<
TestOp
>
(
net
->
A
ppen
dOp
(
std
::
unique_ptr
<
TestOp
>
(
new
TestOp
(
"test"
,
{{
"X"
,
{
"x"
}},
{
"W"
,
{
"w1"
}},
{
"b"
,
{
"b1"
}}},
{{
"Out"
,
{
"y"
}}},
{})));
net
->
A
d
dOp
(
std
::
unique_ptr
<
TestOp
>
(
net
->
A
ppen
dOp
(
std
::
unique_ptr
<
TestOp
>
(
new
TestOp
(
"test"
,
{{
"X"
,
{
"y"
}},
{
"W"
,
{
"w2"
}},
{
"b"
,
{
"b2"
}}},
{{
"Out"
,
{
"z"
}}},
{})));
...
...
@@ -61,7 +61,7 @@ TEST(NetOp, insert_op) {
auto
op1
=
std
::
unique_ptr
<
framework
::
NOP
>
(
new
framework
::
NOP
(
"empty"
,
{{
"X"
,
{
"x"
}},
{
"W"
,
{
"w1"
}},
{
"b"
,
{
"b1"
}}},
{{
"Out"
,
{
"y"
}}},
{}));
net
.
A
d
dOp
(
*
op1
);
net
.
A
ppen
dOp
(
*
op1
);
net
.
InsertOp
(
0
,
*
op1
);
ASSERT_EQ
(
2UL
,
net
.
ops_
.
size
());
net
.
InsertOp
(
2
,
std
::
move
(
op1
));
...
...
@@ -70,9 +70,9 @@ TEST(NetOp, insert_op) {
TEST
(
NetOp
,
Clone
)
{
NetOp
net
;
net
.
A
d
dOp
(
net
.
A
ppen
dOp
(
std
::
unique_ptr
<
framework
::
NOP
>
(
new
framework
::
NOP
{
"empty"
,
{},
{},
{}}));
net
.
A
d
dOp
(
std
::
unique_ptr
<
framework
::
NOP
>
(
net
.
A
ppen
dOp
(
std
::
unique_ptr
<
framework
::
NOP
>
(
new
framework
::
NOP
{
"empty2"
,
{},
{},
{}}));
net
.
CompleteAddOp
(
true
);
auto
new_net_op
=
net
.
Clone
();
...
...
python/paddle/v2/framework/tests/test_net.py
浏览文件 @
ce723af0
...
...
@@ -6,8 +6,8 @@ import unittest
def
fc
(
X
,
W
,
Y
):
ret_v
=
core
.
Net
.
create
()
ret_v
.
a
d
d_op
(
Operator
(
"mul"
,
X
=
"X"
,
Y
=
"W"
,
Out
=
"pre_activation"
))
ret_v
.
a
d
d_op
(
Operator
(
"sigmoid"
,
X
=
"pre_activation"
,
Y
=
Y
))
ret_v
.
a
ppen
d_op
(
Operator
(
"mul"
,
X
=
"X"
,
Y
=
"W"
,
Out
=
"pre_activation"
))
ret_v
.
a
ppen
d_op
(
Operator
(
"sigmoid"
,
X
=
"pre_activation"
,
Y
=
Y
))
ret_v
.
complete_add_op
(
True
)
return
ret_v
...
...
@@ -16,12 +16,12 @@ class TestNet(unittest.TestCase):
def
test_net_all
(
self
):
net
=
core
.
Net
.
create
()
op1
=
Operator
(
"add_two"
,
X
=
"X"
,
Y
=
"Y"
,
Out
=
"Out"
)
net
.
a
d
d_op
(
op1
)
net
.
a
ppen
d_op
(
op1
)
net2
=
core
.
Net
.
create
()
net2
.
a
d
d_op
(
fc
(
X
=
"X"
,
W
=
"w"
,
Y
=
"fc.out"
))
net2
.
a
ppen
d_op
(
fc
(
X
=
"X"
,
W
=
"w"
,
Y
=
"fc.out"
))
net2
.
complete_add_op
(
True
)
net
.
a
d
d_op
(
net2
)
net
.
a
ppen
d_op
(
net2
)
net
.
complete_add_op
(
True
)
expected
=
'''
...
...
python/paddle/v2/framework/tests/test_recurrent_op.py
浏览文件 @
ce723af0
...
...
@@ -150,7 +150,7 @@ class TestRecurrentOp(unittest.TestCase):
sig_op
=
Operator
(
"sigmoid"
,
X
=
"sum"
,
Y
=
"h@alias"
)
for
op
in
[
x_fc_op
,
h_fc_op
,
sum_op
,
sig_op
]:
stepnet
.
a
d
d_op
(
op
)
stepnet
.
a
ppen
d_op
(
op
)
stepnet
.
complete_add_op
(
True
)
self
.
rnnop
.
set_stepnet
(
stepnet
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录