Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
f0500791
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看板
提交
f0500791
编写于
11月 12, 2019
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix running err
上级
ed7e33e7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
15 deletion
+17
-15
paddleslim/quant/quanter.py
paddleslim/quant/quanter.py
+4
-4
paddleslim/tests/quant_test/quanter_test.py
paddleslim/tests/quant_test/quanter_test.py
+8
-6
paddleslim/tests/quant_test/run_quant.sh
paddleslim/tests/quant_test/run_quant.sh
+5
-5
未找到文件。
paddleslim/quant/quanter.py
浏览文件 @
f0500791
...
...
@@ -72,13 +72,13 @@ def _parse_configs(user_config):
assert
isinstance
(
configs
[
'weight_bits'
],
int
),
\
"weight_bits must be int value."
assert
isinstance
(
configs
[
'weight_bits'
]
>=
1
and
configs
[
'weight_bits'
]
<=
16
),
\
assert
(
configs
[
'weight_bits'
]
>=
1
and
configs
[
'weight_bits'
]
<=
16
),
\
"weight_bits should be between 1 and 16."
assert
isinstance
(
configs
[
'activation_bits'
],
int
),
\
"activation_bits must be int value."
assert
isinstance
(
configs
[
'activation_bits'
]
>=
1
and
configs
[
'activation_bits'
]
<=
16
),
\
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
),
\
...
...
@@ -90,7 +90,7 @@ def _parse_configs(user_config):
assert
isinstance
(
configs
[
'dtype'
],
str
),
\
"dtype must be a str."
assert
isinstance
(
configs
[
'dtype'
]
in
VALID_DTYPES
),
\
assert
(
configs
[
'dtype'
]
in
VALID_DTYPES
),
\
"dtype can only be "
+
" "
.
join
(
VALID_DTYPES
)
assert
isinstance
(
configs
[
'window_size'
],
int
),
\
...
...
@@ -140,7 +140,7 @@ def quant_aware(program, scope, place, config, for_test=False):
window_size
=
config
[
'window_size'
],
moving_rate
=
config
[
'moving_rate'
],
quantizable_op_type
=
config
[
'quantize_op_types'
],
skip_pattern
=
''
#not_quant_pattern
skip_pattern
=
config
[
'not_quant_pattern'
]
)
transform_pass
.
apply
(
main_graph
)
...
...
paddleslim/tests/quant_test/quanter_test.py
浏览文件 @
f0500791
...
...
@@ -206,7 +206,7 @@ def train(args):
# activation quantize bit num, default is 8
'activation_bits'
:
8
,
# op of name_scope in not_quant_pattern list, will not quantized
'not_quant_pattern'
:
[
'skip_quant'
],
'not_quant_pattern'
:
[
'skip_quant
_dd
'
],
# op of types in quantize_op_types, will quantized
'quantize_op_types'
:
[
'conv2d'
,
'depthwise_conv2d'
,
'mul'
],
# data type after quantization, default is 'int8'
...
...
@@ -292,14 +292,16 @@ def train(args):
# According to the weight and activation quantization type, the graph will be added
# some fake quantize operators and fake dequantize operators.
############################################################################################################
train_prog
=
quant
.
quanter
.
quant_aware
(
train_prog
,
scope
,
place
,
quant_config
,
for_test
=
False
)
test_prog
=
quant
.
quanter
.
quant_aware
(
test_prog
,
scope
,
place
,
quant_config
,
for_test
=
True
)
build_strategy
=
fluid
.
BuildStrategy
()
build_strategy
.
memory_optimize
=
False
build_strategy
.
enable_inplace
=
False
build_strategy
.
fuse_all_reduce_ops
=
False
test_prog
=
quant
.
quanter
.
quant_aware
(
test_prog
,
scope
,
place
,
quant_config
,
for_test
=
True
)
train_prog
=
quant
.
quanter
.
quant_aware
(
train_prog
,
scope
,
place
,
quant_config
,
for_test
=
False
)
train_prog
=
train_prog
.
with_data_parallel
(
loss_name
=
train_cost
.
name
,
build_strategy
=
build_strategy
)
#train_prog_binary = train_prog_binary.with_data_parallel(loss_name=train_cost.name)
params
=
models
.
__dict__
[
args
.
model
]().
params
for
pass_id
in
range
(
params
[
"num_epochs"
]):
...
...
paddleslim/tests/quant_test/run_quant.sh
浏览文件 @
f0500791
#!/usr/bin/env bash
source
activate py27_paddle1.6
source
/home/wsz/anaconda2/bin/
activate py27_paddle1.6
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3,4,5,6,7
#MobileNet v1:
python quanter_test.py
\
nohup
python quanter_test.py
\
--model
=
MobileNet
\
--pretrained_fp32_model
=
'../../../../pretrain/MobileNetV1_pretrained/'
\
--use_gpu
=
True
\
--data_dir
=
'/home/ssd8/wsz/tianfei01/traindata/imagenet/'
\
--batch_size
=
2
56
\
--batch_size
=
2
048
\
--total_images
=
1281167
\
--class_dim
=
1000
\
--image_shape
=
3,224,224
\
...
...
@@ -16,7 +16,7 @@ python quanter_test.py \
--num_epochs
=
20
\
--lr
=
0.0001
\
--act_quant_type
=
abs_max
\
--wt_quant_type
=
abs_max
--wt_quant_type
=
abs_max
2>&1 &
#ResNet50:
#python quanter_test.py \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录