From 285f3a71f133278746e6d354bf6501132a8c1960 Mon Sep 17 00:00:00 2001 From: zhouzj <41366441+zzjjay@users.noreply.github.com> Date: Thu, 26 May 2022 17:50:41 +0800 Subject: [PATCH] [auto-compression] solve prediction problems and fix docs. (#1142) * solve prediction problems. * fix docs. --- demo/auto_compression/detection/README.md | 3 ++- .../image_classification/README.md | 3 ++- demo/auto_compression/nlp/README.md | 3 ++- .../semantic_segmentation/README.md | 3 ++- paddleslim/auto_compression/utils/predict.py | 20 +++++++++---------- .../auto_compression/utils/prune_model.py | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/demo/auto_compression/detection/README.md b/demo/auto_compression/detection/README.md index 4c7dcc2a..eb75ae20 100644 --- a/demo/auto_compression/detection/README.md +++ b/demo/auto_compression/detection/README.md @@ -45,7 +45,8 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -pip install paddleslim +https://github.com/PaddlePaddle/PaddleSlim.git +python setup.py install ``` 安装paddledet: diff --git a/demo/auto_compression/image_classification/README.md b/demo/auto_compression/image_classification/README.md index 1393e23b..f0b2224e 100644 --- a/demo/auto_compression/image_classification/README.md +++ b/demo/auto_compression/image_classification/README.md @@ -43,7 +43,8 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -pip install paddleslim +https://github.com/PaddlePaddle/PaddleSlim.git +python setup.py install ``` #### 3.2 准备数据集 diff --git a/demo/auto_compression/nlp/README.md b/demo/auto_compression/nlp/README.md index 06587000..3500cbf9 100644 --- a/demo/auto_compression/nlp/README.md +++ b/demo/auto_compression/nlp/README.md @@ -56,7 +56,8 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -pip install paddleslim +https://github.com/PaddlePaddle/PaddleSlim.git +python setup.py install ``` 安装paddlenlp: diff --git a/demo/auto_compression/semantic_segmentation/README.md b/demo/auto_compression/semantic_segmentation/README.md index a8d59299..5385dd5a 100644 --- a/demo/auto_compression/semantic_segmentation/README.md +++ b/demo/auto_compression/semantic_segmentation/README.md @@ -48,7 +48,8 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -pip install paddleslim +https://github.com/PaddlePaddle/PaddleSlim.git +python setup.py install ``` 安装paddleseg diff --git a/paddleslim/auto_compression/utils/predict.py b/paddleslim/auto_compression/utils/predict.py index d72369cb..0e268b84 100644 --- a/paddleslim/auto_compression/utils/predict.py +++ b/paddleslim/auto_compression/utils/predict.py @@ -27,9 +27,9 @@ def predict_compressed_model(model_dir, latency_dict(dict): The latency latency of the model under various compression strategies. """ local_rank = paddle.distributed.get_rank() - quant_model_path = f'quant_model/rank_{local_rank}' - prune_model_path = f'prune_model/rank_{local_rank}' - sparse_model_path = f'sparse_model/rank_{local_rank}' + quant_model_path = f'quant_model_rank_{local_rank}_tmp' + prune_model_path = f'prune_model_rank_{local_rank}_tmp' + sparse_model_path = f'sparse_model_rank_{local_rank}_tmp' latency_dict = {} @@ -116,7 +116,7 @@ def predict_compressed_model(model_dir, model_dir=sparse_model_path, model_filename=model_filename, params_filename=params_filename, - save_model_path='quant_model', + save_model_path=quant_model_path, quantizable_op_type=["conv2d", "depthwise_conv2d", "mul"], is_full_quantize=False, activation_bits=8, @@ -131,10 +131,10 @@ def predict_compressed_model(model_dir, latency_dict.update({f'sparse_{sparse_ratio}_int8': latency}) # NOTE: Delete temporary model files - if os.path.exists('quant_model'): - shutil.rmtree('quant_model', ignore_errors=True) - if os.path.exists('prune_model'): - shutil.rmtree('prune_model', ignore_errors=True) - if os.path.exists('sparse_model'): - shutil.rmtree('sparse_model', ignore_errors=True) + if os.path.exists(quant_model_path): + shutil.rmtree(quant_model_path, ignore_errors=True) + if os.path.exists(prune_model_path): + shutil.rmtree(prune_model_path, ignore_errors=True) + if os.path.exists(sparse_model_path): + shutil.rmtree(sparse_model_path, ignore_errors=True) return latency_dict diff --git a/paddleslim/auto_compression/utils/prune_model.py b/paddleslim/auto_compression/utils/prune_model.py index b9e27fa0..5152d06a 100644 --- a/paddleslim/auto_compression/utils/prune_model.py +++ b/paddleslim/auto_compression/utils/prune_model.py @@ -122,7 +122,7 @@ def get_prune_model(model_file, param_file, ratio, save_path): main_prog = static.Program() startup_prog = static.Program() place = paddle.CPUPlace() - exe = paddle.static.Executor() + exe = paddle.static.Executor(place) scope = static.global_scope() exe.run(startup_prog) -- GitLab