Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e0a2b472
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
e0a2b472
编写于
2月 25, 2019
作者:
M
minqiyang
提交者:
ceci3
3月 04, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move ClearBlock into OpBase and VarBase's destructor
test=develop
上级
9abf40c9
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
18 addition
and
31 deletion
+18
-31
paddle/fluid/framework/block_desc.cc
paddle/fluid/framework/block_desc.cc
+0
-14
paddle/fluid/framework/block_desc.h
paddle/fluid/framework/block_desc.h
+0
-2
paddle/fluid/imperative/layer.h
paddle/fluid/imperative/layer.h
+16
-0
paddle/fluid/pybind/protobuf.cc
paddle/fluid/pybind/protobuf.cc
+0
-2
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+2
-9
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
...paddle/fluid/tests/unittests/test_imperative_optimizer.py
+0
-2
python/paddle/fluid/tests/unittests/test_imperative_resnet.py
...on/paddle/fluid/tests/unittests/test_imperative_resnet.py
+0
-2
未找到文件。
paddle/fluid/framework/block_desc.cc
浏览文件 @
e0a2b472
...
...
@@ -163,20 +163,6 @@ std::vector<OpDesc *> BlockDesc::AllOps() const {
return
res
;
}
void
BlockDesc
::
Clear
()
{
// clear all ops
ops_
.
clear
();
// clear all vars which are not persistable
for
(
auto
it
=
vars_
.
begin
();
it
!=
vars_
.
end
();)
{
if
(
it
->
second
->
Persistable
())
{
++
it
;
}
else
{
vars_
.
erase
(
it
++
);
}
}
}
void
BlockDesc
::
Flush
()
{
for
(
auto
&
op_desc
:
ops_
)
{
op_desc
->
Flush
();
...
...
paddle/fluid/framework/block_desc.h
浏览文件 @
e0a2b472
...
...
@@ -97,8 +97,6 @@ class BlockDesc {
std
::
vector
<
OpDesc
*>
AllOps
()
const
;
void
Clear
();
size_t
OpSize
()
const
{
return
ops_
.
size
();
}
OpDesc
*
Op
(
int
idx
)
const
{
return
ops_
.
at
(
idx
).
get
();
}
...
...
paddle/fluid/imperative/layer.h
浏览文件 @
e0a2b472
...
...
@@ -126,12 +126,19 @@ class VarBase {
:
var_desc_
(
nullptr
),
var_
(
var
),
grads_
(
grad
),
block_
(
nullptr
),
stop_gradient_
(
stop_gradient
),
pre_op_
(
nullptr
),
pre_op_out_idx_
(
-
1
)
{}
public:
virtual
~
VarBase
()
{
LOG
(
ERROR
)
<<
"remove var "
<<
name_
;
if
(
block_
)
{
block_
->
RemoveVar
(
name_
);
}
if
(
var_
)
{
delete
var_
;
}
...
...
@@ -189,11 +196,14 @@ class VarBase {
framework
::
Variable
*
var_
;
VarBase
*
grads_
;
framework
::
BlockDesc
*
block_
;
private:
bool
stop_gradient_
;
OpBase
*
pre_op_
;
std
::
string
pre_op_out_name_
;
int
pre_op_out_idx_
;
std
::
string
name_
;
};
/* The wrapper for OpDesc which holds a OpDesc and a OpDesc of its
...
...
@@ -212,6 +222,12 @@ class OpBase {
for
(
framework
::
OpDesc
*
desc
:
grad_op_descs_
)
{
delete
desc
;
}
LOG
(
ERROR
)
<<
"remove op "
<<
op_desc_
->
Type
()
<<
" id "
<<
trace_id_
;
if
(
block_
)
{
block_
->
RemoveOp
(
trace_id_
,
trace_id_
+
1
);
}
}
std
::
map
<
std
::
string
,
std
::
vector
<
VarBase
*>>
ApplyGrad
();
...
...
paddle/fluid/pybind/protobuf.cc
浏览文件 @
e0a2b472
...
...
@@ -189,8 +189,6 @@ void BindBlockDesc(pybind11::module *m) {
return
self
.
HasVar
(
name
);
},
pybind11
::
return_value_policy
::
reference
)
.
def
(
"_clear_block"
,
[](
pd
::
BlockDesc
&
self
)
{
return
self
.
Clear
();
},
pybind11
::
return_value_policy
::
reference
)
.
def
(
"_rename_var"
,
[](
pd
::
BlockDesc
&
self
,
const
pybind11
::
bytes
&
byte_name
,
const
pybind11
::
bytes
&
byte_name_new
)
{
...
...
python/paddle/fluid/framework.py
浏览文件 @
e0a2b472
...
...
@@ -390,6 +390,8 @@ class Variable(object):
if
_in_imperative_mode
():
# record vars in tracer rather than blocks
self
.
_ivar
=
kwargs
.
get
(
"ivar"
,
None
)
self
.
_ivar
.
block
=
block
.
desc
self
.
_ivar
.
name
=
name
if
not
self
.
_ivar
:
self
.
_ivar
=
core
.
VarBase
(
stop_gradient
)
self
.
_ivar
.
desc
=
self
.
desc
...
...
@@ -1200,15 +1202,6 @@ class Block(object):
else
:
raise
ValueError
(
"Var {0} is not found recursively"
.
format
(
name
))
def
_clear_block
(
self
):
assert
_in_imperative_mode
()
# TODO(minqiyang): move this to Variable and Operator's __del__
self
.
desc
.
_clear_block
()
assert
len
(
self
.
vars
)
==
0
assert
len
(
self
.
ops
)
==
0
def
all_parameters
(
self
):
return
list
(
self
.
iter_parameters
())
...
...
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
浏览文件 @
e0a2b472
...
...
@@ -142,8 +142,6 @@ class TestImperativeMnist(unittest.TestCase):
sgd
.
minimize
(
avg_loss
)
mnist
.
clear_gradients
()
fluid
.
default_main_program
().
global_block
().
_clear_block
()
dy_param_value
=
{}
for
param
in
mnist
.
parameters
():
dy_param_value
[
param
.
name
]
=
param
.
_numpy
()
...
...
python/paddle/fluid/tests/unittests/test_imperative_resnet.py
浏览文件 @
e0a2b472
...
...
@@ -286,8 +286,6 @@ class TestImperativeResnet(unittest.TestCase):
optimizer
.
minimize
(
avg_loss
)
resnet
.
clear_gradients
()
fluid
.
default_main_program
().
global_block
().
_clear_block
()
dy_param_value
=
{}
for
param
in
resnet
.
parameters
():
dy_param_value
[
param
.
name
]
=
param
.
_numpy
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录