Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
5e9d4399
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看板
提交
5e9d4399
编写于
10月 11, 2017
作者:
Q
Qiao Longfei
提交者:
GitHub
10月 11, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4699 from jacquesqiao/expose-backward
expose AppendBackward of ProgramDesc to python
上级
134a0736
e8cad5a1
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
38 addition
and
0 deletion
+38
-0
paddle/framework/backward.h
paddle/framework/backward.h
+2
-0
paddle/pybind/protobuf.cc
paddle/pybind/protobuf.cc
+6
-0
python/paddle/v2/framework/tests/test_program.py
python/paddle/v2/framework/tests/test_program.py
+30
-0
未找到文件。
paddle/framework/backward.h
浏览文件 @
5e9d4399
...
@@ -27,6 +27,8 @@ extern std::unique_ptr<OperatorBase> Backward(
...
@@ -27,6 +27,8 @@ extern std::unique_ptr<OperatorBase> Backward(
const
OperatorBase
&
forwardOp
,
const
OperatorBase
&
forwardOp
,
const
std
::
unordered_set
<
std
::
string
>&
no_grad_vars
);
const
std
::
unordered_set
<
std
::
string
>&
no_grad_vars
);
// TODO(jiayi): Add target as parameter and generate backward op
// according to target.
void
AppendBackward
(
ProgramDescBind
&
program_desc
,
void
AppendBackward
(
ProgramDescBind
&
program_desc
,
const
std
::
unordered_set
<
std
::
string
>&
no_grad_vars
);
const
std
::
unordered_set
<
std
::
string
>&
no_grad_vars
);
...
...
paddle/pybind/protobuf.cc
浏览文件 @
5e9d4399
...
@@ -15,6 +15,7 @@ limitations under the License. */
...
@@ -15,6 +15,7 @@ limitations under the License. */
#include "paddle/pybind/protobuf.h"
#include "paddle/pybind/protobuf.h"
#include <deque>
#include <deque>
#include <iostream>
#include <iostream>
#include "paddle/framework/backward.h"
#include "paddle/framework/block_desc.h"
#include "paddle/framework/block_desc.h"
#include "paddle/framework/op_desc.h"
#include "paddle/framework/op_desc.h"
#include "paddle/framework/program_desc.h"
#include "paddle/framework/program_desc.h"
...
@@ -116,6 +117,11 @@ void BindProgramDesc(py::module &m) {
...
@@ -116,6 +117,11 @@ void BindProgramDesc(py::module &m) {
py
::
return_value_policy
::
reference
)
py
::
return_value_policy
::
reference
)
.
def
(
"append_block"
,
&
ProgramDescBind
::
AppendBlock
,
.
def
(
"append_block"
,
&
ProgramDescBind
::
AppendBlock
,
py
::
return_value_policy
::
reference
)
py
::
return_value_policy
::
reference
)
.
def
(
"append_backward"
,
[](
ProgramDescBind
&
program_desc
,
const
std
::
unordered_set
<
std
::
string
>
&
no_grad_vars
)
{
AppendBackward
(
program_desc
,
no_grad_vars
);
})
.
def
(
"block"
,
&
ProgramDescBind
::
Block
,
py
::
return_value_policy
::
reference
)
.
def
(
"block"
,
&
ProgramDescBind
::
Block
,
py
::
return_value_policy
::
reference
)
.
def
(
"num_blocks"
,
&
ProgramDescBind
::
Size
);
.
def
(
"num_blocks"
,
&
ProgramDescBind
::
Size
);
}
}
...
...
python/paddle/v2/framework/tests/test_program.py
浏览文件 @
5e9d4399
import
unittest
import
unittest
import
paddle.v2.framework.core
as
core
from
paddle.v2.framework.graph
import
g_program
from
paddle.v2.framework.graph
import
g_program
...
@@ -31,6 +33,34 @@ class TestProgram(unittest.TestCase):
...
@@ -31,6 +33,34 @@ class TestProgram(unittest.TestCase):
self
.
assertEqual
(
1
,
b
.
idx
)
self
.
assertEqual
(
1
,
b
.
idx
)
self
.
assertEqual
(
0
,
b
.
parent_idx
)
self
.
assertEqual
(
0
,
b
.
parent_idx
)
def
test_append_backward
(
self
):
prog
=
core
.
ProgramDesc
.
__create_program_desc__
()
self
.
assertIsNotNone
(
prog
)
block
=
prog
.
block
(
0
)
self
.
assertIsNotNone
(
block
)
mul_op_desc
=
block
.
append_op
()
mul_op_desc
.
set_type
(
"mul"
)
mul_op_desc
.
set_input
(
"X"
,
[
"x1"
])
mul_op_desc
.
set_input
(
"Y"
,
[
"y1"
])
mul_op_desc
.
set_output
(
"Out"
,
[
"out1"
])
sum_op_desc
=
block
.
append_op
()
sum_op_desc
.
set_type
(
"elementwise_add"
)
sum_op_desc
.
set_input
(
"X"
,
[
"out1"
])
sum_op_desc
.
set_input
(
"Y"
,
[
"b1"
])
sum_op_desc
.
set_output
(
"Out"
,
[
"out2"
])
expect_ops
=
[
"mul"
,
"elementwise_add"
,
"elementwise_add_grad"
,
"mul_grad"
]
actual_ops
=
[]
prog
.
append_backward
(
set
())
for
op
in
block
.
all_ops
():
actual_ops
.
append
(
op
.
type
())
print
(
actual_ops
)
self
.
assertEqual
(
actual_ops
,
expect_ops
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录