Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
2afa546f
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看板
未验证
提交
2afa546f
编写于
2月 25, 2020
作者:
L
Liufang Sang
提交者:
GitHub
2月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix quant_aware for 1.6 (#152)
上级
f437281b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
15 deletion
+10
-15
demo/quant/quant_aware/train.py
demo/quant/quant_aware/train.py
+1
-1
paddleslim/quant/quanter.py
paddleslim/quant/quanter.py
+9
-14
未找到文件。
demo/quant/quant_aware/train.py
浏览文件 @
2afa546f
...
...
@@ -12,7 +12,7 @@ sys.path.append(sys.path[0] + "/../../../")
sys
.
path
.
append
(
sys
.
path
[
0
]
+
"/../../"
)
from
paddleslim.common
import
get_logger
from
paddleslim.analysis
import
flops
from
paddleslim.quant
import
quant_aware
,
quant_post
,
convert
from
paddleslim.quant
import
quant_aware
,
convert
import
models
from
utility
import
add_arguments
,
print_arguments
...
...
paddleslim/quant/quanter.py
浏览文件 @
2afa546f
...
...
@@ -13,6 +13,7 @@
# limitations under the License.
import
copy
import
logging
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.framework
import
IrGraph
...
...
@@ -22,6 +23,9 @@ from paddle.fluid.contrib.slim.quantization import ConvertToInt8Pass
from
paddle.fluid.contrib.slim.quantization
import
TransformForMobilePass
from
paddle.fluid
import
core
from
..common
import
get_logger
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
WEIGHT_QUANTIZATION_TYPES
=
[
'abs_max'
,
'channel_wise_abs_max'
,
'range_abs_max'
,
'moving_average_abs_max'
...
...
@@ -40,10 +44,8 @@ _quant_config_default = {
'weight_bits'
:
8
,
# activation quantize bit num, default is 8
'activation_bits'
:
8
,
# ops of name_scope in not_quant_pattern list, will not be quantized
'not_quant_pattern'
:
[
'skip_quant'
],
# ops of type in quantize_op_types, will be quantized
'quantize_op_types'
:
[
'conv2d'
,
'depthwise_conv2d'
,
'mul'
],
# ops of name_scope in not_quant_pattern , will not be quantized
'not_quant_pattern'
:
'skip_quant'
,
# data type after quantization, such as 'uint8', 'int8', etc. default is 'int8'
'dtype'
:
'int8'
,
# window size for 'range_abs_max' quantization. defaulf is 10000
...
...
@@ -84,12 +86,9 @@ def _parse_configs(user_config):
assert
(
configs
[
'activation_bits'
]
>=
1
and
configs
[
'activation_bits'
]
<=
16
),
\
"activation_bits should be between 1 and 16."
assert
isinstance
(
configs
[
'not_quant_pattern'
],
list
),
\
assert
isinstance
(
configs
[
'not_quant_pattern'
],
str
),
\
"not_quant_pattern must be a list"
assert
isinstance
(
configs
[
'quantize_op_types'
],
list
),
\
"quantize_op_types must be a list"
assert
isinstance
(
configs
[
'dtype'
],
str
),
\
"dtype must be a str."
...
...
@@ -102,11 +101,6 @@ def _parse_configs(user_config):
assert
isinstance
(
configs
[
'moving_rate'
],
float
),
\
"moving_rate must be float value, The decay coefficient of moving average, default is 0.9."
assert
isinstance
(
configs
[
'quant_weight_only'
],
bool
),
\
"quant_weight_only must be bool value, if set quant_weight_only True, "
\
"then only quantize parameters of layers which need to be quantized, "
\
" and activations will not be quantized."
return
configs
...
...
@@ -142,7 +136,6 @@ def quant_aware(program, place, config=None, scope=None, for_test=False):
weight_quantize_type
=
config
[
'weight_quantize_type'
],
window_size
=
config
[
'window_size'
],
moving_rate
=
config
[
'moving_rate'
],
quantizable_op_type
=
config
[
'quantize_op_types'
],
skip_pattern
=
config
[
'not_quant_pattern'
])
transform_pass
.
apply
(
main_graph
)
...
...
@@ -185,6 +178,8 @@ def convert(program, place, config=None, scope=None, save_int8=False):
freeze_pass
=
QuantizationFreezePass
(
scope
=
scope
,
place
=
place
,
weight_bits
=
config
[
'weight_bits'
],
activation_bits
=
config
[
'activation_bits'
],
weight_quantize_type
=
config
[
'weight_quantize_type'
])
freeze_pass
.
apply
(
test_graph
)
freezed_program
=
test_graph
.
to_program
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录