Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5429d145
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5429d145
编写于
10月 27, 2022
作者:
G
Guanghua Yu
提交者:
GitHub
10月 27, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update dygraph PTQ export_model api (#47284)
上级
b68c4a1e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
10 deletion
+23
-10
python/paddle/fluid/contrib/slim/quantization/imperative/ptq.py
.../paddle/fluid/contrib/slim/quantization/imperative/ptq.py
+22
-10
python/paddle/fluid/contrib/slim/quantization/imperative/ptq_registry.py
...luid/contrib/slim/quantization/imperative/ptq_registry.py
+1
-0
未找到文件。
python/paddle/fluid/contrib/slim/quantization/imperative/ptq.py
浏览文件 @
5429d145
...
@@ -121,7 +121,7 @@ class ImperativePTQ(object):
...
@@ -121,7 +121,7 @@ class ImperativePTQ(object):
InputSpec or example Tensor. If None, all input variables of
InputSpec or example Tensor. If None, all input variables of
the original Layer's forward method would be the inputs of
the original Layer's forward method would be the inputs of
the saved model. Default None.
the saved model. Default None.
**config
s
(dict, optional): Other save configuration options for
**config (dict, optional): Other save configuration options for
compatibility. We do not recommend using these configurations,
compatibility. We do not recommend using these configurations,
they may be removed in the future. If not necessary, DO NOT use
they may be removed in the future. If not necessary, DO NOT use
them. Default None.
them. Default None.
...
@@ -140,11 +140,15 @@ class ImperativePTQ(object):
...
@@ -140,11 +140,15 @@ class ImperativePTQ(object):
assert
isinstance
(
assert
isinstance
(
model
,
paddle
.
nn
.
Layer
model
,
paddle
.
nn
.
Layer
),
"The model must be the instance of paddle.nn.Layer."
),
"The model must be the instance of paddle.nn.Layer."
is_postprocess
=
config
.
get
(
'postprocess'
,
False
)
config
.
pop
(
'postprocess'
,
None
)
# Convert and save dygraph quantized model
# Convert and save dygraph quantized model
self
.
_convert
(
model
)
self
.
_convert
(
model
)
paddle
.
jit
.
save
(
layer
=
model
,
path
=
path
,
input_spec
=
input_spec
,
**
config
)
paddle
.
jit
.
save
(
layer
=
model
,
path
=
path
,
input_spec
=
input_spec
,
**
config
)
if
not
is_postprocess
:
return
# Load inference program
# Load inference program
is_dynamic_mode
=
False
is_dynamic_mode
=
False
...
@@ -272,10 +276,16 @@ class ImperativePTQ(object):
...
@@ -272,10 +276,16 @@ class ImperativePTQ(object):
output_names
=
layer_info
.
output_names
output_names
=
layer_info
.
output_names
output_thresholds
=
quant_config
.
out_act_quantizer
.
thresholds
output_thresholds
=
quant_config
.
out_act_quantizer
.
thresholds
assert
len
(
output_names
)
==
1
assert
len
(
output_names
)
==
1
assert
len
(
output_thresholds
)
==
1
if
len
(
output_thresholds
)
==
1
:
save_name
=
output_names
[
0
]
+
str
(
0
)
+
"_threshold"
save_name
=
output_names
[
0
]
+
str
(
0
)
+
"_threshold"
sub_layer
.
_set_op_attrs
({
save_name
:
output_thresholds
[
0
]})
sub_layer
.
_set_op_attrs
({
save_name
:
output_thresholds
[
0
]})
sub_layer
.
_set_op_attrs
({
"out_threshold"
:
output_thresholds
[
0
]})
sub_layer
.
_set_op_attrs
({
"out_threshold"
:
output_thresholds
[
0
]})
else
:
_logger
.
warning
(
"output_thresholds shape of {} need to be 1, but received {}"
.
format
(
output_names
[
0
],
len
(
output_thresholds
)
)
)
def
_wrap_simulated_layers
(
self
,
model
):
def
_wrap_simulated_layers
(
self
,
model
):
"""
"""
...
@@ -326,11 +336,13 @@ class ImperativePTQ(object):
...
@@ -326,11 +336,13 @@ class ImperativePTQ(object):
# save the input thresholds
# save the input thresholds
assert
hasattr
(
quant_layer
,
"_fake_quant_input"
)
assert
hasattr
(
quant_layer
,
"_fake_quant_input"
)
assert
hasattr
(
quant_layer
.
_fake_quant_input
,
"_scale"
)
assert
hasattr
(
quant_layer
.
_fake_quant_input
,
"_scale"
)
assert
len
(
in_act_quantizer
.
thresholds
)
==
1
if
len
(
in_act_quantizer
.
thresholds
)
==
1
:
input_threshold
=
np
.
array
(
input_threshold
=
np
.
array
(
[
in_act_quantizer
.
thresholds
[
0
]],
dtype
=
np
.
float32
[
in_act_quantizer
.
thresholds
[
0
]],
dtype
=
np
.
float32
)
)
quant_layer
.
_fake_quant_input
.
_scale
.
set_value
(
input_threshold
)
quant_layer
.
_fake_quant_input
.
_scale
.
set_value
(
input_threshold
)
assert
hasattr
(
quant_layer
,
"_fake_quant_weight"
)
assert
hasattr
(
quant_layer
,
"_fake_quant_weight"
)
assert
hasattr
(
quant_layer
.
_fake_quant_weight
,
"_scale"
)
assert
hasattr
(
quant_layer
.
_fake_quant_weight
,
"_scale"
)
...
...
python/paddle/fluid/contrib/slim/quantization/imperative/ptq_registry.py
浏览文件 @
5429d145
...
@@ -41,6 +41,7 @@ PTQ_LAYERS_INFO = [
...
@@ -41,6 +41,7 @@ PTQ_LAYERS_INFO = [
LayerInfo
(
paddle
.
nn
.
ReLU
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
ReLU
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
ReLU6
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
ReLU6
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Hardswish
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Hardswish
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Swish
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Sigmoid
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Sigmoid
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Softmax
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Softmax
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Tanh
,
[
'X'
],
[],
[
'Out'
]),
LayerInfo
(
paddle
.
nn
.
Tanh
,
[
'X'
],
[],
[
'Out'
]),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录