Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
bb143052
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看板
未验证
提交
bb143052
编写于
4月 03, 2019
作者:
Z
Zeng Jinle
提交者:
GitHub
4月 03, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix gc bug in conditional block (#16673)
test=develop
上级
229dc932
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
51 addition
and
8 deletion
+51
-8
paddle/fluid/operators/controlflow/conditional_block_op.cc
paddle/fluid/operators/controlflow/conditional_block_op.cc
+28
-8
python/paddle/fluid/tests/unittests/test_eager_deletion_conditional_block.py
.../tests/unittests/test_eager_deletion_conditional_block.py
+23
-0
未找到文件。
paddle/fluid/operators/controlflow/conditional_block_op.cc
浏览文件 @
bb143052
...
@@ -12,6 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,6 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <algorithm>
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "paddle/fluid/framework/executor.h"
#include "paddle/fluid/framework/executor.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/var_type.h"
#include "paddle/fluid/framework/var_type.h"
...
@@ -174,24 +177,41 @@ class ConditionalBlockGradOp : public ConditionalOp {
...
@@ -174,24 +177,41 @@ class ConditionalBlockGradOp : public ConditionalOp {
framework
::
Executor
exec
(
dev_place
);
framework
::
Executor
exec
(
dev_place
);
auto
*
block
=
Attr
<
framework
::
BlockDesc
*>
(
"sub_block"
);
auto
*
block
=
Attr
<
framework
::
BlockDesc
*>
(
"sub_block"
);
exec
.
Run
(
*
block
->
Program
(),
&
cur_scope
,
block
->
ID
(),
false
);
AssignLocalGradientToGlobal
(
dev_place
,
cur_scope
,
Inputs
(
"Input"
),
const
auto
&
ins
=
Inputs
(
"Input"
);
Outputs
(
framework
::
GradVarName
(
"Input"
)));
const
auto
&
d_ins
=
Outputs
(
framework
::
GradVarName
(
"Input"
));
const
auto
&
conds
=
Inputs
(
"Cond"
);
const
auto
&
d_conds
=
Outputs
(
framework
::
GradVarName
(
"Cond"
));
std
::
vector
<
std
::
string
>
ins_conds_grads
;
ins_conds_grads
.
reserve
(
ins
.
size
()
+
conds
.
size
());
for
(
auto
&
in
:
ins
)
{
ins_conds_grads
.
emplace_back
(
framework
::
GradVarName
(
in
));
}
for
(
auto
&
cond
:
conds
)
{
ins_conds_grads
.
emplace_back
(
framework
::
GradVarName
(
cond
));
}
exec
.
Run
(
*
block
->
Program
(),
&
cur_scope
,
block
->
ID
(),
false
,
true
,
ins_conds_grads
);
AssignLocalGradientToGlobal
(
dev_place
,
cur_scope
,
ins_conds_grads
.
data
(),
ins
.
size
(),
d_ins
);
AssignLocalGradientToGlobal
(
dev_place
,
cur_scope
,
Inputs
(
"Cond"
),
AssignLocalGradientToGlobal
(
dev_place
,
cur_scope
,
Outputs
(
framework
::
GradVarName
(
"Cond"
)));
ins_conds_grads
.
data
()
+
ins
.
size
(),
conds
.
size
(),
d_conds
);
}
}
}
}
private:
private:
void
AssignLocalGradientToGlobal
(
void
AssignLocalGradientToGlobal
(
const
platform
::
Place
&
place
,
const
framework
::
Scope
&
cur_scope
,
const
platform
::
Place
&
place
,
const
framework
::
Scope
&
cur_scope
,
const
std
::
vector
<
std
::
string
>
&
p_names
,
const
std
::
string
*
p_grad_names
,
size_t
p_grad_names_num
,
const
std
::
vector
<
std
::
string
>
&
pg_names
)
const
{
const
std
::
vector
<
std
::
string
>
&
pg_names
)
const
{
for
(
size_t
i
=
0
;
i
<
p_
names
.
size
()
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
p_
grad_names_num
;
++
i
)
{
auto
out_grad_name
=
pg_names
[
i
];
auto
out_grad_name
=
pg_names
[
i
];
auto
in_grad_name
=
framework
::
GradVarName
(
p_names
[
i
])
;
const
auto
&
in_grad_name
=
p_grad_names
[
i
]
;
auto
*
in_var
=
cur_scope
.
FindVar
(
in_grad_name
);
auto
*
in_var
=
cur_scope
.
FindVar
(
in_grad_name
);
if
(
in_var
==
nullptr
)
{
if
(
in_var
==
nullptr
)
{
continue
;
continue
;
...
...
python/paddle/fluid/tests/unittests/test_eager_deletion_conditional_block.py
0 → 100644
浏览文件 @
bb143052
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
paddle.fluid
as
fluid
import
unittest
fluid
.
core
.
_set_eager_deletion_mode
(
0.0
,
1.0
,
True
)
from
test_conditional_block
import
*
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录