From 29eb61ece6a69fbdf9652c146ac2307d57ce30f7 Mon Sep 17 00:00:00 2001 From: ceci3 Date: Wed, 6 Jul 2022 19:07:08 +0800 Subject: [PATCH] cancel opt_model in requirement.txt (#1261) --- example/auto_compression/README.md | 17 ++++++++++++-- example/auto_compression/detection/README.md | 5 ++-- .../image_classification/README.md | 5 ++-- example/auto_compression/nlp/README.md | 5 ++-- .../pytorch_huggingface/README.md | 5 ++-- .../auto_compression/pytorch_yolov5/README.md | 5 ++-- .../semantic_segmentation/README.md | 5 ++-- .../tensorflow_mobilenet/README.md | 5 ++-- paddleslim/analysis/latency_predictor.py | 23 +++++++++++++++++++ paddleslim/auto_compression/utils/predict.py | 7 +++++- requirements.txt | 1 - 11 files changed, 58 insertions(+), 25 deletions(-) diff --git a/example/auto_compression/README.md b/example/auto_compression/README.md index b761402f..bf81e069 100644 --- a/example/auto_compression/README.md +++ b/example/auto_compression/README.md @@ -9,8 +9,21 @@ PaddleSlim推出全新自动化压缩工具(ACT),旨在通过Source-Free ## 环境准备 -- 安装PaddlePaddle >= 2.3版本 (从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- 安装PaddleSlim develop版本 +- 安装PaddlePaddle >= 2.3 (从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) +- 安装PaddleSlim >=2.3 + +(1)安装paddlepaddle: +```shell +# CPU +pip install paddlepaddle +# GPU +pip install paddlepaddle-gpu +``` + +(2)安装paddleslim: +```shell +pip install paddleslim +``` ## 快速上手 diff --git a/example/auto_compression/detection/README.md b/example/auto_compression/detection/README.md index c625eb1c..2126bd66 100644 --- a/example/auto_compression/detection/README.md +++ b/example/auto_compression/detection/README.md @@ -32,7 +32,7 @@ #### 3.1 准备环境 - PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim develop版本 +- PaddleSlim >= 2.3 - PaddleDet >= 2.4 - opencv-python @@ -46,8 +46,7 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -https://github.com/PaddlePaddle/PaddleSlim.git -python setup.py install +pip install paddleslim ``` 安装paddledet: diff --git a/example/auto_compression/image_classification/README.md b/example/auto_compression/image_classification/README.md index 4332dad0..9ecab9ce 100644 --- a/example/auto_compression/image_classification/README.md +++ b/example/auto_compression/image_classification/README.md @@ -56,7 +56,7 @@ - python >= 3.6 - PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim develop版本 +- PaddleSlim >= 2.3 安装paddlepaddle: ```shell @@ -68,8 +68,7 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -https://github.com/PaddlePaddle/PaddleSlim.git -python setup.py install +pip install paddleslim ``` #### 3.2 准备数据集 diff --git a/example/auto_compression/nlp/README.md b/example/auto_compression/nlp/README.md index fd83f8de..347fcd80 100644 --- a/example/auto_compression/nlp/README.md +++ b/example/auto_compression/nlp/README.md @@ -48,7 +48,7 @@ #### 3.1 准备环境 - python >= 3.6 - PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim develop版本 +- PaddleSlim >= 2.3 - PaddleNLP >= 2.3 安装paddlepaddle: @@ -61,8 +61,7 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -https://github.com/PaddlePaddle/PaddleSlim.git -python setup.py install +pip install paddleslim ``` 安装paddlenlp: diff --git a/example/auto_compression/pytorch_huggingface/README.md b/example/auto_compression/pytorch_huggingface/README.md index d2cdd87b..730fd584 100644 --- a/example/auto_compression/pytorch_huggingface/README.md +++ b/example/auto_compression/pytorch_huggingface/README.md @@ -44,7 +44,7 @@ #### 3.1 准备环境 - python >= 3.6 - PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim develop版本或PaddleSlim>=2.3.0 +- PaddleSlim >= 2.3 - X2Paddle develop版本 - transformers >= 4.18.0 - PaddleNLP >= 2.3 @@ -62,8 +62,7 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -git clone https://github.com/PaddlePaddle/PaddleSlim.git -python setup.py install +pip install paddleslim ``` 安装X2Paddle: diff --git a/example/auto_compression/pytorch_yolov5/README.md b/example/auto_compression/pytorch_yolov5/README.md index b6078db1..8afab4cf 100644 --- a/example/auto_compression/pytorch_yolov5/README.md +++ b/example/auto_compression/pytorch_yolov5/README.md @@ -33,7 +33,7 @@ #### 3.1 准备环境 - PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim develop版本 +- PaddleSlim >= 2.3 - PaddleDet >= 2.4 - [X2Paddle](https://github.com/PaddlePaddle/X2Paddle) >= 1.3.6 - opencv-python @@ -48,8 +48,7 @@ pip install paddlepaddle-gpu (2)安装paddleslim: ```shell -https://github.com/PaddlePaddle/PaddleSlim.git -python setup.py install +pip install paddleslim ``` (3)安装paddledet: diff --git a/example/auto_compression/semantic_segmentation/README.md b/example/auto_compression/semantic_segmentation/README.md index d6767627..1cf82cb0 100644 --- a/example/auto_compression/semantic_segmentation/README.md +++ b/example/auto_compression/semantic_segmentation/README.md @@ -58,7 +58,7 @@ #### 3.1 准备环境 - PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim develop版本 +- PaddleSlim >= 2.3 - PaddleSeg >= 2.5 安装paddlepaddle: @@ -71,8 +71,7 @@ pip install paddlepaddle-gpu 安装paddleslim: ```shell -https://github.com/PaddlePaddle/PaddleSlim.git -python setup.py install +pip install paddleslim ``` 安装paddleseg diff --git a/example/auto_compression/tensorflow_mobilenet/README.md b/example/auto_compression/tensorflow_mobilenet/README.md index 7a2dca21..0a41d6e9 100644 --- a/example/auto_compression/tensorflow_mobilenet/README.md +++ b/example/auto_compression/tensorflow_mobilenet/README.md @@ -32,7 +32,7 @@ #### 3.1 准备环境 - PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim develop版本 +- PaddleSlim >= 2.3 - [X2Paddle](https://github.com/PaddlePaddle/X2Paddle) >= 1.3.6 - opencv-python @@ -46,8 +46,7 @@ pip install paddlepaddle-gpu (2)安装paddleslim: ```shell -https://github.com/PaddlePaddle/PaddleSlim.git -python setup.py install +pip install paddleslim ``` (3)安装TensorFlow: diff --git a/paddleslim/analysis/latency_predictor.py b/paddleslim/analysis/latency_predictor.py index c6747511..3c90f22b 100644 --- a/paddleslim/analysis/latency_predictor.py +++ b/paddleslim/analysis/latency_predictor.py @@ -15,6 +15,9 @@ # limitations under the License. import os +import pip +import platform +import logging import pickle import shutil import subprocess @@ -25,9 +28,12 @@ import paddle from .parse_ops import get_key_from_op from .extract_features import get_data_from_tables, get_features_from_paramkey from ._utils import opt_model, load_predictor, nearest_interpolate, _get_download +from ..common import get_logger from ..core import GraphWrapper __all__ = ["LatencyPredictor", "TableLatencyPredictor"] +_logger = get_logger(__name__, level=logging.INFO) + TABLE_URL = 'https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/' @@ -71,6 +77,7 @@ class TableLatencyPredictor(LatencyPredictor): hardware_list = ['SD625', 'SD710', 'RK3288'] def __init__(self, table_file='SD710'): + self._check_opt_model() self.table_file = table_file self.table_dict = {} self.hardware = None @@ -83,6 +90,22 @@ class TableLatencyPredictor(LatencyPredictor): def add_hardware(cls, hardware): cls.hardware_list.append(hardware) + def _check_opt_model(self): + if platform.system().lower() == 'windows': + raise NotImplementedError( + 'latency predictor does NOT support running on Windows.') + elif platform.system().lower() == 'darwin': + py_verion = platform.python_version().split('.') + if int(py_version[0]) != 3 or int(py_version[1]) != 9: + raise NotImplementedError( + 'latency predictor does NOT support running on macOS when python version is not 3.9.' + ) + + _logger.info("pip install paddleslim-opt-tools") + out = shutil.which('paddle_lite_opt') + if out is None: + pip.main(['install', 'paddleslim-opt-tools']) + def _initial_table(self): if self.table_file in TableLatencyPredictor.hardware_list: self.hardware = self.table_file diff --git a/paddleslim/auto_compression/utils/predict.py b/paddleslim/auto_compression/utils/predict.py index 8fd852b3..01ef6a90 100644 --- a/paddleslim/auto_compression/utils/predict.py +++ b/paddleslim/auto_compression/utils/predict.py @@ -62,7 +62,12 @@ def predict_compressed_model(executor, model_file = os.path.join(model_dir, model_filename) param_file = os.path.join(model_dir, params_filename) - predictor = TableLatencyPredictor(hardware) + try: + predictor = TableLatencyPredictor(hardware) + except NotImplementedError: + raise NotImplementedError( + "Latency predictor cannot used on the platform: {}. That means you can not use latency predictor to select compress strategy automatically, you can set deploy_hardware to None or set compress strategy in the yaml". + format(platform.system())) latency = predictor.predict( model_file=model_file, param_file=param_file, data_type='fp32') latency_dict.update({'origin_fp32': latency}) diff --git a/requirements.txt b/requirements.txt index 2f9bde46..8ed081ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,3 @@ pillow pyyaml scikit-learn smac -paddleslim-opt-tools -- GitLab