Skip to content

Commit

Permalink
Fix auto-compression demo (PaddlePaddle#1035)
Browse files Browse the repository at this point in the history
* fix

* fix ac demo
  • Loading branch information
ceci3 committed Apr 8, 2022
1 parent 8386960 commit 3cf6116
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions demo/auto-compression/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ python tools/export_model.py \
```
cd PaddleSlim/demo/auto-compression/
```
使用[eval.py](../quant_post/eval.py)脚本得到模型的分类精度:
使用[eval.py](../quant/quant_post/eval.py)脚本得到模型的分类精度:
```
python ../quant_post/eval.py --model_path infermodel_mobilenetv2 --model_name inference.pdmodel --params_name inference.pdiparams
python ../quant/quant_post/eval.py --model_path infermodel_mobilenetv2 --model_name inference.pdmodel --params_name inference.pdiparams
```
精度输出为:
```
Expand Down
2 changes: 1 addition & 1 deletion demo/auto-compression/configs/CV/mbv2_qat_dis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Distillation:
- teacher_linear_1.tmp_0
- linear_1.tmp_0
merge_feed: true
teacher_model_dir: ./MobileNetV2_ssld_infer
teacher_model_dir: ./infermodel_mobilenetv2
teacher_model_filename: inference.pdmodel
teacher_params_filename: inference.pdiparams
Quantization:
Expand Down
2 changes: 1 addition & 1 deletion demo/auto-compression/configs/NLP/bert_asp_dis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Distillation:
- teacher_linear_147.tmp_1
- linear_147.tmp_1
merge_feed: true
teacher_model_dir: ../auto-compression_origin/static_bert_models
teacher_model_dir: static_bert_models
teacher_model_filename: bert.pdmodel
teacher_params_filename: bert.pdiparams
Prune:
Expand Down
8 changes: 5 additions & 3 deletions demo/auto-compression/run_gelu.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
python3.7 demo_glue.py --config_path ./configs/NLP/bert_qat_dis.yaml --task 'sst-2' \
--model_dir='../auto-compression_origin/static_bert_models/' \
python3.7 demo_glue.py \
--model_dir='./static_bert_models/' \
--model_filename='bert.pdmodel' \
--params_filename='bert.pdiparams' \
--save_dir='./save_asp_bert/' \
--devices='gpu' \
--devices='cpu' \
--batch_size=32 \
--task='sst-2' \
--config_path='./configs/NLP/bert_asp_dis.yaml'
9 changes: 5 additions & 4 deletions demo/auto-compression/run_imagenet.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
python3.7 demo_imagenet.py --config_path ./configs/CV/mbv2_ptq_hpo.yaml \
--model_dir='../auto-compression_origin/MobileNetV2_ssld_infer/' \
python3.7 demo_imagenet.py \
--model_dir='infermodel_mobilenetv2' \
--model_filename='inference.pdmodel' \
--params_filename='./inference.pdiparams' \
--save_dir='./save_qat_mbv2/' \
--devices='gpu' \
--batch_size=64 \
--devices='cpu' \
--batch_size=2 \
--config_path='./configs/CV/mbv2_ptq_hpo.yaml'
2 changes: 2 additions & 0 deletions demo/quant/quant_post/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import paddle
sys.path[0] = os.path.join(
os.path.dirname("__file__"), os.path.pardir, os.path.pardir)
sys.path[1] = os.path.join(
os.path.dirname("__file__"), os.path.pardir)
import imagenet_reader as reader
from utility import add_arguments, print_arguments

Expand Down
1 change: 1 addition & 0 deletions paddleslim/auto_compression/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def compress(self):

### used to check whether the dataloader is right
if self.eval_function is not None and self.train_config.origin_metric is not None:
_logger.info("start to test metric before compress")
metric = self.eval_function(self._exe, inference_program,
feed_target_names, fetch_targets)
_logger.info("metric of compressed model is: {}".format(metric))
Expand Down

0 comments on commit 3cf6116

Please sign in to comment.