Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5a270b0a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5a270b0a
编写于
7月 10, 2018
作者:
F
fengjiayi
提交者:
GitHub
7月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12062 from JiayiFeng/fix_backward_bug
Fix backward bug
上级
10fbb831
dc005dd6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
21 deletion
+39
-21
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+39
-21
未找到文件。
python/paddle/fluid/backward.py
浏览文件 @
5a270b0a
...
@@ -123,7 +123,8 @@ def _append_grad_suffix_(name):
...
@@ -123,7 +123,8 @@ def _append_grad_suffix_(name):
def
_addup_repetitive_outputs_
(
op_descs
):
def
_addup_repetitive_outputs_
(
op_descs
):
"""
"""
In backward part, an variable may be the output of more than one ops.
In backward part, an variable may be the output of more than one ops.
In this case, the variable should be the accumulation of all the outputs.
And one op may yield its multiple outputs to the same variable.
In these cases, the variable should be the accumulation of all the outputs.
`sum_op`s are added to implement the accumulate.
`sum_op`s are added to implement the accumulate.
"""
"""
pending_sum_ops
=
[]
pending_sum_ops
=
[]
...
@@ -136,29 +137,46 @@ def _addup_repetitive_outputs_(op_descs):
...
@@ -136,29 +137,46 @@ def _addup_repetitive_outputs_(op_descs):
"sum"
,
{
"X"
:
renamed_vars
[
var_name
]},
{
"Out"
:
[
var_name
]},
"sum"
,
{
"X"
:
renamed_vars
[
var_name
]},
{
"Out"
:
[
var_name
]},
{
"use_mkldnn"
:
False
}),
idx
))
{
"use_mkldnn"
:
False
}),
idx
))
renamed_vars
[
var_name
]
=
[
var_name
]
renamed_vars
[
var_name
]
=
[
var_name
]
for
var_name
in
op_desc
.
output_arg_names
():
for
param_idx
,
param_name
in
enumerate
(
op_desc
.
output_names
()):
if
var_name
==
core
.
empty_var_name
(
arg_names
=
op_desc
.
output
(
param_name
)
)
or
var_name
in
op_desc
.
input_arg_names
():
for
arg_idx
,
var_name
in
enumerate
(
arg_names
):
# empty variable or inplace op
if
var_name
==
core
.
empty_var_name
(
continue
)
or
var_name
in
op_desc
.
input_arg_names
():
if
len
(
renamed_vars
[
var_name
])
==
0
:
# empty variable or inplace op
# it's the first time we get the variable
continue
renamed_vars
[
var_name
]
=
[
var_name
]
if
len
(
renamed_vars
[
var_name
])
==
0
:
else
:
# it's the first time we get the variable
if
len
(
renamed_vars
[
var_name
])
==
1
:
renamed_vars
[
var_name
]
=
[
var_name
]
else
:
if
len
(
renamed_vars
[
var_name
])
==
1
:
new_name
=
var_name
+
"@RENAME@"
+
\
str
(
var_rename_count
[
var_name
])
var_rename_count
[
var_name
]
+=
1
# rename original var_name
renamed_vars
[
var_name
][
0
]
=
new_name
_rename_arg_
(
op_descs
,
var_name
,
new_name
,
0
,
idx
)
_rename_arg_
(
pending_sum_ops
,
var_name
,
new_name
)
for
p
in
op_desc
.
output_names
()[:
param_idx
]:
p_arg_names
=
op_desc
.
output
(
p
)
if
var_name
in
p_arg_names
:
op_desc
.
set_output
(
p
,
[
new_name
if
x
==
var_name
else
x
for
x
in
p_arg_names
])
arg_names
=
[
new_name
if
x
==
var_name
else
x
for
x
in
arg_names
[:
arg_idx
]
]
+
arg_names
[
arg_idx
:]
new_name
=
var_name
+
"@RENAME@"
+
\
new_name
=
var_name
+
"@RENAME@"
+
\
str
(
var_rename_count
[
var_name
])
str
(
var_rename_count
[
var_name
])
var_rename_count
[
var_name
]
+=
1
var_rename_count
[
var_name
]
+=
1
# rename original var_name
arg_names
[
arg_idx
]
=
new_name
renamed_vars
[
var_name
][
0
]
=
new_name
op_desc
.
set_output
(
param_name
,
arg_names
)
_rename_arg_
(
op_descs
,
var_name
,
new_name
,
0
,
idx
)
renamed_vars
[
var_name
].
append
(
new_name
)
_rename_arg_
(
pending_sum_ops
,
var_name
,
new_name
)
new_name
=
var_name
+
"@RENAME@"
+
\
str
(
var_rename_count
[
var_name
])
var_rename_count
[
var_name
]
+=
1
op_desc
.
rename_output
(
var_name
,
new_name
)
renamed_vars
[
var_name
].
append
(
new_name
)
for
var_name
,
inputs
in
renamed_vars
.
iteritems
():
for
var_name
,
inputs
in
renamed_vars
.
iteritems
():
if
len
(
inputs
)
>
1
:
if
len
(
inputs
)
>
1
:
pending_sum_ops
.
append
(
pending_sum_ops
.
append
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录