Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
672be806
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看板
提交
672be806
编写于
11月 12, 2019
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add scope default val None
上级
5e0c1cc3
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
7 addition
and
22 deletion
+7
-22
paddleslim/quant/quanter.py
paddleslim/quant/quanter.py
+7
-22
未找到文件。
paddleslim/quant/quanter.py
浏览文件 @
672be806
...
...
@@ -26,6 +26,7 @@ WEIGHT_QUANTIZATION_TYPES=['abs_max', 'channel_wise_abs_max']
ACTIVATION_QUANTIZATION_TYPES
=
[
'abs_max'
,
'range_abs_max'
,
'moving_average_abs_max'
]
VALID_DTYPES
=
[
'int8'
]
_quant_config_default
=
{
# weight quantize type, default is 'abs_max'
'weight_quantize_type'
:
'abs_max'
,
...
...
@@ -50,6 +51,7 @@ _quant_config_default = {
'quant_weight_only'
:
False
}
def
_parse_configs
(
user_config
):
"""
check user configs is valid, and set default value if user not config.
...
...
@@ -107,8 +109,7 @@ def _parse_configs(user_config):
return
configs
def
quant_aware
(
program
,
scope
,
place
,
config
,
for_test
=
False
):
def
quant_aware
(
program
,
place
,
config
,
scope
=
None
,
for_test
=
False
):
"""
add trainable quantization ops in program.
Args:
...
...
@@ -151,7 +152,8 @@ def quant_aware(program, scope, place, config, for_test=False):
quant_program
=
fluid
.
CompiledProgram
(
main_graph
.
graph
)
return
quant_program
def
quant_post
(
program
,
scope
,
place
,
config
):
def
quant_post
(
program
,
place
,
config
,
scope
=
None
):
"""
add quantization ops in program. the program returned is not trainable.
Args:
...
...
@@ -163,25 +165,8 @@ def quant_post(program, scope, place, config):
Return:
fluid.Program: the quantization program is not trainable.
"""
pass
scope
=
fluid
.
global_scope
()
if
not
scope
else
scope
assert
isinstance
(
config
,
dict
),
"config must be dict"
assert
'weight_quantize_type'
in
config
.
keys
(),
'weight_quantize_type must be configured'
assert
'activation_quantize_type'
in
config
.
keys
(),
'activation_quantize_type must be configured'
config
=
_parse_configs
(
config
)
main_graph
=
IrGraph
(
core
.
Graph
(
program
.
desc
),
for_test
=
True
)
transform_pass
=
QuantizationTransformPass
(
scope
=
scope
,
place
=
place
,
activation_quantize_type
=
config
[
'activation_quantize_type'
],
weight_quantize_type
=
config
[
'weight_quantize_type'
])
transform_pass
.
apply
(
main_graph
)
quant_program
=
main_graph
.
to_program
()
return
quant_program
def
convert
(
program
,
scope
,
place
,
config
,
save_int8
=
False
):
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录