README.md 12.7 KB
Newer Older
W
wanghaoshuang 已提交
1

W
whs 已提交
2 3 4
<p align="center">
<h1 align="center">PaddleSlim</h1>
</p>
V
vincentXiyu 已提交
5

W
whs 已提交
6 7 8 9 10
<p align="center">
    <a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202-blue.svg"></a>
    <a href="https://paddleslim.readthedocs.io/en/latest/"><img src="https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat"></a>
    <a href="https://paddleslim.readthedocs.io/zh_CN/latest/"><img src="https://img.shields.io/badge/中文文档-最新-brightgreen.svg"></a>
</p>
W
whs 已提交
11

W
wanghaoshuang 已提交
12 13 14 15
PaddleSlim是一个专注于深度学习模型压缩的工具库,提供**低比特量化、知识蒸馏、稀疏化和模型结构搜索**等模型压缩策略,帮助用户快速实现模型的小型化。

## 产品动态

W
whs 已提交
16
- 🔥 **2022.05.23: 发布[v2.3.0版本](https://github.com/PaddlePaddle/PaddleSlim/releases/tag/v2.3.0)**
W
wanghaoshuang 已提交
17

W
whs 已提交
18
  - 发布[自动压缩功能](demo/auto_compression)
W
wanghaoshuang 已提交
19 20 21

    - 支持代码无感知压缩:用户只需提供推理模型文件和数据,既可进行离线量化(PTQ)、量化训练(QAT)、稀疏训练等压缩任务
    - 支持自动策略选择,根据任务特点和部署环境特性:自动搜索合适的离线量化方法,自动搜索最佳的压缩策略组合方式
W
whs 已提交
22
    - 提供了[自然语言处理](demo/auto_compression/nlp)、[图像语义分割](demo/auto_compression/semantic_segmentation)、[图像目标检测](demo/auto_compression/detection)三个方向的自动压缩示例
W
wanghaoshuang 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

  - 升级量化功能

    - 统一量化模型格式
    - 离线量化支持while op
    - 新增7种离线量化方法, 包括HIST, AVG, EMD, Bias Correction, AdaRound等
    - 修复BERT大模型量化训练过慢的问题

  - 支持半结构化稀疏训练

  - 新增延时预估工具

    - 支持预估指定模型在特定部署环境下 (ARM CPU + Paddle Lite) 的推理性能
    - 提供部署环境自动扩展工具,可以自动增加在更多 ARM CPU 设备上的预估工具
    - 支持对稀疏化模型、低比特量化模型的性能预估
    - 提供 SD625、SD710、RK3288 芯片 + Paddle Lite 的预估接口


- **2021.11.15: 发布v2.2.0版本**

  - 支持动态图离线量化功能.

- **2021.5.20: 发布V2.1.0版本**

  - 扩展离线量化方法
  - 新增非结构化稀疏
  - 增强剪枝功能
  - 修复OFA功能若干bug

更多信息请参考:[release note](https://github.com/PaddlePaddle/PaddleSlim/releases)

W
whs 已提交
54

W
whs 已提交
55
## 基础压缩功能概览
W
whs 已提交
56 57 58 59

PaddleSlim支持以下功能,也支持自定义量化、裁剪等功能。
<table>
<tr align="center" valign="bottom">
C
ceci3 已提交
60 61 62
  <th><a href="https://github.com/PaddlePaddle/PaddleSlim/blob/release/2.0.0/docs/zh_cn/tutorials/quant/overview.md">Quantization</a></th>
  <th><a href="https://github.com/PaddlePaddle/PaddleSlim/blob/release/2.0.0/docs/zh_cn/tutorials/pruning/overview.md">Pruning</a></th>
  <th><a href="https://github.com/PaddlePaddle/PaddleSlim/blob/release/2.0.0/docs/zh_cn/tutorials/nas/overview.md">NAS</a></th>
C
ceci3 已提交
63
  <th><a href="https://github.com/PaddlePaddle/PaddleSlim/tree/release/2.0.0/docs/zh_cn/tutorials">Distilling</a></th>
W
whs 已提交
64 65 66 67
</tr>
<tr valign="top">
  <td>
    <ul>
C
ceci3 已提交
68 69 70 71 72
      <li><a href="docs/zh_cn/api_cn/overview.md#%E5%9C%A8%E7%BA%BF%E9%87%8F%E5%8C%96%E8%AE%AD%E7%BB%83qat">QAT</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#pact">PACT</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#%E9%9D%99%E6%80%81%E7%A6%BB%E7%BA%BF%E9%87%8F%E5%8C%96ptq-static">PTQ Static</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#%E5%8A%A8%E6%80%81%E7%A6%BB%E7%BA%BF%E9%87%8F%E5%8C%96ptq-dynamic">PTQ Dynamic</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#embedding%E9%87%8F%E5%8C%96">Embedding Quant</a></li>
W
whs 已提交
73 74 75 76
    </ul>
  </td>
  <td>
    <ul>
C
ceci3 已提交
77 78 79 80 81 82
      <li><a href="docs/zh_cn/api_cn/overview.md#%E6%95%8F%E6%84%9F%E5%BA%A6%E5%89%AA%E6%9E%9D">SensitivityPruner</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#fpgm">FPGMFilterPruner</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#l1norm">L1NormFilterPruner</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#l2norm">**L2NormFilterPruner</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#slimfilter">*SlimFilterPruner</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#optslimfilter">*OptSlimFilterPruner</a></li>
W
whs 已提交
83 84 85 86
    </ul>
  </td>
  <td>
    <ul>
C
ceci3 已提交
87
      <li><a href="docs/zh_cn/api_cn/overview.md#sanas">*Simulate Anneal based NAS</a></li>
C
ceci3 已提交
88 89 90 91 92
      <li><a href="docs/zh_cn/api_cn/overview.md#rlnas">*Reinforcement Learning based NAS</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#darts">**DARTS</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#pc-darts">**PC-DARTS</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#once-for-all">**Once-for-All</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#hardware-aware-search">*Hardware-aware Search</a></li>
W
whs 已提交
93 94 95 96 97
    </ul>
  </td>

  <td>
    <ul>
C
ceci3 已提交
98 99 100
      <li><a href="docs/zh_cn/api_cn/overview.md#fsp">*FSP</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#dml">*DML</a></li>
      <li><a href="docs/zh_cn/api_cn/overview.md#dk">*DK</a></li>
W
whs 已提交
101 102 103 104
    </ul>
  </td>
</tr>
</table>
105

C
ceci3 已提交
106 107 108
注:
- *表示仅支持静态图,**表示仅支持动态图
- 敏感度裁剪指的是通过各个层的敏感度分析来确定各个卷积层的剪裁率,需要和其他裁剪方法配合使用。
109

W
whs 已提交
110
### 多场景效果展示
111

W
whs 已提交
112 113 114 115
PaddleSlim在典型视觉和自然语言处理任务上做了模型压缩,并且测试了Nvidia GPU、ARM等设备上的加速情况,这里展示部分模型的压缩效果,详细方案可以参考下面CV和NLP模型压缩方案:

<p align="center">
<img src="docs/images/benchmark.png" height=185 width=849 hspace='10'/> <br />
W
whs 已提交
116
<strong>表1: 部分场景模型压缩加速情况</strong>
W
whs 已提交
117
</p>
118

W
whs 已提交
119 120 121 122
注:
- YOLOv3: 在移动端SD855上加速3.55倍。
- PP-OCR: 体积由8.9M减少到2.9M, 在SD855上加速1.27倍。
- BERT: 模型参数由110M减少到80M,精度提升的情况下,Tesla T4 GPU FP16计算加速1.47倍。
123

W
whs 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
### 离线量化效果对比

<p align="center">
<img width="750" alt="image" src="https://user-images.githubusercontent.com/7534971/168772388-cbb089a2-0ab8-4448-bc36-79204d9ce6ee.png"/> <br />
<strong>表2: 多种离线量化方法效果对比</strong>
</p>

### 自动压缩效果展示

<p align="center">
<img width="800" alt="image" src="https://user-images.githubusercontent.com/7534971/168772918-ce4ad5e3-27a5-4536-b304-fe250f1e9860.png"/> <br />
<strong>表3: 自动压缩效果</strong>
</p>



W
whs 已提交
140
## 文档教程
W
wanghaoshuang 已提交
141

W
whs 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
## 版本对齐

|  PaddleSlim   | PaddlePaddle   | PaddleLite    |
| :-----------: | :------------: | :------------:|
| 1.0.1         | <=1.7          |       2.7     |
| 1.1.1         | 1.8            |       2.7     |
| 1.2.0         | 2.0Beta/RC     |       2.8     |
| 2.0.0         | 2.0            |       2.8     |
| 2.1.0         | 2.1.0          |       2.8     |
| 2.1.1         | 2.1.1          |       >=2.8   |
| 2.3.0         | 2.3.0          |       >=2.11  |



## 安装

安装最新版本:
```bash
pip install paddleslim -i https://pypi.tuna.tsinghua.edu.cn/simple
```

安装指定版本:
```bash
pip install paddleslim==2.3.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
```


W
whs 已提交
169
### 快速开始
W
wanghaoshuang 已提交
170

C
ceci3 已提交
171 172
快速开始教程是能基于CIFAR10数据集快速运行起来的简单示例,若您是Paddle官方模型套件用户,请直接使用下方的CV模型压缩或者NLP模型压缩中教程。

W
whs 已提交
173 174 175 176 177 178
- 🔥 [自动压缩](demo/auto_compression)
- [量化训练](docs/zh_cn/quick_start/static/quant_aware_tutorial.md)
- [离线量化](docs/zh_cn/quick_start/static/quant_post_static_tutorial.md)
- [结构化剪枝](docs/zh_cn/quick_start/static/pruning_tutorial.md)
- [蒸馏](docs/zh_cn/quick_start/static/distillation_tutorial.md)
- [NAS](docs/zh_cn/quick_start/static/nas_tutorial.md)
W
wanghaoshuang 已提交
179

W
whs 已提交
180
### 更多教程
W
wanghaoshuang 已提交
181

C
ceci3 已提交
182 183
进阶教程详细介绍了每一步的流程,帮助您把相应方法迁移到您自己的模型上。

W
whs 已提交
184 185 186 187 188 189 190 191 192 193
- 通道剪裁
  - [四种剪裁策略效果对比与应用方法](docs/zh_cn/tutorials/pruning/overview.md)
    - [L1NormFilterPruner](docs/zh_cn/tutorials/pruning/overview.md#l1normfilterpruner)
    - [FPGMFilterPruner](docs/zh_cn/tutorials/pruning/overview.md#fpgmfilterpruner)
    - [SlimFilterFilterPruner](docs/zh_cn/tutorials/pruning/overview.md#slimfilterpruner)
    - [OptSlimFilterPruner](docs/zh_cn/tutorials/pruning/overview.md#optslimfilterpruner)
  - 自定义剪裁策略:[动态图](docs/zh_cn/tutorials/pruning/dygraph/self_defined_filter_pruning.md)

- 低比特量化
  - [三种量化方法介绍与应用](docs/zh_cn/tutorials/quant/overview.md)
W
whs 已提交
194 195 196
    - [量化训练](docs/zh_cn/quick_start/static/quant_aware_tutorial.md)
    - [离线量化](docs/zh_cn/tutorials/quant/static/quant_post_tutorial.md)
    - [embedding量化](docs/zh_cn/tutorials/quant/static/embedding_quant_tutorial.md)
W
whs 已提交
197 198 199

- NAS
  - [四种NAS策略介绍和应用](docs/zh_cn/tutorials/nas/overview.md)
C
ceci3 已提交
200 201 202 203
    - [Once-For-All](docs/zh_cn/tutorials/nas/dygraph/nas_ofa.md)
    - [SANAS](docs/zh_cn/tutorials/nas/static/sanas_darts_space.md)
    - [RLNAS](https://github.com/PaddlePaddle/PaddleSlim/tree/release/2.0.0/demo/nas#rlnas%E7%BD%91%E7%BB%9C%E7%BB%93%E6%9E%84%E6%90%9C%E7%B4%A2%E7%A4%BA%E4%BE%8B)
    - [DARTS](demo/darts/README.md)
W
whs 已提交
204 205 206

- 蒸馏
  - [知识蒸馏示例](demo/distillation)
W
wanghaoshuang 已提交
207

W
wanghaoshuang 已提交
208

W
whs 已提交
209
#### 推理部署
W
wanghaoshuang 已提交
210

W
whs 已提交
211 212 213
- [Intel CPU量化部署](demo/mkldnn_quant/README.md)
- [Nvidia GPU量化部署](demo/quant/deploy/TensorRT/README.md)
- [PaddleLite量化部署](docs/zh_cn/deploy/deploy_cls_model_on_mobile_device.md)
W
wanghaoshuang 已提交
214

W
whs 已提交
215
### CV模型压缩
C
ceci3 已提交
216
本系列教程均基于Paddle官方的模型套件中模型进行压缩,若您不是模型套件用户,更推荐使用快速教程和进阶教程。
W
wanghaoshuang 已提交
217

C
ceci3 已提交
218
- 检测模型压缩
W
whs 已提交
219
  - 压缩方案
C
ceci3 已提交
220
    - [PPDetection-YOLOv3 压缩方案](docs/zh_cn/cv/detection/static/yolov3_slim.md)
C
ceci3 已提交
221

W
whs 已提交
222
  - 方法应用-静态图
C
ceci3 已提交
223 224 225
    - [蒸馏](docs/zh_cn/cv/detection/static/paddledetection_slim_distillation_tutorial.md)
    - [量化训练](docs/zh_cn/cv/detection/static/paddledetection_slim_quantization_tutorial.md)
    - [模型结构搜索](docs/zh_cn/cv/detection/static/paddledetection_slim_nas_tutorial.md)
W
whs 已提交
226 227 228
    - [剪枝](docs/zh_cn/cv/detection/static/paddledetection_slim_pruing_tutorial.md)
    - [剪枝与蒸馏的结合使用](docs/zh_cn/cv/detection/static/paddledetection_slim_prune_dist_tutorial.md)
    - [卷积层敏感度分析](docs/zh_cn/cv/detection/static/paddledetection_slim_sensitivy_tutorial.md)
C
ceci3 已提交
229

W
whs 已提交
230
  - 方法应用-动态图
C
ceci3 已提交
231 232
    - [剪枝](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.0-rc/dygraph/configs/slim#%E5%89%AA%E8%A3%81)
    - [量化训练](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.0-rc/dygraph/configs/slim#%E9%87%8F%E5%8C%96)
W
whs 已提交
233

C
ceci3 已提交
234
- 分割模型压缩
W
whs 已提交
235 236

  - 压缩方案
W
wanghaoshuang 已提交
237

W
whs 已提交
238
  - 方法应用-静态图
C
ceci3 已提交
239 240 241 242
    - [蒸馏](https://github.com/PaddlePaddle/PaddleSeg/tree/release/v0.8.0/slim/distillation)
    - [量化训练](https://github.com/PaddlePaddle/PaddleSeg/tree/release/v0.8.0/slim/quantization)
    - [模型结构搜索](https://github.com/PaddlePaddle/PaddleSeg/tree/release/v0.8.0/slim/nas)
    - [剪枝](https://github.com/PaddlePaddle/PaddleSeg/tree/release/v0.8.0/slim/prune)
W
whs 已提交
243 244

  - 方法应用-动态图
C
ceci3 已提交
245 246
    - [剪枝](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/slim#%E6%A8%A1%E5%9E%8B%E8%A3%81%E5%89%AA)
    - [量化训练](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/slim#%E6%A8%A1%E5%9E%8B%E9%87%8F%E5%8C%96)
W
wanghaoshuang 已提交
247

C
ceci3 已提交
248
- OCR模型压缩
W
wanghaoshuang 已提交
249

W
whs 已提交
250
  - 压缩方案
C
ceci3 已提交
251
    - [3.5M模型压缩方案](docs/zh_cn/cv/ocr/static/3.5M_slim.md)
W
whs 已提交
252 253

  - 方法应用-静态图
C
ceci3 已提交
254
    - [量化训练](https://github.com/PaddlePaddle/PaddleOCR/tree/release/1.1/deploy/slim/quantization)
W
whs 已提交
255
    - [剪枝](https://github.com/PaddlePaddle/PaddleOCR/tree/release/1.1/deploy/slim/prune)
W
wanghaoshuang 已提交
256

W
whs 已提交
257
  - 方法应用-动态图
C
ceci3 已提交
258 259
    - [剪枝](https://github.com/PaddlePaddle/PaddleOCR/tree/develop/deploy/slim/prune)
    - [量化训练](https://github.com/PaddlePaddle/PaddleOCR/tree/develop/deploy/slim/quantization)
W
wanghaoshuang 已提交
260 261


W
whs 已提交
262 263
### NLP模型压缩

C
ceci3 已提交
264 265
- [PaddleNLP-BERT](docs/zh_cn/nlp/paddlenlp_slim_ofa_tutorial.md)
- [ERNIE-ERNIE](docs/zh_cn/nlp/ernie_slim_ofa_tutorial.md)
W
wanghaoshuang 已提交
266

W
whs 已提交
267 268
### API文档

W
whs 已提交
269 270
- [动态图](docs/zh_cn/api_cn/dygraph)
- [静态图](docs/zh_cn/api_cn/static)
W
whs 已提交
271

C
ceci3 已提交
272
### [FAQ](docs/zh_cn/FAQ/quantization_FAQ.md)
W
whs 已提交
273 274 275

## 许可证书

W
whs 已提交
276 277 278
本项目的发布受[Apache 2.0 license](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/LICENSE)许可认证。

## 贡献代码
W
whs 已提交
279 280

我们非常欢迎你可以为PaddleSlim提供代码,也十分感谢你的反馈。
W
whs 已提交
281

G
Guanghua Yu 已提交
282
## <img title="" src="https://user-images.githubusercontent.com/48054808/157800467-2a9946ad-30d1-49a9-b9db-ba33413d9c90.png" alt="" width="20"> 技术交流
W
whs 已提交
283

G
Guanghua Yu 已提交
284 285 286 287 288 289 290
- 如果你发现任何PaddleSlim存在的问题或者是建议, 欢迎通过[GitHub Issues](https://github.com/PaddlePaddle/PaddleSlim/issues)给我们提issues。

- 欢迎加入PaddleSlim 微信技术交流群(添加并回复小助手“Slim”)

<div align="center">
  <img src="docs/images/wechat_qr_code.png"  width = "250" />  
  </div>