Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
兽拳
Paddle
提交
5c776877
P
Paddle
项目概览
兽拳
/
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,发现更多精彩内容 >>
提交
5c776877
编写于
1月 28, 2019
作者:
M
minqiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix batch_norm's stop_gradient bug
test=develop
上级
79d62c54
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
4 deletion
+17
-4
paddle/fluid/imperative/layer.cc
paddle/fluid/imperative/layer.cc
+2
-0
paddle/fluid/imperative/layer.h
paddle/fluid/imperative/layer.h
+7
-2
paddle/fluid/imperative/tracer.cc
paddle/fluid/imperative/tracer.cc
+4
-2
python/paddle/fluid/imperative/nn.py
python/paddle/fluid/imperative/nn.py
+4
-0
未找到文件。
paddle/fluid/imperative/layer.cc
浏览文件 @
5c776877
...
...
@@ -156,6 +156,8 @@ class Autograd {
for
(
auto
it
:
candidate
->
pre_ops_
)
{
for
(
OpBase
*
pre_op
:
it
.
second
)
{
if
(
!
pre_op
)
continue
;
VLOG
(
5
)
<<
"op dep "
<<
candidate
->
op_desc_
->
Type
()
<<
" <---- "
<<
it
.
first
<<
" <---- "
<<
pre_op
->
op_desc_
->
Type
();
if
(
visited
.
find
(
pre_op
)
==
visited
.
end
())
{
visited
.
insert
(
pre_op
);
queue
.
push_back
(
pre_op
);
...
...
paddle/fluid/imperative/layer.h
浏览文件 @
5c776877
...
...
@@ -28,6 +28,7 @@
#include "paddle/fluid/framework/var_desc.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/operators/math/math_function.h"
#include "paddle/fluid/imperative/type_defs.h"
...
...
@@ -148,8 +149,12 @@ class VarBase {
}
void
ClearGradient
()
{
delete
grads_
;
grads_
=
new
VarBase
(
true
);
VLOG
(
1
)
<<
"clear gradient of "
<<
var_desc_
->
Name
();
auto
grads_t
=
grads_
->
var_
->
GetMutable
<
framework
::
LoDTensor
>
();
operators
::
math
::
set_constant
(
*
(
platform
::
DeviceContextPool
::
Instance
().
Get
(
grads_
->
var_
->
Get
<
framework
::
LoDTensor
>
().
place
())),
grads_t
,
0.0
);
}
framework
::
LoDTensor
&
GradValue
();
...
...
paddle/fluid/imperative/tracer.cc
浏览文件 @
5c776877
...
...
@@ -83,11 +83,12 @@ void Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
op
->
input_vars_
=
inputs
;
for
(
auto
it
:
op
->
input_vars_
)
{
auto
&
invars
=
invars_map
[
it
.
first
];
invars
.
reserve
(
it
.
second
.
size
());
for
(
VarBase
*
inp
:
it
.
second
)
{
PADDLE_ENFORCE_NOT_NULL
(
inp
->
var_
,
"op %s input %s nullptr"
,
op
->
op_desc_
->
Type
(),
inp
->
var_desc_
->
Name
());
invars
.
push
_back
(
inp
->
var_
);
invars
.
emplace
_back
(
inp
->
var_
);
vars
[
inp
->
var_desc_
->
Name
()]
=
inp
;
if
(
inp
->
PreOp
())
{
op
->
pre_ops_
[
it
.
first
].
push_back
(
inp
->
PreOp
());
...
...
@@ -104,9 +105,10 @@ void Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
for
(
auto
it
:
op
->
output_vars_
)
{
auto
&
outvars
=
outvars_map
[
it
.
first
];
const
std
::
vector
<
VarBase
*>&
outputs
=
it
.
second
;
outvars
.
reserve
(
outputs
.
size
());
for
(
size_t
i
=
0
;
i
<
outputs
.
size
();
++
i
)
{
VarBase
*
out
=
outputs
[
i
];
outvars
.
push
_back
(
out
->
var_
);
outvars
.
emplace
_back
(
out
->
var_
);
vars
[
out
->
var_desc_
->
Name
()]
=
out
;
framework
::
VarDesc
*
var_desc
=
block
->
FindVar
(
out
->
var_desc_
->
Name
());
...
...
python/paddle/fluid/imperative/nn.py
浏览文件 @
5c776877
...
...
@@ -334,6 +334,7 @@ class BatchNorm(layers.Layer):
default_initializer
=
Constant
(
1.0
))
if
use_global_stats
and
self
.
_helper
.
param_attr
.
learning_rate
==
0.
:
self
.
_scale
.
stop_gradient
=
True
self
.
_scale
.
_stop_gradient
=
True
self
.
_bias
=
self
.
_helper
.
create_parameter
(
attr
=
self
.
_helper
.
bias_attr
,
...
...
@@ -342,6 +343,7 @@ class BatchNorm(layers.Layer):
is_bias
=
True
)
if
use_global_stats
and
self
.
_helper
.
bias_attr
.
learning_rate
==
0.
:
self
.
_bias
.
stop_gradient
=
True
self
.
_bias
.
_stop_gradient
=
True
self
.
_mean
=
self
.
_helper
.
create_parameter
(
attr
=
ParamAttr
(
...
...
@@ -352,6 +354,7 @@ class BatchNorm(layers.Layer):
shape
=
param_shape
,
dtype
=
self
.
_dtype
)
self
.
_mean
.
stop_gradient
=
True
self
.
_mean
.
_stop_gradient
=
True
self
.
_variance
=
self
.
_helper
.
create_parameter
(
attr
=
ParamAttr
(
...
...
@@ -362,6 +365,7 @@ class BatchNorm(layers.Layer):
shape
=
param_shape
,
dtype
=
self
.
_dtype
)
self
.
_variance
.
stop_gradient
=
True
self
.
_variance
.
_stop_gradient
=
True
self
.
_in_place
=
in_place
self
.
_momentum
=
momentum
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录