Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
cb642009
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 1 年 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
cb642009
编写于
4月 12, 2022
作者:
C
Chang Xu
提交者:
GitHub
4月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fit new paddle (#1044)
上级
380bce65
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
27 deletion
+85
-27
paddleslim/nas/ofa/layers.py
paddleslim/nas/ofa/layers.py
+43
-14
paddleslim/nas/ofa/layers_old.py
paddleslim/nas/ofa/layers_old.py
+42
-13
未找到文件。
paddleslim/nas/ofa/layers.py
浏览文件 @
cb642009
...
...
@@ -963,19 +963,48 @@ class SuperBatchNorm2D(nn.BatchNorm2D):
"use_mkldnn"
,
False
,
"fuse_with_relu"
,
False
,
"use_global_stats"
,
self
.
_use_global_stats
,
"trainable_statistics"
,
trainable_statistics
)
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
self
.
_variance
[:
feature_dim
].
set_value
(
variance
)
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
try
:
from
paddle
import
_C_ops
from
paddle.fluid.framework
import
in_dygraph_mode
,
_in_legacy_dygraph
if
in_dygraph_mode
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
_C_ops
.
final_state_batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
self
.
_variance
[:
feature_dim
].
set_value
(
variance
)
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
batch_norm_out
=
_C_ops
.
final_state_batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
elif
_in_legacy_dygraph
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
None
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
self
.
_variance
[:
feature_dim
].
set_value
(
variance
)
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
None
,
mean_out
,
variance_out
,
*
attrs
)
except
:
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
self
.
_variance
[:
feature_dim
].
set_value
(
variance
)
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
self
.
cur_config
=
{
'prune_dim'
:
feature_dim
}
return
batch_norm_out
[
0
]
...
...
@@ -1246,4 +1275,4 @@ class SuperEmbedding(nn.Embedding):
weight
=
weight
,
padding_idx
=
self
.
_padding_idx
,
sparse
=
self
.
_sparse
,
name
=
self
.
_name
)
\ No newline at end of file
name
=
self
.
_name
)
paddleslim/nas/ofa/layers_old.py
浏览文件 @
cb642009
...
...
@@ -903,19 +903,48 @@ class SuperBatchNorm(fluid.dygraph.BatchNorm):
"use_mkldnn"
,
False
,
"fuse_with_relu"
,
self
.
_fuse_with_relu
,
"use_global_stats"
,
self
.
_use_global_stats
,
'trainable_statistics'
,
self
.
_trainable_statistics
)
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
]
=
mean
self
.
_variance
[:
feature_dim
]
=
variance
mean_out
[:
feature_dim
]
=
mean_out_tmp
variance_out
[:
feature_dim
]
=
variance_out_tmp
else
:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
try
:
from
paddle
import
_C_ops
from
paddle.fluid.framework
import
in_dygraph_mode
,
_in_legacy_dygraph
if
in_dygraph_mode
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
_C_ops
.
final_state_batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
]
=
mean
self
.
_variance
[:
feature_dim
]
=
variance
mean_out
[:
feature_dim
]
=
mean_out_tmp
variance_out
[:
feature_dim
]
=
variance_out_tmp
else
:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
elif
_in_legacy_dygraph
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
None
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
self
.
_variance
[:
feature_dim
].
set_value
(
variance
)
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
None
,
mean_out
,
variance_out
,
*
attrs
)
except
:
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
self
.
_variance
[:
feature_dim
].
set_value
(
variance
)
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
batch_norm_out
=
core
.
ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
return
dygraph_utils
.
_append_activation_in_dygraph
(
batch_norm_out
[
0
],
act
=
self
.
_act
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录