Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7858d332
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7858d332
编写于
7月 09, 2021
作者:
C
cc
提交者:
GitHub
7月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[dygraph qat] change default config and fix bug (#34047)
上级
1f28968b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
8 deletion
+20
-8
python/paddle/fluid/contrib/slim/quantization/imperative/ptq.py
.../paddle/fluid/contrib/slim/quantization/imperative/ptq.py
+17
-6
python/paddle/fluid/contrib/slim/quantization/imperative/ptq_config.py
.../fluid/contrib/slim/quantization/imperative/ptq_config.py
+1
-1
python/paddle/fluid/contrib/slim/tests/test_imperative_ptq.py
...on/paddle/fluid/contrib/slim/tests/test_imperative_ptq.py
+2
-1
未找到文件。
python/paddle/fluid/contrib/slim/quantization/imperative/ptq.py
浏览文件 @
7858d332
...
...
@@ -46,8 +46,8 @@ class ImperativePTQ(object):
Args:
quant_config(PTQConfig): the config of post training quantization.
The config has weight_quantizer and activation_quantizer.
In default, the weight_quantizer
and activation_quantizer are
Absmax
Quantizer.
In default, the weight_quantizer
is PerChannelAbsmaxQuantizer
and the activation_quantizer is KL
Quantizer.
"""
super
(
ImperativePTQ
,
self
).
__init__
()
...
...
@@ -70,9 +70,9 @@ class ImperativePTQ(object):
"The model must be the instance of paddle.nn.Layer."
if
not
inplace
:
new_
model
=
copy
.
deepcopy
(
model
)
model
=
copy
.
deepcopy
(
model
)
for
name
,
layer
in
new_
model
.
named_sublayers
():
for
name
,
layer
in
model
.
named_sublayers
():
if
PTQRegistry
.
is_supported_layer
(
layer
)
\
and
utils
.
is_leaf_layer
(
layer
)
\
and
not
self
.
_is_skip_layer
(
layer
):
...
...
@@ -90,13 +90,13 @@ class ImperativePTQ(object):
layer
.
_forward_post_hooks
.
move_to_end
(
quant_hook_handle
.
_hook_id
,
last
=
False
)
return
new_
model
return
model
def
save_quantized_model
(
self
,
model
,
path
,
input_spec
=
None
,
**
config
):
"""
1. Convert the quantized model
2. Call jit.save to save the inference model
3.
Load and postprocess the
inference model.
3.
Post process the
inference model.
Args:
model (Layer): The model to be saved.
...
...
@@ -207,8 +207,19 @@ class ImperativePTQ(object):
assert
isinstance
(
model
,
paddle
.
nn
.
Layer
),
\
"The input model must be the instance of paddle.nn.Layer."
total_num
=
0
cur_num
=
0
for
name
,
sub_layer
in
model
.
named_sublayers
():
if
self
.
_is_quant_layer
(
sub_layer
):
total_num
+=
1
for
name
,
sub_layer
in
model
.
named_sublayers
():
if
self
.
_is_quant_layer
(
sub_layer
):
cur_num
+=
1
if
cur_num
%
5
==
0
:
_logger
.
info
(
"Process the %s / %s layer"
%
(
cur_num
,
total_num
))
quant_config
=
sub_layer
.
_quant_config
if
quant_config
.
enable_in_act_quantizer
:
...
...
python/paddle/fluid/contrib/slim/quantization/imperative/ptq_config.py
浏览文件 @
7858d332
...
...
@@ -53,4 +53,4 @@ class PTQConfig(object):
self
.
enable_in_act_quantizer
=
False
default_ptq_config
=
PTQConfig
(
AbsmaxQuantizer
(),
AbsmaxQuantizer
())
default_ptq_config
=
PTQConfig
(
KLQuantizer
(),
PerChannel
AbsmaxQuantizer
())
python/paddle/fluid/contrib/slim/tests/test_imperative_ptq.py
浏览文件 @
7858d332
...
...
@@ -82,7 +82,8 @@ class TestImperativePTQ(unittest.TestCase):
return
data_cache_folder
def
set_vars
(
self
):
self
.
ptq
=
ImperativePTQ
(
default_ptq_config
)
config
=
PTQConfig
(
AbsmaxQuantizer
(),
AbsmaxQuantizer
())
self
.
ptq
=
ImperativePTQ
(
config
)
self
.
batch_num
=
10
self
.
batch_size
=
10
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录