Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
e9a0c4ef
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看板
提交
e9a0c4ef
编写于
10月 10, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expose AppendBackward of ProgramDesc to python
上级
d1479d93
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
0 deletion
+25
-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
+17
-0
未找到文件。
paddle/framework/backward.h
浏览文件 @
e9a0c4ef
...
@@ -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(someone): 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
浏览文件 @
e9a0c4ef
...
@@ -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
(
"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
浏览文件 @
e9a0c4ef
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,21 @@ class TestProgram(unittest.TestCase):
...
@@ -31,6 +33,21 @@ 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_backward
(
self
):
prog
=
core
.
ProgramDesc
.
__create_program_desc__
()
self
.
assertIsNotNone
(
prog
)
block
=
prog
.
block
(
0
)
self
.
assertIsNotNone
(
block
)
sum_op_desc
=
block
.
append_op
()
sum_op_desc
.
set_type
(
"sum"
)
sum_op_desc
.
set_input
(
"X"
,
[
"x1"
,
"x2"
])
sum_op_desc
.
set_output
(
"Out"
,
[
"out"
])
self
.
assertEqual
(
len
(
block
.
all_ops
()),
1
)
prog
.
backward
(
set
())
self
.
assertEqual
(
len
(
block
.
all_ops
()),
3
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录