Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
a1095172
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
接近 2 年 前同步成功
通知
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看板
未验证
提交
a1095172
编写于
8月 30, 2022
作者:
C
Chang Xu
提交者:
GitHub
8月 30, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace _C_ops API in OFA (#1398)
上级
954bae8b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
54 deletion
+53
-54
paddleslim/nas/ofa/layers.py
paddleslim/nas/ofa/layers.py
+12
-12
paddleslim/nas/ofa/layers_old.py
paddleslim/nas/ofa/layers_old.py
+41
-42
未找到文件。
paddleslim/nas/ofa/layers.py
浏览文件 @
a1095172
...
...
@@ -20,7 +20,7 @@ import paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
import
paddle.fluid.core
as
core
from
paddle
import
_C_ops
from
paddle
import
_C_ops
,
_legacy_C_ops
from
paddle.fluid.framework
import
in_dygraph_mode
,
_in_legacy_dygraph
,
_non_static_mode
from
paddle.fluid.data_feeder
import
check_variable_and_dtype
from
paddle.fluid.dygraph.layer_object_helper
import
LayerObjectHelper
...
...
@@ -993,7 +993,7 @@ class SuperBatchNorm2D(nn.BatchNorm2D):
if
in_dygraph_mode
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
final_state_
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
self
.
_momentum
,
self
.
_epsilon
,
self
.
_data_format
,
not
self
.
training
,
self
.
_use_global_stats
,
trainable_statistics
,
False
,
False
)
...
...
@@ -1003,7 +1003,7 @@ class SuperBatchNorm2D(nn.BatchNorm2D):
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
return
batch_norm_out
else
:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
final_state_
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
self
.
_momentum
,
self
.
_epsilon
,
self
.
_data_format
,
not
self
.
training
,
self
.
_use_global_stats
,
trainable_statistics
,
False
)
...
...
@@ -1011,7 +1011,7 @@ class SuperBatchNorm2D(nn.BatchNorm2D):
elif
_in_legacy_dygraph
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_
legacy_
C_ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
None
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
...
...
@@ -1020,7 +1020,7 @@ class SuperBatchNorm2D(nn.BatchNorm2D):
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
return
batch_norm_out
else
:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_
legacy_
C_ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
None
,
mean_out
,
variance_out
,
*
attrs
)
return
batch_norm_out
...
...
@@ -1113,7 +1113,7 @@ class SuperSyncBatchNorm(nn.SyncBatchNorm):
if
_non_static_mode
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
sync_batch_norm_out
,
_
,
_
,
_
,
_
,
_
=
_C_ops
.
sync_batch_norm
(
sync_batch_norm_out
,
_
,
_
,
_
,
_
,
_
=
_
legacy_
C_ops
.
sync_batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
...
...
@@ -1122,7 +1122,7 @@ class SuperSyncBatchNorm(nn.SyncBatchNorm):
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
sync_batch_norm_out
,
_
,
_
,
_
,
_
,
_
=
_C_ops
.
sync_batch_norm
(
sync_batch_norm_out
,
_
,
_
,
_
,
_
,
_
=
_
legacy_
C_ops
.
sync_batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
mean_out
,
variance_out
,
*
attrs
)
...
...
@@ -1300,12 +1300,12 @@ class SuperLayerNorm(nn.LayerNorm):
self
.
cur_config
=
{
'prune_dim'
:
feature_dim
}
if
in_dygraph_mode
():
out
,
_
,
_
=
_C_ops
.
final_state_layer_norm
(
input
,
weight
,
bias
,
self
.
_epsilon
,
begin_norm_axis
,
False
)
out
,
_
,
_
=
_C_ops
.
layer_norm
(
input
,
weight
,
bias
,
self
.
_epsilon
,
begin_norm_axis
,
False
)
elif
_in_legacy_dygraph
():
out
,
_
,
_
=
_
C_ops
.
layer_norm
(
input
,
weight
,
bias
,
'epsilon'
,
self
.
_epsilon
,
'begin_norm_axis'
,
begin_norm_axis
)
out
,
_
,
_
=
_
legacy_C_ops
.
layer_norm
(
input
,
weight
,
bias
,
'epsilon'
,
self
.
_epsilon
,
'begin_norm_axis'
,
begin_norm_axis
)
else
:
check_variable_and_dtype
(
input
,
'input'
,
[
'float32'
,
'float64'
],
'LayerNorm'
)
...
...
paddleslim/nas/ofa/layers_old.py
浏览文件 @
a1095172
...
...
@@ -21,7 +21,7 @@ import paddle.fluid.core as core
import
paddle.fluid.dygraph_utils
as
dygraph_utils
from
paddle.fluid.data_feeder
import
check_variable_and_dtype
from
paddle.fluid.framework
import
_varbase_creator
,
in_dygraph_mode
,
_in_legacy_dygraph
,
_non_static_mode
from
paddle
import
_C_ops
from
paddle
import
_C_ops
,
_legacy_C_ops
from
paddle.fluid.data_feeder
import
check_variable_and_dtype
from
paddle.fluid.dygraph.layer_object_helper
import
LayerObjectHelper
from
paddle.fluid.dygraph.nn
import
InstanceNorm
,
Conv2D
,
Conv2DTranspose
,
BatchNorm
...
...
@@ -239,11 +239,11 @@ class SuperConv2D(fluid.dygraph.Conv2D):
-
1
])
_tmp_filter
=
_varbase_creator
(
dtype
=
_input_filter
.
dtype
)
if
_non_static_mode
():
_C_ops
.
matmul
(
_input_filter
,
self
.
__getattr__
(
'%dto%d_matrix'
%
(
src_ks
,
target_ks
)),
_tmp_filter
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
_
legacy_
C_ops
.
matmul
(
_input_filter
,
self
.
__getattr__
(
'%dto%d_matrix'
%
(
src_ks
,
target_ks
)),
_tmp_filter
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
_tmp_filter
=
fluid
.
layers
.
reshape
(
_tmp_filter
,
...
...
@@ -312,11 +312,11 @@ class SuperConv2D(fluid.dygraph.Conv2D):
self
.
_dilation
,
'groups'
,
groups
if
groups
else
1
,
'use_cudnn'
,
self
.
_use_cudnn
)
if
in_dygraph_mode
():
out
=
_C_ops
.
final_state_
conv2d
(
out
=
_C_ops
.
conv2d
(
input
,
weight
,
self
.
_stride
,
padding
,
"EXPLICIT"
,
groups
if
groups
else
1
,
self
.
_dilation
,
"NCHW"
,
False
,
-
1
,
False
)
elif
_in_legacy_dygraph
():
out
=
_C_ops
.
conv2d
(
input
,
weight
,
*
attrs
)
out
=
_
legacy_
C_ops
.
conv2d
(
input
,
weight
,
*
attrs
)
elif
self
.
_l_type
==
'depthwise_conv2d'
:
attrs
=
(
'strides'
,
self
.
_stride
,
'paddings'
,
padding
,
'dilations'
,
self
.
_dilation
,
'groups'
,
groups
...
...
@@ -551,11 +551,11 @@ class SuperConv2DTranspose(fluid.dygraph.Conv2DTranspose):
-
1
])
_tmp_filter
=
_varbase_creator
(
dtype
=
_input_filter
.
dtype
)
if
_non_static_mode
():
_C_ops
.
matmul
(
_input_filter
,
self
.
__getattr__
(
'%dto%d_matrix'
%
(
src_ks
,
target_ks
)),
_tmp_filter
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
_
legacy_
C_ops
.
matmul
(
_input_filter
,
self
.
__getattr__
(
'%dto%d_matrix'
%
(
src_ks
,
target_ks
)),
_tmp_filter
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
_tmp_filter
=
fluid
.
layers
.
reshape
(
_tmp_filter
,
...
...
@@ -620,7 +620,7 @@ class SuperConv2DTranspose(fluid.dygraph.Conv2DTranspose):
padding
=
self
.
_padding
if
_non_static_mode
():
op
=
getattr
(
_C_ops
,
self
.
_op_type
)
op
=
getattr
(
_
legacy_
C_ops
,
self
.
_op_type
)
out
=
op
(
input
,
weight
,
'output_size'
,
self
.
_output_size
,
'strides'
,
self
.
_stride
,
'paddings'
,
padding
,
'dilations'
,
self
.
_dilation
,
'groups'
,
groups
,
'use_cudnn'
,
...
...
@@ -765,21 +765,21 @@ class SuperSeparableConv2D(fluid.dygraph.Layer):
### conv1
if
self
.
conv
[
0
].
_l_type
==
'conv2d'
:
if
in_dygraph_mode
():
out
=
_C_ops
.
final_state_conv2d
(
input
,
weight
,
self
.
conv
[
0
].
_stride
,
self
.
conv
[
0
].
_padding
,
"EXPLICIT"
,
in_nc
,
self
.
conv
[
0
].
_dilation
,
"NCHW"
,
False
,
-
1
,
False
)
out
=
_C_ops
.
conv2d
(
input
,
weight
,
self
.
conv
[
0
].
_stride
,
self
.
conv
[
0
].
_padding
,
"EXPLICIT"
,
in_nc
,
self
.
conv
[
0
].
_dilation
,
"NCHW"
,
False
,
-
1
,
False
)
elif
_in_legacy_dygraph
():
attrs
=
(
'strides'
,
self
.
conv
[
0
].
_stride
,
'paddings'
,
self
.
conv
[
0
].
_padding
,
'dilations'
,
self
.
conv
[
0
].
_dilation
,
'groups'
,
in_nc
,
'use_cudnn'
,
self
.
conv
[
0
].
_use_cudnn
)
out
=
_C_ops
.
conv2d
(
input
,
weight
,
*
attrs
)
out
=
_
legacy_
C_ops
.
conv2d
(
input
,
weight
,
*
attrs
)
elif
self
.
conv
[
0
].
_l_type
==
'depthwise_conv2d'
:
if
in_dygraph_mode
():
out
=
_C_ops
.
final_state_
depthwise_conv2d
(
out
=
_C_ops
.
depthwise_conv2d
(
input
,
weight
,
self
.
conv
[
0
].
_stride
,
self
.
conv
[
0
].
_padding
,
"EXPLICIT"
,
in_nc
,
self
.
conv
[
0
].
_dilation
,
"NCHW"
,
False
,
-
1
,
False
,
False
,
self
.
conv
[
0
].
_use_cudnn
)
...
...
@@ -790,7 +790,7 @@ class SuperSeparableConv2D(fluid.dygraph.Layer):
self
.
conv
[
0
].
_dilation
,
'groups'
,
in_nc
,
'use_cudnn'
,
self
.
conv
[
0
].
_use_cudnn
)
out
=
_C_ops
.
depthwise_conv2d
(
input
,
weight
,
*
attrs
)
out
=
_
legacy_
C_ops
.
depthwise_conv2d
(
input
,
weight
,
*
attrs
)
else
:
raise
ValueError
(
"conv type error"
)
...
...
@@ -810,7 +810,7 @@ class SuperSeparableConv2D(fluid.dygraph.Layer):
if
self
.
conv
[
2
].
_l_type
==
'conv2d'
:
if
in_dygraph_mode
():
out
=
_C_ops
.
final_state_
conv2d
(
out
=
_C_ops
.
conv2d
(
input
,
weight
,
self
.
conv
[
2
].
_stride
,
self
.
conv
[
2
].
_padding
,
"EXPLICIT"
,
self
.
conv
[
2
].
_groups
if
self
.
conv
[
2
].
_groups
else
1
,
self
.
conv
[
2
].
_dilation
,
"NCHW"
,
False
,
-
1
,
False
)
...
...
@@ -821,7 +821,7 @@ class SuperSeparableConv2D(fluid.dygraph.Layer):
self
.
conv
[
2
].
_dilation
,
'groups'
,
self
.
conv
[
2
].
_groups
if
self
.
conv
[
2
].
_groups
else
1
,
'use_cudnn'
,
self
.
conv
[
2
].
_use_cudnn
)
out
=
_C_ops
.
conv2d
(
norm_out
,
weight
,
*
attrs
)
out
=
_
legacy_
C_ops
.
conv2d
(
norm_out
,
weight
,
*
attrs
)
elif
self
.
conv
[
2
].
_l_type
==
'depthwise_conv2d'
:
attrs
=
(
'strides'
,
self
.
conv
[
2
].
_stride
,
'paddings'
,
self
.
conv
[
2
].
_padding
,
'dilations'
,
self
.
conv
[
2
].
_dilation
,
...
...
@@ -889,8 +889,8 @@ class SuperLinear(fluid.dygraph.Linear):
pre_bias
=
_varbase_creator
(
dtype
=
input
.
dtype
)
if
_non_static_mode
():
_C_ops
.
matmul
(
input
,
weight
,
pre_bias
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
_
legacy_
C_ops
.
matmul
(
input
,
weight
,
pre_bias
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
if
self
.
_bias_attr
!=
False
:
pre_act
=
dygraph_utils
.
_append_bias_in_dygraph
(
...
...
@@ -949,7 +949,7 @@ class SuperBatchNorm(fluid.dygraph.BatchNorm):
if
in_dygraph_mode
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
final_state_
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
self
.
_momentum
,
self
.
_epsilon
,
self
.
_data_layout
,
not
self
.
training
,
self
.
_use_global_stats
,
self
.
_trainable_statistics
,
False
)
...
...
@@ -958,7 +958,7 @@ class SuperBatchNorm(fluid.dygraph.BatchNorm):
mean_out
[:
feature_dim
]
=
mean_out_tmp
variance_out
[:
feature_dim
]
=
variance_out_tmp
else
:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
final_state_
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
self
.
_momentum
,
self
.
_epsilon
,
self
.
_data_layout
,
not
self
.
training
,
self
.
_use_global_stats
,
self
.
_trainable_statistics
,
False
)
...
...
@@ -966,7 +966,7 @@ class SuperBatchNorm(fluid.dygraph.BatchNorm):
elif
_in_legacy_dygraph
():
if
feature_dim
!=
self
.
_mean
.
shape
[
0
]:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_
legacy_
C_ops
.
batch_norm
(
input
,
weight
,
bias
,
mean
,
variance
,
None
,
mean_out_tmp
,
variance_out_tmp
,
*
attrs
)
self
.
_mean
[:
feature_dim
].
set_value
(
mean
)
...
...
@@ -974,7 +974,7 @@ class SuperBatchNorm(fluid.dygraph.BatchNorm):
mean_out
[:
feature_dim
].
set_value
(
mean_out_tmp
)
variance_out
[:
feature_dim
].
set_value
(
variance_out_tmp
)
else
:
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_C_ops
.
batch_norm
(
batch_norm_out
,
t1
,
t2
,
t3
,
t4
,
_
=
_
legacy_
C_ops
.
batch_norm
(
input
,
weight
,
bias
,
self
.
_mean
,
self
.
_variance
,
None
,
mean_out
,
variance_out
,
*
attrs
)
return
batch_norm_out
...
...
@@ -1057,12 +1057,11 @@ class SuperInstanceNorm(fluid.dygraph.InstanceNorm):
bias
=
self
.
bias
[:
feature_dim
]
if
in_dygraph_mode
():
out
=
_C_ops
.
final_state_instance_norm
(
input
,
scale
,
bias
,
self
.
_epsilon
)
out
=
_C_ops
.
instance_norm
(
input
,
scale
,
bias
,
self
.
_epsilon
)
return
out
if
_in_legacy_dygraph
():
out
,
_
,
_
=
_
C_ops
.
instance_norm
(
input
,
scale
,
bias
,
'epsilon'
,
self
.
_epsilon
)
out
,
_
,
_
=
_
legacy_C_ops
.
instance_norm
(
input
,
scale
,
bias
,
'epsilon'
,
self
.
_epsilon
)
return
out
...
...
@@ -1091,13 +1090,13 @@ class SuperLayerNorm(fluid.dygraph.LayerNorm):
weight
=
self
.
weight
[:
feature_dim
]
bias
=
self
.
bias
[:
feature_dim
]
if
in_dygraph_mode
():
pre_act
,
_
,
_
,
=
_C_ops
.
final_state_layer_norm
(
input
,
weight
,
bias
,
self
.
_epsilon
,
self
.
_begin_norm_axis
,
False
)
pre_act
,
_
,
_
,
=
_C_ops
.
layer_norm
(
input
,
weight
,
bias
,
self
.
_epsilon
,
self
.
_begin_norm_axis
,
False
)
elif
_in_legacy_dygraph
():
pre_act
,
_
,
_
=
_
C_ops
.
layer_norm
(
input
,
weight
,
bias
,
'epsilon'
,
self
.
_epsilon
,
'begin_norm_axis'
,
self
.
_begin_norm_axis
)
pre_act
,
_
,
_
=
_
legacy_C_ops
.
layer_norm
(
input
,
weight
,
bias
,
'epsilon'
,
self
.
_epsilon
,
'begin_norm_axis'
,
self
.
_begin_norm_axis
)
return
pre_act
...
...
@@ -1132,10 +1131,10 @@ class SuperEmbedding(fluid.dygraph.Embedding):
weight
=
self
.
weight
[:,
:
out_nc
]
if
in_dygraph_mode
():
return
_C_ops
.
final_state_embedding
(
input
,
weight
,
self
.
_padding_idx
,
self
.
_is_sparse
)
return
_C_ops
.
embedding
(
input
,
weight
,
self
.
_padding_idx
,
self
.
_is_sparse
)
elif
_in_legacy_dygraph
():
return
_C_ops
.
lookup_table_v2
(
return
_
legacy_
C_ops
.
lookup_table_v2
(
weight
,
input
,
'is_sparse'
,
self
.
_is_sparse
,
'is_distributed'
,
self
.
_is_distributed
,
'remote_prefetch'
,
self
.
_remote_prefetch
,
'padding_idx'
,
self
.
_padding_idx
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录