Skip to content

Commit

Permalink
update readme (PaddlePaddle#1129)
Browse files Browse the repository at this point in the history
* update readme

* update

* update

* remove cv2

* update

* update
  • Loading branch information
ceci3 authored May 21, 2022
1 parent 80184c4 commit 490c1f7
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 54 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


### 快速开始

Expand Down Expand Up @@ -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)许可认证。
Expand Down
4 changes: 2 additions & 2 deletions demo/auto_compression/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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版本

## 快速上手

Expand Down
4 changes: 2 additions & 2 deletions demo/auto_compression/detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions demo/auto_compression/image_classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions demo/auto_compression/nlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions demo/auto_compression/semantic_segmentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion demo/dygraph/pruning/imagenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import os
import cv2
import math
import random
import numpy as np
Expand Down
16 changes: 8 additions & 8 deletions docs/zh_cn/FAQ/quantization_FAQ.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 量化FAQ

1. 量化训练或者离线量化后的模型体积为什么没有变小?
2. 量化训练或者离线量化后的模型使用fluid加载为什么没有加速?怎样才能加速?
2. 量化训练或者离线量化后的模型使用paddle加载为什么没有加速?怎样才能加速?
3. 该怎么设置适合的量化配置?
4. 离线量化出现'KeyError: '报错
5. 离线量化或者量化训练时出现CUDNN或者CUDA错误
Expand All @@ -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).

Expand Down Expand Up @@ -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 |

Expand Down
4 changes: 2 additions & 2 deletions paddleslim/auto_compression/auto_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
'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'
Expand Down
13 changes: 9 additions & 4 deletions paddleslim/auto_compression/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
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
Expand All @@ -35,6 +34,12 @@

_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,
Expand Down Expand Up @@ -113,7 +118,7 @@ def __init__(self,
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()

Expand Down
4 changes: 2 additions & 2 deletions paddleslim/common/patterns_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions paddleslim/nas/ofa/layers_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -374,7 +374,7 @@ class SuperConv2DTranspose(fluid.dygraph.Conv2DTranspose):
`conv2dtranspose <http://www.matthewzeiler.com/wp-content/uploads/2017/07/cvpr2010.pdf>`_ .
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] .
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion paddleslim/quant/quant_post_hpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""quant post with hyper params search"""

import os
import cv2
import sys
import math
import time
Expand Down
17 changes: 0 additions & 17 deletions paddleslim/version.py

This file was deleted.

2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
tqdm
pyzmq
matplotlib
opencv-python==4.5.5.64
opencv-python-headless==4.5.5.62
pillow
pyyaml
scikit-learn
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

from setuptools import find_packages
from setuptools import setup
from paddleslim.version import slim_version

slim_version = "2.3.0"


def python_version():
Expand Down

0 comments on commit 490c1f7

Please sign in to comment.