Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
3ce2d295
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3ce2d295
编写于
1月 24, 2019
作者:
M
minqiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine stop_gradient
test=develop
上级
c8965dc1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
15 deletion
+20
-15
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+11
-0
python/paddle/fluid/imperative/nn.py
python/paddle/fluid/imperative/nn.py
+4
-9
python/paddle/fluid/optimizer.py
python/paddle/fluid/optimizer.py
+1
-1
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
...paddle/fluid/tests/unittests/test_imperative_optimizer.py
+4
-5
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
3ce2d295
...
@@ -1307,6 +1307,17 @@ class Block(object):
...
@@ -1307,6 +1307,17 @@ class Block(object):
outputs
=
kwargs
.
get
(
"outputs"
,
None
),
outputs
=
kwargs
.
get
(
"outputs"
,
None
),
attrs
=
kwargs
.
get
(
"attrs"
,
None
))
attrs
=
kwargs
.
get
(
"attrs"
,
None
))
self
.
ops
.
append
(
op
)
self
.
ops
.
append
(
op
)
# set stop_gradient in static mode
if
kwargs
.
get
(
"stop_gradient"
,
False
):
outputs
=
kwargs
.
get
(
"outputs"
,
None
)
if
outputs
is
not
None
:
for
k
,
v
in
six
.
iteritems
(
outputs
):
if
isinstance
(
v
,
Variable
):
v
.
stop_gradient
=
True
elif
isinstance
(
v
,
list
)
or
isinstance
(
v
,
tuple
):
for
var
in
v
:
var
.
stop_gradient
=
True
self
.
_trace_op
(
op
,
kwargs
.
get
(
"stop_gradient"
,
False
))
self
.
_trace_op
(
op
,
kwargs
.
get
(
"stop_gradient"
,
False
))
return
op
return
op
...
...
python/paddle/fluid/imperative/nn.py
浏览文件 @
3ce2d295
...
@@ -332,21 +332,16 @@ class BatchNorm(layers.Layer):
...
@@ -332,21 +332,16 @@ class BatchNorm(layers.Layer):
shape
=
param_shape
,
shape
=
param_shape
,
dtype
=
self
.
_dtype
,
dtype
=
self
.
_dtype
,
default_initializer
=
Constant
(
1.0
))
default_initializer
=
Constant
(
1.0
))
if
use_global_stats
and
self
.
_helper
.
param_attr
.
learning_rate
==
0.
:
# TODO(minqiyang): change stop_gradient sign to trainable to align with static graph
self
.
_scale
.
stop_gradient
=
True
# # setting stop_gradient=True to reduce computation
# if use_global_stats and self._helper.param_attr.learning_rate == 0.:
# self._scale.stop_gradient = True
self
.
_bias
=
self
.
_helper
.
create_parameter
(
self
.
_bias
=
self
.
_helper
.
create_parameter
(
attr
=
self
.
_helper
.
bias_attr
,
attr
=
self
.
_helper
.
bias_attr
,
shape
=
param_shape
,
shape
=
param_shape
,
dtype
=
self
.
_dtype
,
dtype
=
self
.
_dtype
,
is_bias
=
True
)
is_bias
=
True
)
# TODO(minqiyang): change stop_gradient sign to trainable to align with static graph
if
use_global_stats
and
self
.
_helper
.
bias_attr
.
learning_rate
==
0.
:
# # setting stop_gradient=True to reduce computation
self
.
_bias
.
stop_gradient
=
True
# if use_global_stats and self._helper.bias_attr.learning_rate == 0.:
# self._bias.stop_gradient = True
self
.
_mean
=
self
.
_helper
.
create_parameter
(
self
.
_mean
=
self
.
_helper
.
create_parameter
(
attr
=
ParamAttr
(
attr
=
ParamAttr
(
...
...
python/paddle/fluid/optimizer.py
浏览文件 @
3ce2d295
...
@@ -387,7 +387,7 @@ class Optimizer(object):
...
@@ -387,7 +387,7 @@ class Optimizer(object):
params_grads
=
[]
params_grads
=
[]
for
param
in
parameters
:
for
param
in
parameters
:
if
param
.
stop_gradient
:
if
param
.
stop_gradient
or
not
param
.
trainable
:
continue
continue
# create gradient variable
# create gradient variable
grad_var
=
Variable
(
grad_var
=
Variable
(
...
...
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
浏览文件 @
3ce2d295
...
@@ -98,7 +98,7 @@ class MNIST(fluid.imperative.Layer):
...
@@ -98,7 +98,7 @@ class MNIST(fluid.imperative.Layer):
class
TestImperativeMnist
(
unittest
.
TestCase
):
class
TestImperativeMnist
(
unittest
.
TestCase
):
def
test_mnist_
cpu_
float32
(
self
):
def
test_mnist_float32
(
self
):
seed
=
90
seed
=
90
with
fluid
.
imperative
.
guard
():
with
fluid
.
imperative
.
guard
():
...
@@ -196,11 +196,10 @@ class TestImperativeMnist(unittest.TestCase):
...
@@ -196,11 +196,10 @@ class TestImperativeMnist(unittest.TestCase):
static_param_value
[
static_param_name_list
[
i
-
1
]]
=
out
[
i
]
static_param_value
[
static_param_name_list
[
i
-
1
]]
=
out
[
i
]
for
key
,
value
in
six
.
iteritems
(
static_param_init_value
):
for
key
,
value
in
six
.
iteritems
(
static_param_init_value
):
self
.
assertTrue
(
self
.
assertTrue
(
np
.
allclose
(
value
,
dy_param_init_value
[
key
]))
np
.
allclose
(
value
.
all
(),
dy_param_init_value
[
key
].
all
()))
self
.
assertTrue
(
np
.
allclose
(
static_out
,
dy_out
))
self
.
assertTrue
(
np
.
allclose
(
static_out
.
all
(),
dy_out
.
all
()))
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
self
.
assertTrue
(
np
.
allclose
(
value
.
all
(),
dy_param_value
[
key
].
all
()
))
self
.
assertTrue
(
np
.
allclose
(
value
,
dy_param_value
[
key
]
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录