Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
da951788
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看板
未验证
提交
da951788
编写于
9月 08, 2020
作者:
C
ceci3
提交者:
GitHub
9月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[2.0API] fix weight_norm support negative dim and unittest in convert_syncbn (#27108) (#27157)
* fix 2.0api, test=develop * fix, test=develop
上级
2118868f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
8 deletion
+27
-8
python/paddle/fluid/tests/unittests/test_dygraph_weight_norm.py
.../paddle/fluid/tests/unittests/test_dygraph_weight_norm.py
+10
-0
python/paddle/fluid/tests/unittests/test_sync_batch_norm_op.py
...n/paddle/fluid/tests/unittests/test_sync_batch_norm_op.py
+5
-4
python/paddle/nn/layer/norm.py
python/paddle/nn/layer/norm.py
+4
-4
python/paddle/nn/utils/weight_norm_hook.py
python/paddle/nn/utils/weight_norm_hook.py
+8
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_dygraph_weight_norm.py
浏览文件 @
da951788
...
...
@@ -121,6 +121,9 @@ class TestDygraphWeightNorm(unittest.TestCase):
before_weight
=
linear
.
weight
.
numpy
()
if
self
.
dim
==
None
:
self
.
dim
=
-
1
if
self
.
dim
!=
-
1
:
self
.
dim
=
(
self
.
dim
+
len
(
before_weight
))
%
len
(
before_weight
)
wn
=
weight_norm
(
linear
,
dim
=
self
.
dim
)
outputs
=
[]
for
name
,
data
in
self
.
data
.
items
():
...
...
@@ -158,6 +161,13 @@ class TestDygraphWeightNormCase3(TestDygraphWeightNorm):
self
.
dim
=
3
class
TestDygraphWeightNormCase4
(
TestDygraphWeightNorm
):
def
init_test_case
(
self
):
self
.
batch_size
=
3
self
.
data_desc
=
([
'x'
,
[
2
,
3
,
3
]],
)
self
.
dim
=
-
3
class
TestDygraphRemoveWeightNorm
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
init_test_case
()
...
...
python/paddle/fluid/tests/unittests/test_sync_batch_norm_op.py
浏览文件 @
da951788
...
...
@@ -227,14 +227,15 @@ class TestConvertSyncBatchNorm(unittest.TestCase):
return
with
program_guard
(
Program
(),
Program
()):
compare_model
=
paddle
.
nn
.
Sequential
(
paddle
.
nn
.
Conv2d
(
3
,
5
,
3
),
paddle
.
nn
.
BatchNorm2d
(
5
))
model
=
paddle
.
nn
.
Sequential
(
paddle
.
nn
.
Conv2d
(
3
,
5
,
3
),
paddle
.
nn
.
BatchNorm2d
(
5
))
sync_
model
=
paddle
.
nn
.
SyncBatchNorm
.
convert_sync_batchnorm
(
model
)
for
idx
,
sublayer
in
enumerate
(
model
.
sublayers
()):
model
=
paddle
.
nn
.
SyncBatchNorm
.
convert_sync_batchnorm
(
model
)
for
idx
,
sublayer
in
enumerate
(
compare_
model
.
sublayers
()):
if
isinstance
(
sublayer
,
paddle
.
nn
.
BatchNorm2d
):
self
.
assertEqual
(
isinstance
(
sync_model
[
idx
],
paddle
.
nn
.
SyncBatchNorm
),
True
)
isinstance
(
model
[
idx
],
paddle
.
nn
.
SyncBatchNorm
),
True
)
if
__name__
==
'__main__'
:
...
...
python/paddle/nn/layer/norm.py
浏览文件 @
da951788
...
...
@@ -1130,10 +1130,10 @@ class SyncBatchNorm(_BatchNormBase):
"""
layer_output
=
layer
if
isinstance
(
layer
,
_BatchNormBase
):
layer_output
=
SyncBatchNorm
(
layer
.
_num_features
,
layer
.
_epsilon
,
layer
.
_momentum
,
layer
.
_weight_attr
,
layer
.
_bias_attr
,
layer
.
_data_format
,
layer
.
_name
)
layer_output
=
SyncBatchNorm
(
layer
.
_num_features
,
layer
.
_momentum
,
layer
.
_epsilon
,
layer
.
_weight_attr
,
layer
.
_bias_attr
,
layer
.
_data_format
,
layer
.
_track_running_stats
,
layer
.
_name
)
if
layer
.
_weight_attr
!=
False
and
layer
.
_bias_attr
!=
False
:
with
no_grad
():
...
...
python/paddle/nn/utils/weight_norm_hook.py
浏览文件 @
da951788
...
...
@@ -112,6 +112,14 @@ class WeightNorm(object):
if
dim
is
None
:
dim
=
-
1
# support dim is negative numeber, (dim = -1) == (dim = None)
weight_dim
=
len
(
layer
.
_parameters
[
name
].
shape
)
assert
(
dim
<
weight_dim
and
dim
>=
-
1
*
weight_dim
),
"dim must set between [-R, R), R means the dimension of weight."
if
dim
!=
-
1
:
dim
=
(
dim
+
weight_dim
)
%
weight_dim
fn
=
WeightNorm
(
name
,
dim
)
w
=
getattr
(
layer
,
name
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录