From 490c1f7fea0cb65478df3ce0becc3b18dbe6d42c Mon Sep 17 00:00:00 2001 From: ceci3 Date: Sat, 21 May 2022 10:18:48 +0800 Subject: [PATCH] update readme (#1129) * update readme * update * update * remove cv2 * update * update --- README.md | 9 +++++++++ demo/auto_compression/README.md | 4 ++-- demo/auto_compression/detection/README.md | 4 ++-- .../image_classification/README.md | 4 ++-- demo/auto_compression/nlp/README.md | 4 ++-- .../semantic_segmentation/README.md | 4 ++-- demo/dygraph/pruning/imagenet.py | 1 - docs/zh_cn/FAQ/quantization_FAQ.md | 16 ++++++++-------- paddleslim/auto_compression/auto_strategy.py | 4 ++-- paddleslim/auto_compression/compressor.py | 13 +++++++++---- paddleslim/common/patterns_common.py | 4 ++-- paddleslim/nas/ofa/layers_old.py | 12 ++++++------ paddleslim/quant/quant_post_hpo.py | 1 - paddleslim/version.py | 17 ----------------- requirements.txt | 2 -- setup.py | 3 ++- 16 files changed, 48 insertions(+), 54 deletions(-) delete mode 100644 paddleslim/version.py diff --git a/README.md b/README.md index e3164246..1cf4a682 100755 --- a/README.md +++ b/README.md @@ -163,6 +163,12 @@ pip install paddleslim -i https://pypi.tuna.tsinghua.edu.cn/simple pip install paddleslim==2.3.0 -i https://pypi.tuna.tsinghua.edu.cn/simple ``` +安装develop版本: +```bash +git clone https://github.com/PaddlePaddle/PaddleSlim.git & cd PaddleSlim +python setup.py install +``` + ### 快速开始 @@ -269,6 +275,9 @@ pip install paddleslim==2.3.0 -i https://pypi.tuna.tsinghua.edu.cn/simple ### [FAQ](docs/zh_cn/FAQ/quantization_FAQ.md) +#### 1. 量化训练或者离线量化后的模型体积为什么没有变小? +答:这是因为量化后保存的参数是虽然是int8范围,但是类型是float。这是因为Paddle训练前向默认的Kernel不支持INT8 Kernel实现,只有Paddle Inference TensorRT的推理才支持量化推理加速。为了方便量化后验证量化精度,使用Paddle训练前向能加载此模型,默认保存的Float32类型权重,体积没有发生变换。 + ## 许可证书 本项目的发布受[Apache 2.0 license](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/LICENSE)许可认证。 diff --git a/demo/auto_compression/README.md b/demo/auto_compression/README.md index 31b8686a..a0a9695b 100644 --- a/demo/auto_compression/README.md +++ b/demo/auto_compression/README.md @@ -9,8 +9,8 @@ PaddleSlim推出全新自动化压缩工具(ACT),旨在通过Source-Free ## 环境准备 -- 安装PaddlePaddle >= 2.2版本 (从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- 安装PaddleSlim >= 2.3 或者适当develop版本 +- 安装PaddlePaddle >= 2.3版本 (从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) +- 安装PaddleSlim develop版本 ## 快速上手 diff --git a/demo/auto_compression/detection/README.md b/demo/auto_compression/detection/README.md index 93c0f6f8..e1777ce6 100644 --- a/demo/auto_compression/detection/README.md +++ b/demo/auto_compression/detection/README.md @@ -31,8 +31,8 @@ ## 3. 自动压缩流程 #### 3.1 准备环境 -- PaddlePaddle >= 2.2 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim >= 2.3 或者适当develop版本 +- PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) +- PaddleSlim develop版本 - PaddleDet >= 2.4 安装paddlepaddle: diff --git a/demo/auto_compression/image_classification/README.md b/demo/auto_compression/image_classification/README.md index bf3eeaf4..1192620b 100644 --- a/demo/auto_compression/image_classification/README.md +++ b/demo/auto_compression/image_classification/README.md @@ -30,8 +30,8 @@ #### 3.1 准备环境 - python >= 3.6 -- PaddlePaddle >= 2.2 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim >= 2.3 或者适当develop版本 +- PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) +- PaddleSlim develop版本 安装paddlepaddle: ```shell diff --git a/demo/auto_compression/nlp/README.md b/demo/auto_compression/nlp/README.md index 625b4020..891425e1 100644 --- a/demo/auto_compression/nlp/README.md +++ b/demo/auto_compression/nlp/README.md @@ -42,8 +42,8 @@ PP-MiniLM是一个6层的预训练中文小模型,使用PaddleNLP中```from_pr #### 3.1 准备环境 - python >= 3.6 -- PaddlePaddle >= 2.2 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim >= 2.3 或者适当develop版本 +- PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) +- PaddleSlim develop版本 - PaddleNLP >= 2.3 安装paddlepaddle: diff --git a/demo/auto_compression/semantic_segmentation/README.md b/demo/auto_compression/semantic_segmentation/README.md index f8d25072..455227ac 100644 --- a/demo/auto_compression/semantic_segmentation/README.md +++ b/demo/auto_compression/semantic_segmentation/README.md @@ -34,8 +34,8 @@ #### 3.1 准备环境 -- PaddlePaddle >= 2.2 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) -- PaddleSlim >= 2.3 或者适当develop版本 +- PaddlePaddle >= 2.3 (可从[Paddle官网](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html)下载安装) +- PaddleSlim develop版本 - PaddleSeg >= 2.5 安装paddlepaddle: diff --git a/demo/dygraph/pruning/imagenet.py b/demo/dygraph/pruning/imagenet.py index f6ff26f2..1c7ca57d 100644 --- a/demo/dygraph/pruning/imagenet.py +++ b/demo/dygraph/pruning/imagenet.py @@ -13,7 +13,6 @@ # limitations under the License. import os -import cv2 import math import random import numpy as np diff --git a/docs/zh_cn/FAQ/quantization_FAQ.md b/docs/zh_cn/FAQ/quantization_FAQ.md index 24a9dead..e461229a 100644 --- a/docs/zh_cn/FAQ/quantization_FAQ.md +++ b/docs/zh_cn/FAQ/quantization_FAQ.md @@ -1,7 +1,7 @@ ## 量化FAQ 1. 量化训练或者离线量化后的模型体积为什么没有变小? -2. 量化训练或者离线量化后的模型使用fluid加载为什么没有加速?怎样才能加速? +2. 量化训练或者离线量化后的模型使用paddle加载为什么没有加速?怎样才能加速? 3. 该怎么设置适合的量化配置? 4. 离线量化出现'KeyError: '报错 5. 离线量化或者量化训练时出现CUDNN或者CUDA错误 @@ -10,17 +10,17 @@ #### 1. 量化训练或者离线量化后的模型体积为什么没有变小? -答:这是因为量化后保存的参数是虽然是int8范围,但是类型是float。这是由于fluid没有int8 kernel, 为了方便量化后验证量化精度,必须能让fluid能够加载。 +答:这是因为量化后保存的参数是虽然是int8范围,但是类型是float。这是因为Paddle训练前向默认的Kernel不支持INT8 Kernel实现,只有Paddle Inference TensorRT的推理才支持量化推理加速。为了方便量化后验证量化精度,使用Paddle训练前向能加载此模型,默认保存的Float32类型权重,体积没有发生变换。 -#### 2. 量化训练或者离线量化后的模型使用fluid加载为什么没有加速?怎样才能加速? +#### 2. 量化训练或者离线量化后的模型使用paddle加载为什么没有加速?怎样才能加速? -答:这是因为量化后保存的参数是虽然是int8范围,但是类型是float。fluid并不具备加速量化模型的能力。量化模型必须配合使用预测库才能加速。 +答:这是因为量化后保存的参数是虽然是Int8范围,但是类型是Float32。Paddle训练前向默认的Kernel并不具备加速量化模型的能力。量化模型必须配合使用支持Int8计算的的预测库才能加速。 -- 如果量化模型在ARM上线,则需要使用[Paddle-Lite](https://paddle-lite.readthedocs.io/zh/latest/index.html). +- 如果量化模型在ARM上线,则需要使用[Paddle Lite](https://paddle-lite.readthedocs.io/zh/latest/index.html). - - Paddle-Lite会对量化模型进行模型转化和优化,转化方法见[链接](https://paddle-lite.readthedocs.io/zh/latest/index.html#sec-user-guides)。 + - Paddle Lite会对量化模型进行模型转化和优化,转化方法见[链接](https://paddle-lite.readthedocs.io/zh/latest/index.html#sec-user-guides)。 - - 转化之后可以像非量化模型一样使用[Paddle-Lite API](https://paddle-lite.readthedocs.io/zh/latest/index.html)进行加载预测。 + - 转化之后可以像非量化模型一样使用[Paddle Lite API](https://paddle-lite.readthedocs.io/zh/latest/index.html)进行加载预测。 - 如果量化模型在GPU上线,则需要使用[Paddle-TensorRT 预测接口](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/advanced_guide/performance_improving/inference_improving/paddle_tensorrt_infer.html). @@ -48,7 +48,7 @@ config->EnableTensorRtEngine(1 << 20 /* workspace_size*/, | 平台 | 支持weight量化方式 | 支持activation量化方式 | 支持量化的OP | | ---------------- | ------------------------------ | ------------------------------------- | ------------------------------------------------------------ | - | ARM(Paddle-Lite) | channel_wise_abs_max, abs_max | moving_average_abs_max,range_abs_max | conv2d, depthwise_conv2d, mul | + | ARM(Paddle Lite) | channel_wise_abs_max, abs_max | moving_average_abs_max,range_abs_max | conv2d, depthwise_conv2d, mul | | x86(MKL-DNN) | abs_max | moving_average_abs_max,range_abs_max | conv2d, depthwise_conv2d, mul, matmul | | GPU(TensorRT) | channel_wise_abs_max | moving_average_abs_max,range_abs_max | mul, conv2d, pool2d, depthwise_conv2d, elementwise_add, leaky_relu | diff --git a/paddleslim/auto_compression/auto_strategy.py b/paddleslim/auto_compression/auto_strategy.py index 10e8d4d8..c0311fac 100644 --- a/paddleslim/auto_compression/auto_strategy.py +++ b/paddleslim/auto_compression/auto_strategy.py @@ -71,8 +71,8 @@ EXPERIENCE_STRATEGY_WITHOUT_LOSS = [ 'prune_0.3_int8' ] MAGIC_SPARSE_RATIO = 0.75 -### TODO: 0.03 threshold maybe not suitable, need to check -MAGIC_MAX_EMD_DISTANCE = 0.03 +### TODO: 0.02 threshold maybe not suitable, need to check +MAGIC_MAX_EMD_DISTANCE = 0.02 MAGIC_MIN_EMD_DISTANCE = 0.01 DEFAULT_TRANSFORMER_STRATEGY = 'prune_0.25_int8' diff --git a/paddleslim/auto_compression/compressor.py b/paddleslim/auto_compression/compressor.py index bcd0e4c0..70f81108 100644 --- a/paddleslim/auto_compression/compressor.py +++ b/paddleslim/auto_compression/compressor.py @@ -18,12 +18,11 @@ import sys import numpy as np import inspect import shutil -from collections import namedtuple, Iterable +from collections import namedtuple +from collections.abc import Iterable import platform import paddle import paddle.distributed.fleet as fleet -if platform.system().lower() == 'linux': - from ..quant import quant_post_hpo from ..quant.quanter import convert, quant_post from ..common.recover_program import recover_inference_program from ..common import get_logger @@ -35,6 +34,12 @@ from .auto_strategy import prepare_strategy, get_final_quant_config, create_stra _logger = get_logger(__name__, level=logging.INFO) +try: + if platform.system().lower() == 'linux': + from ..quant.quant_post_hpo import quant_post_hpo +except Exception as e: + _logger.warning(e) + class AutoCompression: def __init__(self, @@ -113,7 +118,7 @@ class AutoCompression: self.train_dataloader = train_dataloader self.target_speedup = target_speedup self.eval_function = eval_callback - self.eval_dataloader = eval_dataloader + self.eval_dataloader = eval_dataloader if eval_dataloader is not None else train_dataloader paddle.enable_static() diff --git a/paddleslim/common/patterns_common.py b/paddleslim/common/patterns_common.py index 8e6699b2..9f3951df 100644 --- a/paddleslim/common/patterns_common.py +++ b/paddleslim/common/patterns_common.py @@ -99,8 +99,8 @@ def _find_next_target_op(op, graph, target_op_idx, sc_path): def is_shortcut(op, graph, sc_path, shortcut_start_op): """ - op /```````````````````\ add - \____op1___op2__..._/ + op /```````````````````\\ add + \\____op1___op2__..._/ """ inps = op.all_inputs() pre_ops = graph.pre_ops(op) diff --git a/paddleslim/nas/ofa/layers_old.py b/paddleslim/nas/ofa/layers_old.py index 73dad7f7..33d648c0 100644 --- a/paddleslim/nas/ofa/layers_old.py +++ b/paddleslim/nas/ofa/layers_old.py @@ -116,7 +116,7 @@ class SuperConv2D(fluid.dygraph.Conv2D): of conv2d. If it is set to None or one attribute of ParamAttr, conv2d will create ParamAttr as param_attr. If the Initializer of the param_attr is not set, the parameter is initialized with :math:`Normal(0.0, std)`, - and the :math:`std` is :math:`(\\frac{2.0 }{filter\_elem\_num})^{0.5}`. Default: None. + and the :math:`std` is :math:`(\\frac{2.0 }{filter\\_elem\\_num})^{0.5}`. Default: None. bias_attr (ParamAttr or bool, optional): The attribute for the bias of conv2d. If it is set to False, no bias will be added to the output units. If it is set to None or one attribute of ParamAttr, conv2d @@ -374,7 +374,7 @@ class SuperConv2DTranspose(fluid.dygraph.Conv2DTranspose): `conv2dtranspose `_ . For each input :math:`X`, the equation is: .. math:: - Out = \sigma (W \\ast X + b) + Out = \\sigma (W \\ast X + b) Where: * :math:`X`: Input value, a ``Tensor`` with NCHW format. * :math:`W`: Filter value, a ``Tensor`` with shape [MCHW] . @@ -390,10 +390,10 @@ class SuperConv2DTranspose(fluid.dygraph.Conv2DTranspose): Output shape: :math:`(N, C_{out}, H_{out}, W_{out})` Where .. math:: - H^\prime_{out} &= (H_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (H_f - 1) + 1 \\\\ - W^\prime_{out} &= (W_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (W_f - 1) + 1 \\\\ - H_{out} &\in [ H^\prime_{out}, H^\prime_{out} + strides[0] ) \\\\ - W_{out} &\in [ W^\prime_{out}, W^\prime_{out} + strides[1] ) + H^\\prime_{out} &= (H_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (H_f - 1) + 1 \\\\ + W^\\prime_{out} &= (W_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (W_f - 1) + 1 \\\\ + H_{out} &\\in [ H^\\prime_{out}, H^\\prime_{out} + strides[0] ) \\\\ + W_{out} &\\in [ W^\\prime_{out}, W^\\prime_{out} + strides[1] ) Parameters: num_channels(int): The number of channels in the input image. num_filters(int): The number of the filter. It is as same as the output diff --git a/paddleslim/quant/quant_post_hpo.py b/paddleslim/quant/quant_post_hpo.py index 4e654b48..a6ff710f 100755 --- a/paddleslim/quant/quant_post_hpo.py +++ b/paddleslim/quant/quant_post_hpo.py @@ -14,7 +14,6 @@ """quant post with hyper params search""" import os -import cv2 import sys import math import time diff --git a/paddleslim/version.py b/paddleslim/version.py deleted file mode 100644 index f5360de7..00000000 --- a/paddleslim/version.py +++ /dev/null @@ -1,17 +0,0 @@ -#coding:utf-8 -# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License" -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" PaddleSlim version string """ -__all__ = ["slim_version"] -slim_version = "2.3.0" diff --git a/requirements.txt b/requirements.txt index 8892ab1a..2f9bde46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,8 +2,6 @@ tqdm pyzmq matplotlib -opencv-python==4.5.5.64 -opencv-python-headless==4.5.5.62 pillow pyyaml scikit-learn diff --git a/setup.py b/setup.py index dc5be3fa..c42fb576 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,8 @@ import platform from setuptools import find_packages from setuptools import setup -from paddleslim.version import slim_version + +slim_version = "2.3.0" def python_version(): -- GitLab