未验证 提交 51538a94 编写于 作者: G Guanghua Yu 提交者: GitHub

update full quant PTQ demo (#1512)

上级 e2f7e378
...@@ -7,11 +7,15 @@ Global: ...@@ -7,11 +7,15 @@ Global:
model_filename: model.pdmodel model_filename: model.pdmodel
params_filename: model.pdiparams params_filename: model.pdiparams
Distillation: PTQ: # Post Training Quantization
alpha: 1.0 quantizable_op_type: ["conv2d", "depthwise_conv2d"]
loss: l2 activation_quantize_type: 'moving_average_abs_max'
algo: avg
onnx_format: False
batch_size: 32
batch_nums: 10
Quantization: Quantization: # Auto Compression
use_pact: true use_pact: true
activation_quantize_type: 'moving_average_abs_max' activation_quantize_type: 'moving_average_abs_max'
weight_bits: 8 weight_bits: 8
...@@ -20,6 +24,10 @@ Quantization: ...@@ -20,6 +24,10 @@ Quantization:
- conv2d - conv2d
- depthwise_conv2d - depthwise_conv2d
Distillation:
alpha: 1.0
loss: l2
TrainConfig: TrainConfig:
train_iter: 8000 train_iter: 8000
eval_iter: 1000 eval_iter: 1000
......
...@@ -7,11 +7,15 @@ Global: ...@@ -7,11 +7,15 @@ Global:
model_filename: model.pdmodel model_filename: model.pdmodel
params_filename: model.pdiparams params_filename: model.pdiparams
Distillation: PTQ: # Post Training Quantization
alpha: 1.0 quantizable_op_type: ["conv2d", "depthwise_conv2d"]
loss: l2 activation_quantize_type: 'moving_average_abs_max'
algo: avg
onnx_format: False
batch_size: 32
batch_nums: 10
Quantization: Quantization: # Auto Compression
use_pact: true use_pact: true
activation_quantize_type: 'moving_average_abs_max' activation_quantize_type: 'moving_average_abs_max'
weight_bits: 8 weight_bits: 8
...@@ -20,6 +24,10 @@ Quantization: ...@@ -20,6 +24,10 @@ Quantization:
- conv2d - conv2d
- depthwise_conv2d - depthwise_conv2d
Distillation:
alpha: 1.0
loss: l2
TrainConfig: TrainConfig:
train_iter: 8000 train_iter: 8000
eval_iter: 1000 eval_iter: 1000
......
...@@ -41,8 +41,6 @@ def argsparser(): ...@@ -41,8 +41,6 @@ def argsparser():
type=str, type=str,
default='gpu', default='gpu',
help="which device used to compress.") help="which device used to compress.")
parser.add_argument(
'--algo', type=str, default='avg', help="post quant algo.")
return parser return parser
...@@ -71,6 +69,7 @@ def main(): ...@@ -71,6 +69,7 @@ def main():
reader_cfg['worker_num'], reader_cfg['worker_num'],
return_list=True) return_list=True)
train_loader = reader_wrapper(train_loader, global_config['input_list']) train_loader = reader_wrapper(train_loader, global_config['input_list'])
ptq_config = all_config['PTQ']
place = paddle.CUDAPlace(0) if FLAGS.devices == 'gpu' else paddle.CPUPlace() place = paddle.CUDAPlace(0) if FLAGS.devices == 'gpu' else paddle.CPUPlace()
exe = paddle.static.Executor(place) exe = paddle.static.Executor(place)
...@@ -81,13 +80,15 @@ def main(): ...@@ -81,13 +80,15 @@ def main():
data_loader=train_loader, data_loader=train_loader,
model_filename=global_config["model_filename"], model_filename=global_config["model_filename"],
params_filename=global_config["params_filename"], params_filename=global_config["params_filename"],
batch_size=32, quantizable_op_type=ptq_config['quantizable_op_type'],
batch_nums=10, activation_quantize_type=ptq_config['activation_quantize_type'],
algo=FLAGS.algo, batch_size=ptq_config['batch_size'],
batch_nums=ptq_config['batch_nums'],
algo=ptq_config['algo'],
hist_percent=0.999, hist_percent=0.999,
is_full_quantize=False, is_full_quantize=False,
bias_correction=False, bias_correction=False,
onnx_format=True, onnx_format=ptq_config['onnx_format'],
skip_tensor_list=None) skip_tensor_list=None)
......
...@@ -7,9 +7,10 @@ Global: ...@@ -7,9 +7,10 @@ Global:
model_filename: model.pdmodel model_filename: model.pdmodel
params_filename: model.pdiparams params_filename: model.pdiparams
PTQ: PTQ: # Post Training Quantization
quantizable_op_type: ["conv2d", "depthwise_conv2d"] quantizable_op_type: ["conv2d", "depthwise_conv2d"]
activation_quantize_type: 'moving_average_abs_max' activation_quantize_type: 'moving_average_abs_max'
algo: avg
is_full_quantize: True is_full_quantize: True
onnx_format: False onnx_format: False
batch_size: 10 batch_size: 10
...@@ -19,7 +20,7 @@ Distillation: ...@@ -19,7 +20,7 @@ Distillation:
alpha: 1.0 alpha: 1.0
loss: soft_label loss: soft_label
Quantization: Quantization: # Auto Compression
onnx_format: true onnx_format: true
use_pact: true use_pact: true
activation_quantize_type: 'moving_average_abs_max' activation_quantize_type: 'moving_average_abs_max'
......
...@@ -7,19 +7,16 @@ Global: ...@@ -7,19 +7,16 @@ Global:
model_filename: model.pdmodel model_filename: model.pdmodel
params_filename: model.pdiparams params_filename: model.pdiparams
PTQ: PTQ: # Post Training Quantization
quantizable_op_type: ["conv2d", "depthwise_conv2d"] quantizable_op_type: ["conv2d", "depthwise_conv2d"]
activation_quantize_type: 'moving_average_abs_max' activation_quantize_type: 'moving_average_abs_max'
algo: avg
is_full_quantize: True is_full_quantize: True
onnx_format: False onnx_format: False
batch_size: 10 batch_size: 10
batch_nums: 10 batch_nums: 10
Distillation: Quantization: # Auto Compression
alpha: 1.0
loss: soft_label
Quantization:
onnx_format: true onnx_format: true
use_pact: true use_pact: true
activation_quantize_type: 'moving_average_abs_max' activation_quantize_type: 'moving_average_abs_max'
...@@ -27,6 +24,10 @@ Quantization: ...@@ -27,6 +24,10 @@ Quantization:
- conv2d - conv2d
- depthwise_conv2d - depthwise_conv2d
Distillation:
alpha: 1.0
loss: soft_label
TrainConfig: TrainConfig:
train_iter: 5000 train_iter: 5000
eval_iter: 1000 eval_iter: 1000
......
...@@ -42,8 +42,6 @@ def argsparser(): ...@@ -42,8 +42,6 @@ def argsparser():
type=str, type=str,
default='gpu', default='gpu',
help="which device used to compress.") help="which device used to compress.")
parser.add_argument(
'--algo', type=str, default='avg', help="post quant algo.")
return parser return parser
...@@ -89,7 +87,7 @@ def main(): ...@@ -89,7 +87,7 @@ def main():
activation_quantize_type=ptq_config['activation_quantize_type'], activation_quantize_type=ptq_config['activation_quantize_type'],
batch_size=ptq_config['batch_size'], batch_size=ptq_config['batch_size'],
batch_nums=ptq_config['batch_nums'], batch_nums=ptq_config['batch_nums'],
algo=FLAGS.algo, algo=ptq_config['algo'],
hist_percent=0.999, hist_percent=0.999,
is_full_quantize=ptq_config['is_full_quantize'], is_full_quantize=ptq_config['is_full_quantize'],
bias_correction=False, bias_correction=False,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册