Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
csdn_franckjun
Paddle
提交
113c8b93
P
Paddle
项目概览
csdn_franckjun
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
113c8b93
编写于
12月 27, 2021
作者:
P
pangyoki
提交者:
GitHub
12月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix accumulator bug when multiple inplace OPs are executed continuously (#38406)
* fix accumulator bug * fix unittest
上级
65f7fa0d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
7 deletion
+21
-7
paddle/fluid/imperative/basic_engine.cc
paddle/fluid/imperative/basic_engine.cc
+8
-7
python/paddle/fluid/tests/unittests/test_inplace.py
python/paddle/fluid/tests/unittests/test_inplace.py
+13
-0
未找到文件。
paddle/fluid/imperative/basic_engine.cc
浏览文件 @
113c8b93
...
@@ -174,7 +174,7 @@ void BasicEngine::PrepareGradAccumulators(
...
@@ -174,7 +174,7 @@ void BasicEngine::PrepareGradAccumulators(
if
(
!
var
)
continue
;
if
(
!
var
)
continue
;
bool
find_grad_node_of_var
=
false
;
bool
find_grad_node_of_var
=
false
;
if
(
var
->
HasGradNod
e
())
{
if
(
grad_pending_nodes
.
siz
e
())
{
// Because Inplace op overwrites the grad_node of the input grad_var. So
// Because Inplace op overwrites the grad_node of the input grad_var. So
// only the information of grad_pending_node can be used to find the
// only the information of grad_pending_node can be used to find the
// grad_node of grad_var.
// grad_node of grad_var.
...
@@ -240,7 +240,7 @@ void BasicEngine::PrepareGradAccumulators(
...
@@ -240,7 +240,7 @@ void BasicEngine::PrepareGradAccumulators(
}
}
}
}
if
(
!
var
->
HasGradNod
e
()
||
!
find_grad_node_of_var
)
{
if
(
!
grad_pending_nodes
.
siz
e
()
||
!
find_grad_node_of_var
)
{
auto
&
accumulator
=
accumulators_
[
var
.
get
()];
auto
&
accumulator
=
accumulators_
[
var
.
get
()];
if
(
!
accumulator
)
{
if
(
!
accumulator
)
{
if
(
FLAGS_sort_sum_gradient
)
{
if
(
FLAGS_sort_sum_gradient
)
{
...
@@ -438,15 +438,15 @@ void BasicEngine::Execute() {
...
@@ -438,15 +438,15 @@ void BasicEngine::Execute() {
continue
;
continue
;
}
}
const
auto
&
grad_pending_nodes
=
shared_cur_node
->
GradPendingNodes
();
std
::
unordered_map
<
VariableWrapper
*
,
std
::
unordered_map
<
VariableWrapper
*
,
std
::
unique_ptr
<
GradientAccumulator
>>::
iterator
std
::
unique_ptr
<
GradientAccumulator
>>::
iterator
iter
;
iter
;
bool
flag_find_grad
=
false
;
bool
flag_find_grad
=
false
;
if
(
var
->
HasGradNod
e
())
{
if
(
grad_pending_nodes
.
siz
e
())
{
VLOG
(
10
)
<<
"Find gradient of var ("
<<
var
->
Name
()
VLOG
(
10
)
<<
"Find gradient of var ("
<<
var
->
Name
()
<<
") with grad_node."
;
<<
") with grad_node."
;
for
(
auto
&
grad_pending_node
:
for
(
auto
&
grad_pending_node
:
grad_pending_nodes
)
{
shared_cur_node
->
GradPendingNodes
())
{
const
auto
&
iter_grad_node
=
const
auto
&
iter_grad_node
=
accumulators_with_grad_node_
.
find
(
grad_pending_node
);
accumulators_with_grad_node_
.
find
(
grad_pending_node
);
if
(
iter_grad_node
!=
accumulators_with_grad_node_
.
end
())
{
if
(
iter_grad_node
!=
accumulators_with_grad_node_
.
end
())
{
...
@@ -458,10 +458,11 @@ void BasicEngine::Execute() {
...
@@ -458,10 +458,11 @@ void BasicEngine::Execute() {
}
}
}
}
if
(
!
flag_find_grad
)
{
if
(
!
flag_find_grad
)
{
VLOG
(
6
)
<<
"Cannot find gradient of variable "
<<
var
->
Name
();
VLOG
(
6
)
<<
"Cannot find gradient of variable "
<<
var
->
Name
()
<<
" in accumulators_with_grad_node_"
;
}
}
}
}
if
(
!
var
->
HasGradNod
e
()
||
!
flag_find_grad
)
{
if
(
!
grad_pending_nodes
.
siz
e
()
||
!
flag_find_grad
)
{
VLOG
(
10
)
<<
"Find gradient of var ("
<<
var
->
Name
()
VLOG
(
10
)
<<
"Find gradient of var ("
<<
var
->
Name
()
<<
") with no grad_node."
;
<<
") with no grad_node."
;
iter
=
accumulators_
.
find
(
var
.
get
());
iter
=
accumulators_
.
find
(
var
.
get
());
...
...
python/paddle/fluid/tests/unittests/test_inplace.py
浏览文件 @
113c8b93
...
@@ -434,5 +434,18 @@ class TestLossIsInplaceVar(unittest.TestCase):
...
@@ -434,5 +434,18 @@ class TestLossIsInplaceVar(unittest.TestCase):
self
.
assertTrue
(
np
.
array_equal
(
inplace_grad_var_a
,
grad_var_a
))
self
.
assertTrue
(
np
.
array_equal
(
inplace_grad_var_a
,
grad_var_a
))
class
TestContinuouslyInplace
(
unittest
.
TestCase
):
def
test_continuously_inplace
(
self
):
a
=
paddle
.
rand
([
2
,
3
])
a
.
stop_gradient
=
False
b
=
a
*
2
b
.
reshape_
([
-
1
])
b
.
reshape_
([
2
,
3
])
b
.
reshape_
([
-
1
])
b
.
backward
()
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录