From 48db9a8c5b01b36492798037f6cad9e71758f905 Mon Sep 17 00:00:00 2001 From: shangliang Xu Date: Mon, 18 Oct 2021 19:45:00 +0800 Subject: [PATCH] [ce tests] add kl to ce (#4311) --- .../slim/post_quant/ppyolo_r50vd_dcn_ptq.yml | 10 ++++ .../slim/post_quant/yolov3_darknet53_ptq.yml | 10 ++++ .../ppyolo_mbv3_large_coco_params.txt | 4 +- .../ppyolo_r50vd_dcn_1x_coco_params.txt | 4 +- .../yolov3_darknet53_270e_coco_params.txt | 4 +- tests/prepare.sh | 1 + tests/test.sh | 60 ++++++++++++------- 7 files changed, 65 insertions(+), 28 deletions(-) create mode 100644 configs/slim/post_quant/ppyolo_r50vd_dcn_ptq.yml create mode 100644 configs/slim/post_quant/yolov3_darknet53_ptq.yml diff --git a/configs/slim/post_quant/ppyolo_r50vd_dcn_ptq.yml b/configs/slim/post_quant/ppyolo_r50vd_dcn_ptq.yml new file mode 100644 index 000000000..e829d2715 --- /dev/null +++ b/configs/slim/post_quant/ppyolo_r50vd_dcn_ptq.yml @@ -0,0 +1,10 @@ +weights: https://paddledet.bj.bcebos.com/models/ppyolo_r50vd_dcn_1x_coco.pdparams +slim: PTQ + +PTQ: + ptq_config: { + 'activation_quantizer': 'HistQuantizer', + 'upsample_bins': 127, + 'hist_percent': 0.999} + quant_batch_num: 10 + fuse: True diff --git a/configs/slim/post_quant/yolov3_darknet53_ptq.yml b/configs/slim/post_quant/yolov3_darknet53_ptq.yml new file mode 100644 index 000000000..7715b082a --- /dev/null +++ b/configs/slim/post_quant/yolov3_darknet53_ptq.yml @@ -0,0 +1,10 @@ +weights: https://paddledet.bj.bcebos.com/models/yolov3_darknet53_270e_coco.pdparams +slim: PTQ + +PTQ: + ptq_config: { + 'activation_quantizer': 'HistQuantizer', + 'upsample_bins': 127, + 'hist_percent': 0.999} + quant_batch_num: 10 + fuse: True diff --git a/tests/ppdet_params/ppyolo_mbv3_large_coco_params.txt b/tests/ppdet_params/ppyolo_mbv3_large_coco_params.txt index fc0bcd772..e91713148 100644 --- a/tests/ppdet_params/ppyolo_mbv3_large_coco_params.txt +++ b/tests/ppdet_params/ppyolo_mbv3_large_coco_params.txt @@ -31,11 +31,11 @@ norm_export:tools/export_model.py -c configs/ppyolo/ppyolo_mbv3_large_coco.yml - quant_export:tools/export_model.py -c configs/ppyolo/ppyolo_mbv3_large_coco.yml --slim_config configs/slim/quant/ppyolo_mbv3_large_qat.yml -o fpgm_export:tools/export_model.py -c configs/ppyolo/ppyolo_mbv3_large_coco.yml --slim_config configs/slim/prune/ppyolo_mbv3_large_prune_fpgm.yml -o distill_export:null -export1:null +kl_quant:tools/post_quant.py -c configs/ppyolo/ppyolo_mbv3_large_coco.yml --slim_config configs/slim/post_quant/ppyolo_mbv3_large_ptq.yml -o export2:null ## infer_model:ppyolo_mbv3_large_coco.pdparams|ppyolo_mbv3_large_qat.pdparams|ppyolo_mbv3_large_prune_fpgm.pdparams -infer_export:./tests/weights|./tests/weights|./tests/weights +infer_model_dir:./tests/weights infer_quant:False|True|False inference:deploy/python/infer.py --device:gpu|cpu diff --git a/tests/ppdet_params/ppyolo_r50vd_dcn_1x_coco_params.txt b/tests/ppdet_params/ppyolo_r50vd_dcn_1x_coco_params.txt index 3e3ab0b04..d30124491 100644 --- a/tests/ppdet_params/ppyolo_r50vd_dcn_1x_coco_params.txt +++ b/tests/ppdet_params/ppyolo_r50vd_dcn_1x_coco_params.txt @@ -31,11 +31,11 @@ norm_export:tools/export_model.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml quant_export:tools/export_model.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml --slim_config configs/slim/quant/ppyolo_r50vd_qat_pact.yml -o fpgm_export:tools/export_model.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml --slim_config configs/slim/prune/ppyolo_r50vd_prune_fpgm.yml -o distill_export:null -export1:null +kl_quant:tools/post_quant.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml --slim_config configs/slim/post_quant/ppyolo_r50vd_dcn_ptq.yml -o export2:null ## infer_model:ppyolo_r50vd_dcn_1x_coco.pdparams|ppyolo_r50vd_qat_pact.pdparams|ppyolo_r50vd_prune_fpgm.pdparams -infer_export:./tests/weights|./tests/weights|./tests/weights +infer_model_dir:./tests/weights infer_quant:False|True|False inference:deploy/python/infer.py --device:gpu|cpu diff --git a/tests/ppdet_params/yolov3_darknet53_270e_coco_params.txt b/tests/ppdet_params/yolov3_darknet53_270e_coco_params.txt index 42fd225b7..a4be4ae5d 100644 --- a/tests/ppdet_params/yolov3_darknet53_270e_coco_params.txt +++ b/tests/ppdet_params/yolov3_darknet53_270e_coco_params.txt @@ -31,11 +31,11 @@ norm_export:tools/export_model.py -c configs/yolov3/yolov3_darknet53_270e_coco.y quant_export:tools/export_model.py -c configs/yolov3/yolov3_darknet53_270e_coco.yml --slim_config configs/slim/quant/yolov3_darknet_qat.yml -o fpgm_export:tools/export_model.py -c configs/yolov3/yolov3_darknet53_270e_coco.yml --slim_config configs/slim/prune/yolov3_darknet_prune_fpgm.yml -o distill_export:null -export1:null +kl_quant:tools/post_quant.py -c configs/yolov3/yolov3_darknet53_270e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o export2:null ## infer_model:yolov3_darknet53_270e_coco.pdparams|yolov3_darknet_coco_qat.pdparams|yolov3_darknet_prune_fpgm.pdparams -infer_export:./tests/weights|./tests/weights|./tests/weights +infer_model_dir:./tests/weights infer_quant:False|True|False inference:deploy/python/infer.py --device:gpu|cpu diff --git a/tests/prepare.sh b/tests/prepare.sh index f01736d7d..96dc514e2 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -60,6 +60,7 @@ elif [ ${MODE} = "whole_infer" ];then cd ../../ && mkdir -p ./tests/demo/ cp -u dataset/coco/val2017/* ./tests/demo/ else + mv ./dataset/coco/download_coco.py . && rm -rf ./dataset/coco/* && mv ./download_coco.py ./dataset/coco/ # prepare infer data wget -nc -P ./dataset/coco/ https://paddledet.bj.bcebos.com/data/coco_ce.tar cd ./dataset/coco/ && tar -xvf coco_ce.tar && mv -u coco_ce/* . diff --git a/tests/test.sh b/tests/test.sh index 14e032dcc..c41c25d59 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -119,8 +119,8 @@ export_key2=$(func_parser_key "${lines[34]}") export_value2=$(func_parser_value "${lines[34]}") # parser inference model -infer_model_dir_list=$(func_parser_value "${lines[36]}") -infer_export_list=$(func_parser_value "${lines[37]}") +infer_model_name_list=$(func_parser_value "${lines[36]}") +infer_model_dir=$(func_parser_value "${lines[37]}") infer_is_quant=$(func_parser_value "${lines[38]}") # parser inference inference_py=$(func_parser_value "${lines[39]}") @@ -185,14 +185,13 @@ function func_inference(){ elif [ ${device} = "True" ] || [ ${device} = "gpu" ]; then for use_trt in ${use_trt_list[*]}; do for precision in ${precision_list[*]}; do - if [[ ${_flag_quant} = "False" ]] && [[ ${precision} =~ "int8" ]]; then - continue - fi - if [[ ${precision} =~ "fp16" || ${precision} =~ "int8" ]] && [ ${use_trt} = "False" ]; then - continue - fi - if [[ ${use_trt} = "False" || ${precision} =~ "int8" ]] && [ ${_flag_quant} = "True" ]; then - continue + if [[ ${precision} != "fluid" ]]; then + if [[ ${_flag_quant} = "False" ]] && [[ ${precision} = "trt_int8" ]]; then + continue + fi + if [[ ${_flag_quant} = "True" ]] && [[ ${precision} != "trt_int8" ]]; then + continue + fi fi for batch_size in ${batch_size_list[*]}; do _save_log_path="${_log_path}/infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" @@ -229,28 +228,45 @@ if [ ${MODE} = "infer" ]; then eval $env export Count=0 IFS="|" - infer_run_exports=(${infer_export_list}) infer_quant_flag=(${infer_is_quant}) set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") - for infer_model in ${infer_model_dir_list[*]}; do + set_save_infer_key=$(func_set_params "${save_infer_key}" "${infer_model_dir}") + infer_model="${infer_model_dir}/${train_param_value1}" + for infer_model_name in ${infer_model_name_list[*]}; do # run export - if [ ${infer_run_exports[Count]} != "null" ];then - set_export_weight=$(func_set_params "${export_weight}" "${infer_run_exports[Count]}/${infer_model}") - set_save_infer_key=$(func_set_params "${save_infer_key}" "${infer_run_exports[Count]}") - export_cmd="${python} ${norm_export} ${set_export_weight} ${set_train_params1} ${set_save_infer_key}" - eval $export_cmd - status_export=$? - if [ ${status_export} = 0 ];then - status_check $status_export "${export_cmd}" "${status_log}" - fi + case ${Count} in + 0) run_export=${norm_export} ;; + 1) run_export=${pact_export} ;; + 2) run_export=${fpgm_export} ;; + *) echo "Undefined run_export"; exit 1; + esac + set_export_weight=$(func_set_params "${export_weight}" "${infer_model_dir}/${infer_model_name}") + export_cmd="${python} ${run_export} ${set_export_weight} ${set_train_params1} ${set_save_infer_key}" + eval $export_cmd + status_export=$? + if [ ${status_export} = 0 ];then + status_check $status_export "${export_cmd}" "${status_log}" fi #run inference is_quant=${infer_quant_flag[Count]} - infer_model="${infer_run_exports[Count]}/${train_param_value1}" func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" ${is_quant} Count=$(($Count + 1)) done + # kl quant + if [ ${export_key1} = "kl_quant" ]; then + # run kl quant + kl_cmd="${python} ${export_value1} ${set_train_params1} ${set_save_infer_key}" + eval $kl_cmd + status_export=$? + if [ ${status_export} = 0 ];then + status_check $status_export "${kl_cmd}" "${status_log}" + fi + # run inference + is_quant=True + func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" ${is_quant} + fi + else IFS="|" export Count=0 -- GitLab