Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
d9fa688a
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看板
未验证
提交
d9fa688a
编写于
10月 17, 2022
作者:
G
Guanghua Yu
提交者:
GitHub
10月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update dygraph new format QAT API (#1464)
上级
9814a312
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
19 deletion
+30
-19
demo/dygraph/quant/train.py
demo/dygraph/quant/train.py
+3
-2
paddleslim/dygraph/quant/qat.py
paddleslim/dygraph/quant/qat.py
+27
-17
未找到文件。
demo/dygraph/quant/train.py
浏览文件 @
d9fa688a
...
...
@@ -165,6 +165,8 @@ def compress(args):
'moving_rate'
:
0.9
,
# for dygraph quantization, layers of type in quantizable_layer_type will be quantized
'quantizable_layer_type'
:
[
'Conv2D'
,
'Linear'
],
# # Whether to export the quantized model with format of ONNX.
'onnx_format'
:
args
.
onnx_format
,
}
if
args
.
use_pact
:
...
...
@@ -360,8 +362,7 @@ def compress(args):
input_spec
=
[
paddle
.
static
.
InputSpec
(
shape
=
[
None
,
3
,
224
,
224
],
dtype
=
'float32'
)
],
onnx_format
=
args
.
onnx_format
)
])
def
main
():
...
...
paddleslim/dygraph/quant/qat.py
浏览文件 @
d9fa688a
...
...
@@ -58,6 +58,8 @@ _quant_config_default = {
'quantizable_layer_type'
:
[
'Conv2D'
,
'Linear'
],
# whether fuse conv and bn before QAT
'fuse_conv_bn'
:
False
,
# Whether to export the quantized model with format of ONNX. Default is False.
'onnx_format'
:
False
,
}
...
...
@@ -215,7 +217,9 @@ class QAT(object):
weight_preprocess_layer
=
self
.
weight_preprocess
,
act_preprocess_layer
=
self
.
act_preprocess
,
weight_quantize_layer
=
self
.
weight_quantize
,
act_quantize_layer
=
self
.
act_quantize
)
act_quantize_layer
=
self
.
act_quantize
,
onnx_format
=
self
.
config
[
'onnx_format'
],
# support Paddle >= 2.4
)
except
:
self
.
imperative_qat
=
ImperativeQuantAware
(
weight_bits
=
self
.
config
[
'weight_bits'
],
...
...
@@ -257,11 +261,7 @@ class QAT(object):
return
quant_model
def
save_quantized_model
(
self
,
model
,
path
,
input_spec
=
None
,
onnx_format
=
False
):
def
save_quantized_model
(
self
,
model
,
path
,
input_spec
=
None
):
"""
Save the quantized inference model.
...
...
@@ -287,20 +287,30 @@ class QAT(object):
model
.
eval
()
self
.
imperative_qat
.
save_quantized_model
(
layer
=
model
,
path
=
path
,
input_spec
=
input_spec
,
onnx_format
=
onnx_format
)
layer
=
model
,
path
=
path
,
input_spec
=
input_spec
)
def
_remove_preprocess
(
self
,
model
):
state_dict
=
model
.
state_dict
()
self
.
imperative_qat
=
ImperativeQuantAware
(
weight_bits
=
self
.
config
[
'weight_bits'
],
activation_bits
=
self
.
config
[
'activation_bits'
],
weight_quantize_type
=
self
.
config
[
'weight_quantize_type'
],
activation_quantize_type
=
self
.
config
[
'activation_quantize_type'
],
moving_rate
=
self
.
config
[
'moving_rate'
],
quantizable_layer_type
=
self
.
config
[
'quantizable_layer_type'
])
try
:
self
.
imperative_qat
=
ImperativeQuantAware
(
weight_bits
=
self
.
config
[
'weight_bits'
],
activation_bits
=
self
.
config
[
'activation_bits'
],
weight_quantize_type
=
self
.
config
[
'weight_quantize_type'
],
activation_quantize_type
=
self
.
config
[
'activation_quantize_type'
],
moving_rate
=
self
.
config
[
'moving_rate'
],
quantizable_layer_type
=
self
.
config
[
'quantizable_layer_type'
],
onnx_format
=
self
.
config
[
'onnx_format'
],
# support Paddle >= 2.4
)
except
:
self
.
imperative_qat
=
ImperativeQuantAware
(
weight_bits
=
self
.
config
[
'weight_bits'
],
activation_bits
=
self
.
config
[
'activation_bits'
],
weight_quantize_type
=
self
.
config
[
'weight_quantize_type'
],
activation_quantize_type
=
self
.
config
[
'activation_quantize_type'
],
moving_rate
=
self
.
config
[
'moving_rate'
],
quantizable_layer_type
=
self
.
config
[
'quantizable_layer_type'
])
with
paddle
.
utils
.
unique_name
.
guard
():
if
hasattr
(
model
,
"_layers"
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录