Skip to content

Commit fb3fac1

Browse files
gushiqiaozzjjay
andauthored
Add automatic region division and Fix pre-tensor quant (#1517)
* Fixed naming conflicts and fc layer quantification * Update fine_tune.py * Update readme * Add automatic region division and Fix pre-tensor quant * Update unit test file * Fix bugs. Co-authored-by: zhouzj <[email protected]>
1 parent 4fb41e4 commit fb3fac1

File tree

5 files changed

+307
-106
lines changed

5 files changed

+307
-106
lines changed

docs/zh_cn/tutorials/quant/post_training_quantization.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $$
7474
说明:
7575
- 如果想使用bias_correction,可以在PaddleSlim的[离线量化接口](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/api_cn/static/quant/quantization_api.rst#quant_post_static)修改`bias_correction`参数为True即可,默认为False。
7676
- 如果想使用Adaround方法,可以在PaddleSlim的[离线量化接口](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/api_cn/static/quant/quantization_api.rst#quant_post_static)修改`round_type`参数为`adaround`即可,默认为`round`
77-
- 如果想使用BRECQ方法,可以在PaddleSlim的[量化重构接口](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/api_cn/static/quant/quantization_api.rst#quant_post_static)修改`recon_level`参数为`regionn-wise`即可,默认为`layer-wise`
77+
- 如果想使用BRECQ方法,可以在PaddleSlim的[量化重构接口](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/api_cn/static/quant/quantization_api.rst#quant_post_static)修改`recon_level`参数为`region-wise`即可,默认为`layer-wise`
7878
- 如果想使用QDrop方法,可以在PaddleSlim的[量化重构接口](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/api_cn/static/quant/quantization_api.rst#quant_post_static)修改`simulate_activation_quant`参数为`True`即可,默认为`False`
7979

8080
### 效果对比
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
arch: YOLOv6
2-
model_dir: ./yolov6s.onnx
2+
model_dir: ./yolov6s.onnx
33
dataset_dir: /dataset/coco/
44
model_filename: model.pdmodel
55
params_filename: model.pdiparams
@@ -8,25 +8,3 @@ val_image_dir: val2017
88
train_anno_path: annotations/instances_train2017.json
99
val_anno_path: annotations/instances_val2017.json
1010
skip_tensor_list: None
11-
regions: [['x2paddle_image_arrays','relu_8.tmp_0'],
12-
['relu_8.tmp_0','relu_15.tmp_0'],
13-
['relu_15.tmp_0','relu_21.tmp_0'],
14-
['concat_1.tmp_0','relu_26.tmp_0'],
15-
['concat_2.tmp_0', 'relu_30.tmp_0'],
16-
['relu_30.tmp_0', 'concat_4.tmp_0'],
17-
['relu_30.tmp_0', 'relu_31.tmp_0'],
18-
['concat_3.tmp_0', 'relu_35.tmp_0'],
19-
['relu_35.tmp_0', 'relu_36.tmp_0'],
20-
['concat_5.tmp_0', 'concat_10.tmp_0'],
21-
['relu_35.tmp_0', 'concat_8.tmp_0']]
22-
region_weights_names: [['conv2d_0.w_0','conv2d_1.w_0','conv2d_2.w_0','conv2d_3.w_0','conv2d_4.w_0','conv2d_5.w_0','conv2d_6.w_0','conv2d_7.w_0','conv2d_8.w_0'],
23-
['conv2d_9.w_0','conv2d_10.w_0','conv2d_11.w_0','conv2d_12.w_0','conv2d_13.w_0','conv2d_14.w_0','conv2d_15.w_0'],
24-
['conv2d_16.w_0','conv2d_17.w_0','conv2d_18.w_0','conv2d_19.w_0','conv2d_20.w_0','conv2d_21.w_0'],
25-
['conv2d_22.w_0','conv2d_23.w_0','conv2d_24.w_0','conv2d_25.w_0','conv2d_26.w_0'],
26-
['conv2d_27.w_0','conv2d_28.w_0','conv2d_29.w_0','conv2d_30.w_0'],
27-
['conv2d_32.w_0','conv2d_34.w_0','conv2d_35.w_0','conv2d_37.w_0','conv2d_38.w_0','conv2d_39.w_0'],
28-
['conv2d_31.w_0'],
29-
['conv2d_33.w_0','conv2d_36.w_0','conv2d_40.w_0','conv2d_41.w_0'],
30-
['conv2d_42.w_0'],
31-
['conv2d_44.w_0','conv2d_47.w_0','conv2d_51.w_0','conv2d_52.w_0','conv2d_53.w_0','conv2d_54.w_0','conv2d_55.w_0','conv2d_56.w_0','conv2d_57.w_0','conv2d_58.w_0'],
32-
['conv2d_43.w_0','conv2d_45.w_0','conv2d_46.w_0','conv2d_49.w_0','conv2d_48.w_0','conv2d_50.w_0'],]

example/post_training_quantization/pytorch_yolo_series/fine_tune.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def argsparser():
4343
help="which device used to compress.")
4444
parser.add_argument(
4545
'--algo', type=str, default='avg', help="post quant algo.")
46-
parser.add_argument(
47-
'--round_type', type=str, default='adaround', help="round type.")
4846
parser.add_argument('--gpu', type=int, default=0, help='gpu index')
4947

5048
parser.add_argument(
@@ -59,6 +57,10 @@ def argsparser():
5957
help='simulate activation quant')
6058
parser.add_argument(
6159
'--epochs', type=int, default=20, help='steps to reconstruct')
60+
parser.add_argument(
61+
'--lr', type=float, default=0.1, help='learning rate of reconstruct')
62+
parser.add_argument(
63+
'--limit', type=int, default=5, help='size of each region')
6264

6365
return parser
6466

@@ -104,10 +106,11 @@ def main():
104106
weight_quantize_type='channel_wise_abs_max',
105107
recon_level=FLAGS.recon_level,
106108
simulate_activation_quant=FLAGS.simulate_activation_quant,
107-
regions=config['regions'],
108-
region_weights_names=config['region_weights_names'],
109+
regions=None,
110+
region_weights_names=None,
109111
epochs=FLAGS.epochs,
110-
lr=0.1)
112+
lr=FLAGS.lr,
113+
limit=FLAGS.limit)
111114

112115

113116
if __name__ == '__main__':

0 commit comments

Comments
 (0)