Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
edba405d
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看板
提交
edba405d
编写于
12月 22, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass test_dyn_rnn.py
上级
dcc51da4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
38 addition
and
10 deletion
+38
-10
paddle/framework/op_desc.cc
paddle/framework/op_desc.cc
+8
-0
paddle/framework/op_desc.h
paddle/framework/op_desc.h
+2
-0
paddle/framework/var_desc.cc
paddle/framework/var_desc.cc
+1
-1
paddle/pybind/protobuf.cc
paddle/pybind/protobuf.cc
+1
-0
python/paddle/v2/fluid/backward.py
python/paddle/v2/fluid/backward.py
+26
-9
未找到文件。
paddle/framework/op_desc.cc
浏览文件 @
edba405d
...
...
@@ -90,6 +90,14 @@ OpDescBind::OpDescBind(const std::string &type, const VariableNameMap &inputs,
need_update_
=
true
;
}
void
OpDescBind
::
CopyFrom
(
const
OpDescBind
&
op_desc
)
{
desc_
.
set_type
(
op_desc
.
Type
());
inputs_
=
op_desc
.
inputs_
;
outputs_
=
op_desc
.
outputs_
;
attrs_
=
op_desc
.
attrs_
;
need_update_
=
true
;
}
OpDescBind
::
OpDescBind
(
const
OpDesc
&
desc
,
ProgramDescBind
*
prog
)
:
desc_
(
desc
),
need_update_
(
false
)
{
// restore inputs_
...
...
paddle/framework/op_desc.h
浏览文件 @
edba405d
...
...
@@ -35,6 +35,8 @@ class OpDescBind {
OpDescBind
(
const
OpDesc
&
desc
,
ProgramDescBind
*
prog
);
void
CopyFrom
(
const
OpDescBind
&
op_desc
);
OpDesc
*
Proto
();
std
::
string
Type
()
const
{
return
desc_
.
type
();
}
...
...
paddle/framework/var_desc.cc
浏览文件 @
edba405d
...
...
@@ -72,7 +72,7 @@ const TensorDesc &VarDescBind::tensor_desc() const {
case
VarDesc
::
LOD_TENSOR_ARRAY
:
return
desc_
.
tensor_array
().
tensor
();
default:
PADDLE_THROW
(
"
Unexpected branch
."
);
PADDLE_THROW
(
"
The type of var '"
,
this
->
Name
(),
"' is unsupported
."
);
}
}
...
...
paddle/pybind/protobuf.cc
浏览文件 @
edba405d
...
...
@@ -255,6 +255,7 @@ void BindOpDesc(py::module &m) {
op_desc
.
def
(
"__init__"
,
[](
OpDescBind
&
self
)
{
new
(
&
self
)
OpDescBind
();
},
py
::
return_value_policy
::
reference
)
.
def
(
"copy_from"
,
&
OpDescBind
::
CopyFrom
)
.
def
(
"type"
,
&
OpDescBind
::
Type
)
.
def
(
"set_type"
,
&
OpDescBind
::
SetType
)
.
def
(
"input"
,
&
OpDescBind
::
Input
)
...
...
python/paddle/v2/fluid/backward.py
浏览文件 @
edba405d
...
...
@@ -32,6 +32,16 @@ def _create_op_desc_(op_type, inputs, outputs, attrs):
return
op_desc
def
_infer_var_data_type_
(
var_name
,
block
):
grad_var
=
block
.
desc
.
find_var
(
var_name
.
encode
(
"ascii"
))
fwd_name
=
_strip_grad_suffix_
(
var_name
.
encode
(
"ascii"
))
if
block
.
desc
.
has_var_recursive
(
fwd_name
):
fwd_var
=
block
.
desc
.
find_var_recursive
(
fwd_name
.
encode
(
"ascii"
))
grad_var
.
set_dtype
(
fwd_var
.
dtype
())
else
:
grad_var
.
set_dtype
(
core
.
DataType
.
FP32
)
def
_is_all_in_set_
(
cands
,
s
):
for
c
in
cands
:
if
not
c
in
s
:
...
...
@@ -64,7 +74,7 @@ def _backward_impl_(target,
grad_sub_block
=
program
.
create_block
(
parent_idx
=
sub_block_idx
)
_backward_impl_
(
target
,
sub_block
,
grad_sub_block
,
no_grad_set
,
grad_info_map
,
callback
)
grad_sub_block_list
.
append
(
grad_sub_block
)
grad_sub_block_list
.
append
(
grad_sub_block
.
desc
)
grad_op_desc
,
op_grad_to_var
=
core
.
get_grad_op_desc
(
each_op
.
desc
,
no_grad_set
[
block
.
idx
],
grad_sub_block_list
)
grad_op_descs
.
append
(
grad_op_desc
)
...
...
@@ -80,17 +90,18 @@ def _backward_impl_(target,
for
var_name
in
op_desc
.
input_arg_names
():
if
len
(
var_inputs
[
var_name
])
>
1
:
pending_sum_ops
.
append
((
_create_op_desc_
(
op_type
=
"sum
_op
"
,
inputs
=
var_inputs
[
var_name
]
,
outputs
=
[
var_name
]
,
op_type
=
"sum"
,
inputs
=
{
"X"
:
var_inputs
[
var_name
]}
,
outputs
=
{
"Out"
:
[
var_name
]}
,
attrs
=
{}),
idx
))
var_inputs
[
var_name
]
=
[
var_name
]
for
var_name
in
op_desc
.
output_arg_names
():
if
len
(
var_inputs
[
var_name
])
==
0
:
if
var_name
==
core
.
empty_var_name
()
or
len
(
var_inputs
[
var_name
])
==
0
:
# it's the first time we get the variable
var_inputs
[
var_name
]
=
[
var_name
]
else
:
if
len
(
var_inputs
[
var_name
]
==
1
)
:
if
len
(
var_inputs
[
var_name
]
)
==
1
:
new_name
=
var_name
+
"@RENAME@"
+
\
str
(
var_rename_count
[
var_name
])
var_rename_count
[
var_name
]
=
var_rename_count
[
var_name
]
+
1
...
...
@@ -107,7 +118,7 @@ def _backward_impl_(target,
for
var_name
,
inputs
in
var_inputs
.
iteritems
():
if
len
(
inputs
)
>
1
:
pending_sum_ops
.
append
((
_create_op_desc_
(
op_type
=
"sum
_op
"
,
op_type
=
"sum"
,
inputs
=
{
"X"
:
inputs
},
outputs
=
{
"Out"
:
var_name
},
attrs
=
{}),
len
(
grad_op_descs
)))
...
...
@@ -131,13 +142,15 @@ def _backward_impl_(target,
{})
grad_op_descs
.
insert
(
ele
[
1
],
fill_zeros_like_op
)
# create new gradient variables in the target block desc
new_vars
=
set
()
for
op_desc
in
grad_op_descs
:
for
grad_var_name
in
op_desc
.
output_arg_names
():
grad_var_name
=
grad_var_name
.
encode
(
"ascii"
)
if
target_block
.
desc
.
has_var
(
if
target_block
.
desc
.
has_var
_recursive
(
grad_var_name
)
or
grad_var_name
==
core
.
empty_var_name
():
continue
target_block
.
desc
.
var
(
grad_var_name
)
new_vars
.
add
(
grad_var_name
)
if
not
grad_to_var
.
has_key
(
grad_var_name
):
continue
grad_info_map
[
grad_to_var
[
grad_var_name
]]
=
(
grad_var_name
,
...
...
@@ -160,7 +173,11 @@ def _backward_impl_(target,
for
op_desc
in
grad_op_descs
:
op_desc
.
infer_var_type
(
target_block
.
desc
)
op_desc
.
infer_shape
(
target_block
.
desc
)
target_block
.
desc
.
append_allocated_op
(
op_desc
)
for
arg
in
op_desc
.
output_arg_names
():
if
arg
in
new_vars
:
_infer_var_data_type_
(
arg
,
target_block
)
new_op_desc
=
target_block
.
desc
.
append_op
()
new_op_desc
.
copy_from
(
op_desc
)
target_block
.
sync_with_cpp
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录