Unverified Commit 346721be authored by kvartet's avatar kvartet Committed by GitHub
Browse files

Update Chinese translation (#3413)

parent b122c63d
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
[![MIT 许可证](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) [![生成状态](https://msrasrg.visualstudio.com/NNIOpenSource/_apis/build/status/full%20test%20-%20linux?branchName=master)](https://msrasrg.visualstudio.com/NNIOpenSource/_build/latest?definitionId=62&branchName=master) [![问题](https://img.shields.io/github/issues-raw/Microsoft/nni.svg)](https://github.com/Microsoft/nni/issues?q=is%3Aissue+is%3Aopen) [![Bug](https://img.shields.io/github/issues/Microsoft/nni/bug.svg)](https://github.com/Microsoft/nni/issues?q=is%3Aissue+is%3Aopen+label%3Abug) [![拉取请求](https://img.shields.io/github/issues-pr-raw/Microsoft/nni.svg)](https://github.com/Microsoft/nni/pulls?q=is%3Apr+is%3Aopen) [![版本](https://img.shields.io/github/release/Microsoft/nni.svg)](https://github.com/Microsoft/nni/releases) [![进入 https://gitter.im/Microsoft/nni 聊天室提问](https://badges.gitter.im/Microsoft/nni.svg)](https://gitter.im/Microsoft/nni?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![文档状态](https://readthedocs.org/projects/nni/badge/?version=latest)](https://nni.readthedocs.io/zh/latest/?badge=latest) [![MIT 许可证](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) [![生成状态](https://msrasrg.visualstudio.com/NNIOpenSource/_apis/build/status/full%20test%20-%20linux?branchName=master)](https://msrasrg.visualstudio.com/NNIOpenSource/_build/latest?definitionId=62&branchName=master) [![问题](https://img.shields.io/github/issues-raw/Microsoft/nni.svg)](https://github.com/Microsoft/nni/issues?q=is%3Aissue+is%3Aopen) [![Bug](https://img.shields.io/github/issues/Microsoft/nni/bug.svg)](https://github.com/Microsoft/nni/issues?q=is%3Aissue+is%3Aopen+label%3Abug) [![拉取请求](https://img.shields.io/github/issues-pr-raw/Microsoft/nni.svg)](https://github.com/Microsoft/nni/pulls?q=is%3Apr+is%3Aopen) [![版本](https://img.shields.io/github/release/Microsoft/nni.svg)](https://github.com/Microsoft/nni/releases) [![进入 https://gitter.im/Microsoft/nni 聊天室提问](https://badges.gitter.im/Microsoft/nni.svg)](https://gitter.im/Microsoft/nni?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![文档状态](https://readthedocs.org/projects/nni/badge/?version=latest)](https://nni.readthedocs.io/zh/latest/?badge=latest)
[English](README.md) [NNI 文档](https://nni.readthedocs.io/zh/stable/) | [English](README.md)
**NNI (Neural Network Intelligence)** 是一个轻量但强大的工具包,帮助用户**自动**的进行[特征工程](docs/zh_CN/FeatureEngineering/Overview.rst)[神经网络架构搜索](docs/zh_CN/NAS/Overview.rst)[超参调优](docs/zh_CN/Tuner/BuiltinTuner.rst)以及[模型压缩](docs/zh_CN/Compression/Overview.rst) **NNI (Neural Network Intelligence)** 是一个轻量但强大的工具包,帮助用户**自动**的进行[特征工程](docs/zh_CN/FeatureEngineering/Overview.rst)[神经网络架构搜索](docs/zh_CN/NAS/Overview.rst)[超参调优](docs/zh_CN/Tuner/BuiltinTuner.rst)以及[模型压缩](docs/zh_CN/Compression/Overview.rst)
NNI 管理自动机器学习 (AutoML) 的 Experiment,**调度运行**由调优算法生成的 Trial 任务来找到最好的神经网络架构和/或超参,支持**各种训练环境**,如[本机](docs/zh_CN/TrainingService/LocalMode.rst)[远程服务器](docs/zh_CN/TrainingService/RemoteMachineMode.rst)[OpenPAI](docs/zh_CN/TrainingService/PaiMode.rst)[Kubeflow](docs/zh_CN/TrainingService/KubeflowMode.rst)[基于 K8S 的 FrameworkController(如,AKS 等)](docs/zh_CN/TrainingService/FrameworkControllerMode.rst)[DLWorkspace (又称 DLTS)](docs/zh_CN/TrainingService/DLTSMode.rst), [AML (Azure Machine Learning)](docs/zh_CN/TrainingService/AMLMode.rst), [AdaptDL(又称 ADL)](docs/zh_CN/TrainingService/AdaptDLMode.rst) 和其他云服务 NNI 管理自动机器学习 (AutoML) 的 Experiment,**调度运行**由调优算法生成的 Trial 任务来找到最好的神经网络架构和/或超参,支持**各种训练环境**,如[本机](docs/zh_CN/TrainingService/LocalMode.rst)[远程服务器](docs/zh_CN/TrainingService/RemoteMachineMode.rst)[OpenPAI](docs/zh_CN/TrainingService/PaiMode.rst)[Kubeflow](docs/zh_CN/TrainingService/KubeflowMode.rst)[基于 K8S 的 FrameworkController(如,AKS 等)](docs/zh_CN/TrainingService/FrameworkControllerMode.rst)[DLWorkspace (又称 DLTS)](docs/zh_CN/TrainingService/DLTSMode.rst), [AML (Azure Machine Learning)](docs/zh_CN/TrainingService/AMLMode.rst), [AdaptDL(又称 ADL)](docs/zh_CN/TrainingService/AdaptDLMode.rst) 和其他的云平台甚至 [混合模式](docs/zh_CN/TrainingService/HybridMode.rst)
## **使用场景** ## **使用场景**
...@@ -19,7 +19,12 @@ NNI 管理自动机器学习 (AutoML) 的 Experiment,**调度运行**由调优 ...@@ -19,7 +19,12 @@ NNI 管理自动机器学习 (AutoML) 的 Experiment,**调度运行**由调优
* 想要更容易**实现或试验新的自动机器学习算法**的研究员或数据科学家,包括:超参调优算法,神经网络搜索算法以及模型压缩算法。 * 想要更容易**实现或试验新的自动机器学习算法**的研究员或数据科学家,包括:超参调优算法,神经网络搜索算法以及模型压缩算法。
* 在机器学习平台中**支持自动机器学习** * 在机器学习平台中**支持自动机器学习**
### **[NNI v1.9 已发布!](https://github.com/microsoft/nni/releases) &nbsp;[<img width="48" src="docs/img/release_icon.png" />](#nni-released-reminder)** ## **最新消息!** &nbsp;[<img width="48" src="docs/img/release_icon.png" />](#nni-released-reminder)
* **最新版本**[v2.0 已发布](https://github.com/microsoft/nni/releases) - *2021年1月14日*
* **最新视频 demo**[Youtube 入口](https://www.youtube.com/channel/UCKcafm6861B2mnYhPbZHavw) | [Bilibili 入口](https://space.bilibili.com/1649051673) - *上次更新:2021年2月19日*
* **最新案例分享**[利用 AdaptDL 和 NNI 集成方案实现经济高效超参调优](https://medium.com/casl-project/cost-effective-hyper-parameter-tuning-using-adaptdl-with-nni-e55642888761) - *2021年2月23日发布*
## **NNI 功能一览** ## **NNI 功能一览**
...@@ -165,6 +170,7 @@ NNI 提供命令行工具以及友好的 WebUI 来管理训练的 Experiment。 ...@@ -165,6 +170,7 @@ NNI 提供命令行工具以及友好的 WebUI 来管理训练的 Experiment。
<ul> <ul>
<li><a href="docs/zh_CN/TrainingService/LocalMode.rst">本机</a></li> <li><a href="docs/zh_CN/TrainingService/LocalMode.rst">本机</a></li>
<li><a href="docs/zh_CN/TrainingService/RemoteMachineMode.rst">远程计算机</a></li> <li><a href="docs/zh_CN/TrainingService/RemoteMachineMode.rst">远程计算机</a></li>
<li><a href="docs/zh_CN/TrainingService/HybridMode.rst">混合模式</a></li>
<li><a href="docs/zh_CN/TrainingService/AMLMode.rst">AML(Azure Machine Learning)</a></li> <li><a href="docs/zh_CN/TrainingService/AMLMode.rst">AML(Azure Machine Learning)</a></li>
<li><b>基于 Kubernetes 的平台</b></li> <li><b>基于 Kubernetes 的平台</b></li>
<ul> <ul>
...@@ -238,12 +244,10 @@ Linux 和 macOS 下 NNI 系统需求[参考这里](https://nni.readthedocs.io/zh ...@@ -238,12 +244,10 @@ Linux 和 macOS 下 NNI 系统需求[参考这里](https://nni.readthedocs.io/zh
### **验证安装** ### **验证安装**
以下示例基于 TensorFlow 1.x 。确保运行环境中使用的的是 ** TensorFlow 1.x**
* 通过克隆源代码下载示例。 * 通过克隆源代码下载示例。
```bash ```bash
git clone -b v1.9 https://github.com/Microsoft/nni.git git clone -b v2.0 https://github.com/Microsoft/nni.git
``` ```
* 运行 MNIST 示例。 * 运行 MNIST 示例。
...@@ -251,13 +255,13 @@ Linux 和 macOS 下 NNI 系统需求[参考这里](https://nni.readthedocs.io/zh ...@@ -251,13 +255,13 @@ Linux 和 macOS 下 NNI 系统需求[参考这里](https://nni.readthedocs.io/zh
Linux 或 macOS Linux 或 macOS
```bash ```bash
nnictl create --config nni/examples/trials/mnist-tfv1/config.yml nnictl create --config nni/examples/trials/mnist-pytorch/config.yml
``` ```
Windows Windows
```bash ```powershell
nnictl create --config nni\examples\trials\mnist-tfv1\config_windows.yml nnictl create --config nni\examples\trials\mnist-pytorch\config_windows.yml
``` ```
* 在命令行中等待输出 `INFO: Successfully started experiment!`。 此消息表明 Experiment 已成功启动。 通过命令行输出的 `Web UI url` 来访问 Experiment 的界面。 * 在命令行中等待输出 `INFO: Successfully started experiment!`。 此消息表明 Experiment 已成功启动。 通过命令行输出的 `Web UI url` 来访问 Experiment 的界面。
...@@ -296,54 +300,23 @@ You can use these commands to get more information about the experiment ...@@ -296,54 +300,23 @@ You can use these commands to get more information about the experiment
<th><img src="./docs/img/webui-img/full-detail.png" alt="drawing" width="410" height="300"/></th> <th><img src="./docs/img/webui-img/full-detail.png" alt="drawing" width="410" height="300"/></th>
</table> </table>
## **文档** ## **发布和贡献**
* 要了解 NNI,请阅读 [NNI 概述](https://nni.readthedocs.io/zh/latest/Overview.html)
* 要熟悉如何使用 NNI,请阅读[文档](https://nni.readthedocs.io/zh/latest/index.html)
* 要安装并使用 NNI,参考[安装指南](https://nni.readthedocs.io/zh/latest/installation.html)
## **贡献**
本项目欢迎任何贡献和建议。 大多数贡献都需要你同意参与者许可协议(CLA),来声明你有权,并实际上授予我们有权使用你的贡献。 有关详细信息,请访问 https://cla.microsoft.com。
当你提交拉取请求时,CLA机器人会自动检查你是否需要提供CLA,并修饰这个拉取请求(例如,标签、注释)。 只需要按照机器人提供的说明进行操作即可。 CLA 只需要同意一次,就能应用到所有的代码仓库上。
该项目采用了 [ Microsoft 开源行为准则 ](https://opensource.microsoft.com/codeofconduct/)。 有关详细信息,请参阅[常见问题解答](https://opensource.microsoft.com/codeofconduct/faq/),如有任何疑问或意见可联系 opencode@microsoft.com NNI 有一个月度发布周期(主要发布)。 如果您遇到问题可以通过 [创建 issue](https://github.com/microsoft/nni/issues/new/choose) 来报告
熟悉贡献协议后,即可按照 NNI 开发人员教程,创建第一个 PR: 我们感谢所有的贡献。 如果您计划提供任何 Bug 修复,请放手去做,不需要任何顾虑。
* 推荐新贡献者先从简单的问题开始:['good first issue'](https://github.com/Microsoft/nni/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)['help-wanted'](https://github.com/microsoft/nni/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) 如果您计划提供新的功能、新的 Tuner 和 新的训练平台等, 请先创建一个新的 issue 或重用现有 issue,并与我们讨论该功能。 我们会及时与您讨论这个问题,如有需要会安排电话会议。
* [NNI 开发环境安装教程](docs/zh_CN/Tutorial/SetupNniDeveloperEnvironment.rst)
* [如何调试](docs/zh_CN/Tutorial/HowToDebug.rst)
* 如果有使用上的问题,可先查看[常见问题解答](https://github.com/microsoft/nni/blob/master/docs/zh_CN/Tutorial/FAQ.rst)。如果没能解决问题,可通过 [Gitter](https://gitter.im/Microsoft/nni?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 联系 NNI 开发团队或在 GitHub 上 [报告问题](https://github.com/microsoft/nni/issues/new/choose)
* [自定义 Tuner](docs/zh_CN/Tuner/CustomizeTuner.rst)
* [实现定制的训练平台](docs/zh_CN/TrainingService/HowToImplementTrainingService.rst)
* [在 NNI 上实现新的 NAS Trainer](docs/zh_CN/NAS/Advanced.rst)
* [自定义 Advisor](docs/zh_CN/Tuner/CustomizeAdvisor.rst)
## **其它代码库和参考** 如果需要了解更多如何贡献的信息,请参考 [如何贡献页面](https://nni.readthedocs.io/zh/stable/contribution.html)
经作者许可的一些 NNI 用法示例和相关文档。 再次感谢所有的贡献者!
* ### **外部代码库** ### <a href="https://github.com/microsoft/nni/graphs/contributors"><img src="docs/img/contributors.png" /></a>
* 在 NNI 中运行 [ENAS](examples/nas/enas/README_zh_CN.md)
* [NNI 中的自动特征工程](examples/feature_engineering/auto-feature-engineering/README_zh_CN.md)
* 使用 NNI 的 [矩阵分解超参调优](https://github.com/microsoft/recommenders/blob/master/examples/04_model_select_and_optimize/nni_surprise_svd.ipynb)
* [scikit-nni](https://github.com/ksachdeva/scikit-nni) 使用 NNI 为 scikit-learn 开发的超参搜索。
* ### **相关文章** ###
* [超参数优化的对比](docs/zh_CN/CommunitySharings/HpoComparison.rst)
* [神经网络结构搜索的对比](docs/zh_CN/CommunitySharings/NasComparison.rst)
* [并行化顺序算法:TPE](docs/zh_CN/CommunitySharings/ParallelizingTpeSearch.rst)
* [使用 NNI 为 SVD 自动调参](docs/zh_CN/CommunitySharings/RecommendersSvd.rst)
* [使用 NNI 为 SPTAG 自动调参](docs/zh_CN/CommunitySharings/SptagAutoTune.rst)
* [使用 NNI 为 scikit-learn 查找超参](https://towardsdatascience.com/find-thy-hyper-parameters-for-scikit-learn-pipelines-using-microsoft-nni-f1015b1224c1)
* **博客** - [AutoML 工具(Advisor,NNI 与 Google Vizier)的对比](http://gaocegege.com/Blog/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/katib-new#%E6%80%BB%E7%BB%93%E4%B8%8E%E5%88%86%E6%9E%90) 作者:[@gaocegege](https://github.com/gaocegege) - kubeflow/katib 的设计与实现的总结与分析章节
* **博客** - [NNI 2019 新功能汇总](https://mp.weixin.qq.com/s/7_KRT-rRojQbNuJzkjFMuA) by @squirrelsc
## **反馈** ## **反馈**
* [在 GitHub 上提交问题](https://github.com/microsoft/nni/issues/new/choose) * [在 GitHub 上提交问题](https://github.com/microsoft/nni/issues/new/choose)
*[Stack Overflow](https://stackoverflow.com/questions/tagged/nni?sort=Newest&edited=true) 上使用 nni 标签提问。
*[Gitter](https://gitter.im/Microsoft/nni?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 中参与讨论。 *[Gitter](https://gitter.im/Microsoft/nni?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 中参与讨论。
加入聊天组: 加入聊天组:
......
...@@ -47,8 +47,8 @@ Median Stop Assessor ...@@ -47,8 +47,8 @@ Median Stop Assessor
**classArgs 要求:** **classArgs 要求:**
* **optimize_mode** (*maximize 或 minimize,可选默认值是maximize*)。如果为 'maximize',Assessor 会在结果小于期望值时**中止** Trial。 如果为 'minimize',Assessor 会在结果大于期望值时**终止** Trial。 * **optimize_mode** ( *maximize 或 minimize,可选默认值是maximize* )。如果为 'maximize',Assessor 会在结果小于期望值时 **中止** Trial。 如果为 'minimize',Assessor 会在结果大于期望值时**终止** Trial。
* **start_step** (*int,可选,默认值为 0*)。只有收到 start_step 个中间结果后,才开始判断是否一个 Trial 应该被终止。 * **start_step** ( *int,可选,默认值为 0* )。只有收到 start_step 个中间结果后,才开始判断是否一个 Trial 应该被终止。
**使用示例:** **使用示例:**
...@@ -82,10 +82,10 @@ Curve Fitting Assessor ...@@ -82,10 +82,10 @@ Curve Fitting Assessor
**classArgs 要求:** **classArgs 要求:**
* **epoch_num** (*int,必需*),epoch 的总数。 需要此数据来决定需要预测点的总数。 * **epoch_num** ( *int,必需* ),epoch 的总数。 需要此数据来决定需要预测点的总数。
* **start_step** (*int,可选,默认值为 6*)。只有收到 start_step 个中间结果后,才开始判断是否一个 Trial 应该被终止。 * **start_step** ( *int,可选,默认值为 6* )。只有收到 start_step 个中间结果后,才开始判断是否一个 Trial 应该被终止。
* **threshold** (*float,可选,默认值为 0.95*),用来确定提前终止较差结果的阈值。 例如,如果 threshold = 0.95,最好的历史结果是 0.9,那么会在 Trial 的预测值低于 0.95 * 0.9 = 0.855 时停止。 * **threshold** ( *float,可选,默认值为 0.95* ),用来确定提前终止较差结果的阈值。 例如,如果 threshold = 0.95,最好的历史结果是 0.9,那么会在 Trial 的预测值低于 0.95 * 0.9 = 0.855 时停止。
* **gap** (*int,可选,默认值为 1*),Assessor 两次评估之间的间隔次数。 例如:如果 gap = 2, start_step = 6,就会评估第 6, 8, 10, 12... 个中间结果。 * **gap** ( *int,可选,默认值为 1* ),Assessor 两次评估之间的间隔次数。 例如:如果 gap = 2, start_step = 6,就会评估第 6, 8, 10, 12... 个中间结果。
**使用示例:** **使用示例:**
......
...@@ -43,8 +43,6 @@ NNI 支持自定义 Assessor。 ...@@ -43,8 +43,6 @@ NNI 支持自定义 Assessor。
NNI 需要定位到自定义的 Assessor 类,并实例化它,因此需要指定自定义 Assessor 类的文件位置,并将参数值传给 __init__ 构造函数。 NNI 需要定位到自定义的 Assessor 类,并实例化它,因此需要指定自定义 Assessor 类的文件位置,并将参数值传给 __init__ 构造函数。
`论文 <https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/46180.pdf>`__。
.. code-block:: yaml .. code-block:: yaml
assessor: assessor:
...@@ -62,8 +60,6 @@ Assessor 的工作目录是 ``<home>/nni-experiments/<experiment_id>/log``\ , ...@@ -62,8 +60,6 @@ Assessor 的工作目录是 ``<home>/nni-experiments/<experiment_id>/log``\ ,
更多示例,可参考: 更多示例,可参考:
.. * :githublink:`medianstop-assessor <nni/algorithms/hpo/medianstop_assessor.py>`
* :githublink:`curvefitting-assessor <nni/algorithms/hpo/curvefitting_assessor/>`
* :githublink:`medianstop-assessor <src/sdk/pynni/nni/medianstop_assessor>`
* :githublink:`curvefitting-assessor <src/sdk/pynni/nni/curvefitting_assessor>`
...@@ -25,7 +25,9 @@ NNI的命令行工具 **nnictl** 支持自动补全,也就是说,您可以 ...@@ -25,7 +25,9 @@ NNI的命令行工具 **nnictl** 支持自动补全,也就是说,您可以
cd ~ cd ~
wget https://raw.githubusercontent.com/microsoft/nni/{nni-version}/tools/bash-completion wget https://raw.githubusercontent.com/microsoft/nni/{nni-version}/tools/bash-completion
{nni-version} 应该填充 NNI 的版本,例如 ``master``\ , ``v1.9``。 你也可以 :githublink:`在这里 <tools/bash-completion>` 查看最新的 ``bash-completion`` 脚本。 {nni-version} 应该填充 NNI 的版本,例如 ``master``\ , ``v2.0``。 你也可以 :githublink:`在这里 <tools/bash-completion>` 查看最新的 ``bash-completion`` 脚本。
.. cannot find :githublink:`here <tools/bash-completion>`.
步骤 2. 安装脚本 步骤 2. 安装脚本
^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
......
...@@ -203,7 +203,7 @@ AutoGBDT 示例 ...@@ -203,7 +203,7 @@ AutoGBDT 示例
此例中,所有算法都使用了默认参数。 Metis 算法因为其高斯计算过程的复杂度为 O(n^3) 而运行非常慢,因此仅执行了 300 次 Trial。 此例中,所有算法都使用了默认参数。 Metis 算法因为其高斯计算过程的复杂度为 O(n^3) 而运行非常慢,因此仅执行了 300 次 Trial。
RocksDB 的 'fillrandom' 和 'readrandom' 基准测试 RocksDB 的 'fillrandom' 和 'readrandom' 基准测试
------------------------------------------------------ -----------------------------------------------------------
问题描述 问题描述
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
......
...@@ -50,24 +50,24 @@ NNI 在一些基准模型和数据集上使用各种剪枝算法进行了广泛 ...@@ -50,24 +50,24 @@ NNI 在一些基准模型和数据集上使用各种剪枝算法进行了广泛
CIFAR-10, VGG16: CIFAR-10, VGG16:
.. image:: ../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_vgg16.png .. image:: ../../../examples/model_compress/pruning/comparison_of_pruners/img/performance_comparison_vgg16.png
:target: ../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_vgg16.png :target: ../../../examples/model_compress/pruning/comparison_of_pruners/img/performance_comparison_vgg16.png
:alt: :alt:
CIFAR-10, ResNet18: CIFAR-10, ResNet18:
.. image:: ../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_resnet18.png .. image:: ../../../examples/model_compress/pruning/comparison_of_pruners/img/performance_comparison_resnet18.png
:target: ../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_resnet18.png :target: ../../../examples/model_compress/pruning/comparison_of_pruners/img/performance_comparison_resnet18.png
:alt: :alt:
CIFAR-10, ResNet50: CIFAR-10, ResNet50:
.. image:: ../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_resnet50.png .. image:: ../../../examples/model_compress/pruning/comparison_of_pruners/img/performance_comparison_resnet50.png
:target: ../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_resnet50.png :target: ../../../examples/model_compress/pruning/comparison_of_pruners/img/performance_comparison_resnet50.png
:alt: :alt:
...@@ -103,7 +103,7 @@ CIFAR-10, ResNet50: ...@@ -103,7 +103,7 @@ CIFAR-10, ResNet50:
* *
如果遵循 :githublink:`示例 <examples/model_compress/auto_pruners_torch.py>` 的做法,对于每一次剪枝实验,实验结果将以JSON格式保存如下: 如果遵循 :githublink:`示例 <examples/model_compress/auto_pruners_torch.py>`\ 的做法,对于每一次剪枝实验,实验结果将以JSON格式保存如下:
.. code-block:: json .. code-block:: json
...@@ -114,7 +114,8 @@ CIFAR-10, ResNet50: ...@@ -114,7 +114,8 @@ CIFAR-10, ResNet50:
} }
* *
实验代码在 :githublink:`这里 <examples/model_compress/comparison_of_pruners>`。可以参考 :githublink:`分析 <examples/model_compress/comparison_of_pruners/analyze.py>` 来绘制新的性能比较图。 实验代码在 :githublink:`这里 <examples/model_compress/comparison_of_pruners>`.
可以参考 :githublink:`分析 <examples/model_compress/comparison_of_pruners/analyze.py>` 来绘制新的性能比较图。
贡献 贡献
------------ ------------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
本文由 NNI 用户在知乎论坛上发表。 在这篇文章中,Garvin 分享了在使用 NNI 进行自动特征工程方面的体验。 我们认为本文对于有兴趣使用 NNI 进行特征工程的用户非常有用。 经作者许可,将原始文章摘编如下。 本文由 NNI 用户在知乎论坛上发表。 在这篇文章中,Garvin 分享了在使用 NNI 进行自动特征工程方面的体验。 我们认为本文对于有兴趣使用 NNI 进行特征工程的用户非常有用。 经作者许可,将原始文章摘编如下。
**原文**\ : `如何看待微软最新发布的AutoML平台NNI?By Garvin Li <https://www.zhihu.com/question/297982959/answer/964961829?utm_source=wechat_session&utm_medium=social&utm_oi=28812108627968&from=singlemessage&isappinstalled=0>`__ **原文(source)**\ : `如何看待微软最新发布的AutoML平台NNI?By Garvin Li <https://www.zhihu.com/question/297982959/answer/964961829?utm_source=wechat_session&utm_medium=social&utm_oi=28812108627968&from=singlemessage&isappinstalled=0>`__
01 AutoML概述 01 AutoML概述
--------------------- ---------------------
...@@ -24,7 +24,8 @@ NNI (Neural Network Intelligence) 是一个微软开源的自动机器学习工 ...@@ -24,7 +24,8 @@ NNI (Neural Network Intelligence) 是一个微软开源的自动机器学习工
或复杂系统的参数 或复杂系统的参数
链接: `https://github.com/Microsoft/nni <https://github.com/Microsoft/nni>`__ 链接
:`https://github.com/Microsoft/nni <https://github.com/Microsoft/nni>`__
总体看微软的工具都有一个比较大的特点, 总体看微软的工具都有一个比较大的特点,
技术可能不一定多新颖,但是设计都非常赞。 技术可能不一定多新颖,但是设计都非常赞。
...@@ -34,7 +35,9 @@ NNI 的 AutoFeatureENG 基本包含了用户对于 AutoFeatureENG 的一切幻 ...@@ -34,7 +35,9 @@ NNI 的 AutoFeatureENG 基本包含了用户对于 AutoFeatureENG 的一切幻
03 细说NNI - AutoFeatureENG 03 细说NNI - AutoFeatureENG
-------------------------------- --------------------------------
本文使用了此项目: `https://github.com/SpongebBob/tabular_automl_NNI <https://github.com/SpongebBob/tabular_automl_NNI>`__。 ..
本文使用了此项目: `https://github.com/SpongebBob/tabular_automl_NNI <https://github.com/SpongebBob/tabular_automl_NNI>`__。
新用户可以使用 NNI 轻松高效地进行 AutoFeatureENG。 使用是非常简单的,安装下文件中的 require,然后 pip install NNI。 新用户可以使用 NNI 轻松高效地进行 AutoFeatureENG。 使用是非常简单的,安装下文件中的 require,然后 pip install NNI。
...@@ -49,7 +52,7 @@ NNI把 AutoFeatureENG 拆分成 exploration 和 selection 两个模块。 explor ...@@ -49,7 +52,7 @@ NNI把 AutoFeatureENG 拆分成 exploration 和 selection 两个模块。 explor
04 特征 Exploration 04 特征 Exploration
---------------------- ----------------------
对于功能派生,NNI 提供了许多可自动生成新功能的操作, `列表如下 <https://github.com/SpongebBob/tabular_automl_NNI/blob/master/AutoFEOp.rst>`__ 对于功能派生,NNI 提供了许多可自动生成新功能的操作,`列表如下 <https://github.com/SpongebBob/tabular_automl_NNI/blob/master/AutoFEOp.md>`__
**count**:传统的统计,统计一些数据的出现频率 **count**:传统的统计,统计一些数据的出现频率
...@@ -111,7 +114,7 @@ Exploration 的目的就是长生出新的特征。 在代码里可以用 **get_ ...@@ -111,7 +114,7 @@ Exploration 的目的就是长生出新的特征。 在代码里可以用 **get_
了解 xgboost 或者 GBDT 算法同学应该知道,这种树形结构的算法是很容易计算出每个特征对于结果的影响的。 所以使用 lightGBM 可以天然的进行特征筛选。 了解 xgboost 或者 GBDT 算法同学应该知道,这种树形结构的算法是很容易计算出每个特征对于结果的影响的。 所以使用 lightGBM 可以天然的进行特征筛选。
弊病就是,如果下游是个 *LR* (逻辑回归)这种线性算法,筛选出来的特征是否具备普适性。 弊病就是,如果下游是个 *LR* (逻辑回归)这种线性算法,筛选出来的特征可能不具备普适性。
.. image:: https://pic4.zhimg.com/v2-d2f919497b0ed937acad0577f7a8df83_r.jpg .. image:: https://pic4.zhimg.com/v2-d2f919497b0ed937acad0577f7a8df83_r.jpg
...@@ -135,6 +138,5 @@ NNI 的 AutoFeature 模块是给整个行业制定了一个教科书般的标准 ...@@ -135,6 +138,5 @@ NNI 的 AutoFeature 模块是给整个行业制定了一个教科书般的标准
大家用的时候如果是 Mac 电脑可能会遇到 gcc 的问题,因为开源项目自带的脚本是基于 gcc7 编译的, 可以用下面的方法绕过去: 大家用的时候如果是 Mac 电脑可能会遇到 gcc 的问题,因为开源项目自带的脚本是基于 gcc7 编译的, 可以用下面的方法绕过去:
.. code-block:: bash brew install libomp
===================
brew install libomp
...@@ -176,8 +176,8 @@ a, b, c, r, s 以及 t 的推荐值分别为:a = 1, b = 5.1 ⁄ (4π2), c = 5 ...@@ -176,8 +176,8 @@ a, b, c, r, s 以及 t 的推荐值分别为:a = 1, b = 5.1 ⁄ (4π2), c = 5
参考 参考
---------- ----------
[1] James Bergstra, Remi Bardenet, Yoshua Bengio, Balazs Kegl. "Algorithms for Hyper-Parameter Optimization". `链接 <https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf>`__ [1] James Bergstra, Remi Bardenet, Yoshua Bengio, Balazs Kegl. `Algorithms for Hyper-Parameter Optimization. <https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf>`__
[2] Meng-Hiot Lim, Yew-Soon Ong. "Computational Intelligence in Expensive Optimization Problems". `链接 <https://link.springer.com/content/pdf/10.1007%2F978-3-642-10701-6.pdf>`__ [2] Meng-Hiot Lim, Yew-Soon Ong. `Computational Intelligence in Expensive Optimization Problems. <https://link.springer.com/content/pdf/10.1007%2F978-3-642-10701-6.pdf>`__
[3] M. Jordan, J. Kleinberg, B. Scho¨lkopf. "Pattern Recognition and Machine Learning". `链接 <http://users.isr.ist.utl.pt/~wurmd/Livros/school/Bishop%20-%20Pattern%20Recognition%20And%20Machine%20Learning%20-%20Springer%20%202006.pdf>`__ [3] M. Jordan, J. Kleinberg, B. Scho¨lkopf. `Pattern Recognition and Machine Learning. <http://users.isr.ist.utl.pt/~wurmd/Livros/school/Bishop%20-%20Pattern%20Recognition%20And%20Machine%20Learning%20-%20Springer%20%202006.pdf>`__
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
* `准备数据 <https://github.com/microsoft/recommenders/tree/master/examples/01_prepare_data>`__\ : 为每个算法准备并读取数据。 * `准备数据 <https://github.com/microsoft/recommenders/tree/master/examples/01_prepare_data>`__\ : 为每个算法准备并读取数据。
* `模型 <https://github.com/Microsoft/Recommenders/blob/master/examples/02_model/README.md>`__\ 使用种经典的以及深度学习推荐算法,如交替最小二乘法(\ `ALS <https://spark.apache.org/docs/latest/api/python/_modules/pyspark/ml/recommendation.html#ALS>`__\ )或极限深度分解机(\ `xDeepFM <https://arxiv.org/abs/1803.05170>`__\ )。 * 模型(`协同过滤算法 <https://github.com/microsoft/recommenders/tree/master/examples/02_model_collaborative_filtering>`__\ , `基于内容的过滤算法 <https://github.com/microsoft/recommenders/tree/master/examples/02_model_content_based_filtering>`__\ , `混合算法 <https://github.com/microsoft/recommenders/tree/master/examples/02_model_hybrid>`__\ ): 使用种经典的深度学习推荐算法来构建模型,比如 Alternating Least Squares (\ `ALS <https://spark.apache.org/docs/latest/api/python/_modules/pyspark/ml/recommendation.html#ALS>`__\ ) 或者 eXtreme Deep Factorization Machines (\ `xDeepFM <https://arxiv.org/abs/1803.05170>`__\ ).
* `评估 <https://github.com/Microsoft/Recommenders/blob/master/examples/03_evaluate/README.md>`__\ :使用离线指标来评估算法。 * `评估 <https://github.com/microsoft/recommenders/tree/master/examples/03_evaluate>`__\ :使用离线指标来评估算法。
* `模型选择和优化 <https://github.com/Microsoft/Recommenders/blob/master/examples/04_model_select_and_optimize/README.md>`__\ :为推荐算法模型调优超参。 * `模型选择和优化 <https://github.com/microsoft/recommenders/tree/master/examples/04_model_select_and_optimize>`__\:为推荐算法模型调优超参。
* `运营 <https://github.com/Microsoft/Recommenders/blob/master/examples/05_operationalize/README.md>`__\ :在 Azure 的生产环境上运行模型。 * `运营 <https://github.com/microsoft/recommenders/tree/master/examples/05_operationalize>`__\ :在 Azure 的生产环境上运行模型。
在第四项调优模型超参的任务上,NNI 可以发挥作用。 在 NNI 上调优推荐模型的具体示例,采用了 `SVD <https://github.com/Microsoft/Recommenders/blob/master/examples/02_model/surprise_svd_deep_dive.ipynb>`__\ 算法,以及数据集 Movielens100k。 此模型有超过 10 个超参需要调优。 在第四项调优模型超参的任务上,NNI 可以发挥作用。 在 NNI 上调优推荐模型的具体示例,采用了 `SVD <https://github.com/microsoft/recommenders/blob/master/examples/02_model_collaborative_filtering/surprise_svd_deep_dive.ipynb>`__\ 算法,以及数据集 Movielens100k。 此模型有超过 10 个超参需要调优。
由 Recommenders 提供的 `示例 <https://github.com/Microsoft/Recommenders/blob/master/examples/04_model_select_and_optimize/nni_surprise_svd.ipynb>`__ 中有非常详细的一步步的教程。 其中使用了不同的调优函数,包括 ``Annealing``\ , ``SMAC``\ , ``Random Search``\ , ``TPE``\ , ``Hyperband``\ , ``Metis`` 和 ``Evolution``。 最后比较了不同调优算法的结果。 请参考此 Notebook,来学习如何使用 NNI 调优 SVD 模型,并可以继续使用 NNI 来调优 Recommenders 中的其它模型。 由 Recommenders 提供的 `Jupyter notebook <https://github.com/microsoft/recommenders/blob/master/examples/04_model_select_and_optimize/nni_surprise_svd.ipynb>`__ 中有非常详细的一步步的教程。 其中使用了不同的调优函数,包括 ``Annealing``\ , ``SMAC``\ , ``Random Search``\ , ``TPE``\ , ``Hyperband``\ , ``Metis`` 和 ``Evolution``。 最后比较了不同调优算法的结果。 请参考此 Notebook,来学习如何使用 NNI 调优 SVD 模型,并可以继续使用 NNI 来调优 Recommenders 中的其它模型。
...@@ -6,4 +6,4 @@ ...@@ -6,4 +6,4 @@
此工具假设样本可以表示为向量,并且能通过 L2 或余弦算法来比较距离。 输入一个查询向量,会返回与其 L2 或余弦距离最小的一组向量。 此工具假设样本可以表示为向量,并且能通过 L2 或余弦算法来比较距离。 输入一个查询向量,会返回与其 L2 或余弦距离最小的一组向量。
SPTAG 提供了两种方法:kd-tree 与其的相关近邻图 (SPTAG-KDT),以及平衡 k-means 树与其的相关近邻图 (SPTAG-BKT)。 SPTAG-KDT 在索引构建效率上较好,而 SPTAG-BKT 在搜索高维度数据的精度上较好。 SPTAG 提供了两种方法:kd-tree 与其的相关近邻图 (SPTAG-KDT),以及平衡 k-means 树与其的相关近邻图 (SPTAG-BKT)。 SPTAG-KDT 在索引构建效率上较好,而 SPTAG-BKT 在搜索高维度数据的精度上较好。
在 SPTAG中,有几十个参数可以根据特定的场景或数据集进行调优。 NNI 是用来自动化调优这些参数的绝佳工具。 SPTAG 的作者尝试了使用 NNI 来进行自动调优,并轻松找到了性能较好的参数组合,并在 SPTAG `文档 <https://github.com/microsoft/SPTAG/blob/master/docs/Parameters.rst>`__ 中进行了分享。 参考此文档了解详细教程。 在 SPTAG中,有几十个参数可以根据特定的场景或数据集进行调优。 NNI 是用来自动化调优这些参数的绝佳工具。 SPTAG 的作者尝试了使用 NNI 来进行自动调优,并轻松找到了性能较好的参数组合,并在 SPTAG `文档 <https://github.com/microsoft/SPTAG/blob/master/docs/Parameters.md>`__ 中进行了分享。 参考此文档了解详细教程。
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
自动系统调优 自动系统调优
####################### #######################
数据库、张量算子实现等系统的性能往往需要进行调优,以适应特定的硬件配置、目标工作负载等。 手动调优系统非常复杂,并且通常需要对硬件和工作负载有详细的了解。 NNI 可以使这些任务变得更容易,并帮助系统所有者自动找到系统的最佳配置。 自动系统调优的详细设计思想可以在 `这篇文 <https://dl.acm.org/doi/10.1145/3352020.3352031>`__ 中找到。 以下是 NNI 可以发挥作用的一些典型案例。 数据库、张量算子实现等系统的性能往往需要进行调优,以适应特定的硬件配置、目标工作负载等。 手动调优系统非常复杂,并且通常需要对硬件和工作负载有详细的了解。 NNI 可以使这些任务变得更容易,并帮助系统所有者自动找到系统的最佳配置。 自动系统调优的详细设计思想可以在 `这篇文 <https://dl.acm.org/doi/10.1145/3352020.3352031>`__ 中找到。 以下是 NNI 可以发挥作用的一些典型案例。
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
与文档其他部分中展示功能用法的教程和示例不同,本部分主要介绍端到端方案和用例,以帮助用户进一步了解NNI如何为他们提供帮助。 NNI 可广泛应用于各种场景。 除了官方的教程和示例之外,也支持社区贡献者分享自己的自动机器学习实践经验,特别是使用 NNI 的实践经验。 与文档其他部分中展示功能用法的教程和示例不同,本部分主要介绍端到端方案和用例,以帮助用户进一步了解NNI如何为他们提供帮助。 NNI 可广泛应用于各种场景。 除了官方的教程和示例之外,也支持社区贡献者分享自己的自动机器学习实践经验,特别是使用 NNI 的实践经验。
用例与解决方案
=======================
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
...@@ -14,3 +16,25 @@ ...@@ -14,3 +16,25 @@
性能测量,比较和分析<perf_compare> 性能测量,比较和分析<perf_compare>
在 Google Colab 中使用 NNI <NNI_colab_support> 在 Google Colab 中使用 NNI <NNI_colab_support>
自动补全 nnictl 命令 <AutoCompletion> 自动补全 nnictl 命令 <AutoCompletion>
其它代码库和参考
====================================
经作者许可的一些 NNI 用法示例和相关文档。
外部代码库
=====================
* 使用 NNI 的 `矩阵分解超参调优 <https://github.com/microsoft/recommenders/blob/master/examples/04_model_select_and_optimize/nni_surprise_svd.ipynb>`__ 。
* 使用 NNI 为 scikit-learn 开发的超参搜索 `scikit-nni <https://github.com/ksachdeva/scikit-nni>`__ 。
相关文章
=================
* `使用AdaptDL 和 NNI进行经济高效的超参调优 - 2021年2月23日 <https://medium.com/casl-project/cost-effective-hyper-parameter-tuning-using-adaptdl-with-nni-e55642888761>`__
* `(中文博客)NNI v2.0 新功能概述 - 2021年1月21日 <https://www.msra.cn/zh-cn/news/features/nni-2>`__
* `(中文博客)2019年 NNI 新功能概览 - 2019年12月26日 <https://mp.weixin.qq.com/s/7_KRT-rRojQbNuJzkjFMuA>`__
* `使用 NNI 为 scikit-learn 开发的超参搜索 - 2019年11月6日 <https://towardsdatascience.com/find-thy-hyper-parameters-for-scikit-learn-pipelines-using-microsoft-nni-f1015b1224c1>`__
* `(中文博客)自动机器学习工具(Advisor、NNI 和 Google Vizier)对比 - 2019年8月5日 <http://gaocegege.com/Blog/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/katib-new#%E6%80%BB%E7%BB%93%E4%B8%8E%E5%88%86%E6%9E%90>`__
* `超参优化的对比 <./HpoComparison.rst>`__
* `神经网络架构搜索对比 <./NasComparison.rst>`__
* `TPE 并行化顺序算法 <./ParallelizingTpeSearch.rst>`__
* `自动调优 SVD(在推荐系统中使用 NNI ) <./RecommendersSvd.rst>`__
* `使用 NNI 为 SPTAG 自动调参 <./SptagAutoTune.rst>`__
...@@ -6,116 +6,70 @@ ...@@ -6,116 +6,70 @@
首先,使用 NNI 压缩模型 首先,使用 NNI 压缩模型
--------------------------------- ---------------------------------
可使用 NNI 轻松压缩模型。 以剪枝为例,可通过 LevelPruner 对预训练模型剪枝: 可使用 NNI 轻松压缩模型。 以剪枝为例,可通过 L2FilterPruner 对预训练模型剪枝:
.. code-block:: python .. code-block:: python
from nni.algorithms.compression.pytorch.pruning import LevelPruner from nni.algorithms.compression.pytorch.pruning import L2FilterPruner
config_list = [{ 'sparsity': 0.8, 'op_types': ['default'] }] config_list = [{ 'sparsity': 0.5, 'op_types': ['Conv2d'] }]
pruner = LevelPruner(model, config_list) pruner = L2FilterPruner(model, config_list)
pruner.compress() pruner.compress()
op_type 为 'default' 表示模块类型为 PyTorch 定义在 :githublink:`default_layers.py <src/sdk/pynni/nni/compression/pytorch/default_layers.py>` 。 op_type 'Conv2d' 表示在 PyTorch 框架下定义在 :githublink:`default_layers.py <nni/compression/pytorch/default_layers.py>` 中的模块类型
因此 ``{ 'sparsity': 0.8, 'op_types': ['default'] }`` 表示 **所有指定 op_types 的层都会被压缩到 0.8 的稀疏度**。 当调用 ``pruner.compress()`` 时,模型会通过掩码进行压缩。随后还可以微调模型,此时 **被剪除的权重不会被更新**。 因此 ``{ 'sparsity': 0.5, 'op_types': ['Conv2d'] }`` 表示 **所有指定 op_types 的层都会被压缩到 0.5 的稀疏度**。 当调用 ``pruner.compress()`` 时,模型会通过掩码进行压缩。随后还可以微调模型,此时 **被剪除的权重不会被更新**。
然后,进行自动化 然后,进行自动化
------------------------- -------------------------
前面的示例人工选择了 LevelPruner,并对所有层使用了相同的稀疏度,显然这不是最佳方法,因为不同层会有不同的冗余度。 每层的稀疏度都应该仔细调整,以便减少模型性能的下降,可通过 NNI Tuner 来完成。 上一个示例手动选择 L2FilterPruner 并使用指定的稀疏度进行剪枝。 不同的稀疏度和不同的 Pruner 对不同的模型可能有不同的影响。 这个过程可以通过 NNI Tuner 完成。
首先需要设计搜索空间,这里使用了嵌套的搜索空间,其中包含了选择的剪枝函数以及需要优化稀疏度的层。 首先,修改几行代码
.. code-block:: json
{
"prune_method": {
"_type": "choice",
"_value": [
{
"_name": "agp",
"conv0_sparsity": {
"_type": "uniform",
"_value": [
0.1,
0.9
]
},
"conv1_sparsity": {
"_type": "uniform",
"_value": [
0.1,
0.9
]
},
},
{
"_name": "level",
"conv0_sparsity": {
"_type": "uniform",
"_value": [
0.1,
0.9
]
},
"conv1_sparsity": {
"_type": "uniform",
"_value": [
0.01,
0.9
]
},
}
]
}
}
然后需要修改几行代码。
.. code-block:: python .. code-block:: python
import nni import nni
from nni.algorithms.compression.pytorch.pruning import * from nni.algorithms.compression.pytorch.pruning import *
params = nni.get_parameters() params = nni.get_parameters()
conv0_sparsity = params['prune_method']['conv0_sparsity'] sparsity = params['sparsity']
conv1_sparsity = params['prune_method']['conv1_sparsity'] pruner_name = params['pruner']
# 如果需要约束总稀疏度,则应缩放原始稀疏度 model_name = params['model']
config_list_level = [{ 'sparsity': conv0_sparsity, 'op_name': 'conv0' },
{ 'sparsity': conv1_sparsity, 'op_name': 'conv1' }] model, pruner = get_model_pruner(model_name, pruner_name, sparsity)
config_list_agp = [{'initial_sparsity': 0, 'final_sparsity': conv0_sparsity,
'start_epoch': 0, 'end_epoch': 3,
'frequency': 1,'op_name': 'conv0' },
{'initial_sparsity': 0, 'final_sparsity': conv1_sparsity,
'start_epoch': 0, 'end_epoch': 3,
'frequency': 1,'op_name': 'conv1' },]
PRUNERS = {'level':LevelPruner(model, config_list_level), 'agp':AGPPruner(model, config_list_agp)}
pruner = PRUNERS(params['prune_method']['_name'])
pruner.compress() pruner.compress()
... # 微调
acc = evaluate(model) # evaluation train(model) # 微调模型的代码
acc = test(model) # 测试微调后的模型
nni.report_final_results(acc) nni.report_final_results(acc)
后,定义任务,并使用任务来自动修剪层稀疏度。 后,在 YAML 中定义一个 ``config`` 文件来自动调整模型、剪枝算法和稀疏度。
.. code-block:: yaml .. code-block:: yaml
authorName: default searchSpace:
experimentName: Auto_Compression sparsity:
trialConcurrency: 2 _type: choice
maxExecDuration: 100h _value: [0.25, 0.5, 0.75]
maxTrialNum: 500 pruner:
#choice: local, remote, pai _type: choice
trainingServicePlatform: local _value: ['slim', 'l2filter', 'fpgm', 'apoz']
#choice: true, false model:
useAnnotation: False _type: choice
searchSpacePath: search_space.json _value: ['vgg16', 'vgg19']
trainingService:
platform: local
trialCodeDirectory: .
trialCommand: python3 basic_pruners_torch.py --nni
trialConcurrency: 1
trialGpuNumber: 0
tuner: tuner:
#choice: TPE, Random, Anneal... name: grid
builtinTunerName: TPE
classArgs: 完整实验代码在 :githublink:`这里 <examples/model_compress/pruning/config.yml>`
#choice: maximize, minimize
optimize_mode: maximize 最后,开始搜索
trial:
command: bash run_prune.sh .. code-block:: bash
codeDir: .
gpuNum: 1 nnictl create -c config.yml
模型压缩 Python API 参考 模型压缩 API 参考
============================================= =============================================
.. contents:: .. contents::
灵敏度工具 Compressor
-----------
Compressor
^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.compressor.Compressor
:members:
.. autoclass:: nni.compression.pytorch.compressor.Pruner
:members:
.. autoclass:: nni.compression.pytorch.compressor.Quantizer
:members:
module 的包装
^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.compressor.PrunerModuleWrapper
:members:
.. autoclass:: nni.compression.pytorch.compressor.QuantizerModuleWrapper
:members:
权重掩码
^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.pruning.weight_masker.WeightMasker
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.structured_pruning.StructuredWeightMasker
:members:
Pruners
^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.pruning.sensitivity_pruner.SensitivityPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.OneshotPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.LevelPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.SlimPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.L1FilterPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.L2FilterPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.FPGMPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.TaylorFOWeightFilterPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.ActivationAPoZRankFilterPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.ActivationMeanRankFilterPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.lottery_ticket.LotteryTicketPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.agp.AGPPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.admm_pruner.ADMMPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.auto_compress_pruner.AutoCompressPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.net_adapt_pruner.NetAdaptPruner
:members:
.. autoclass:: nni.algorithms.compression.pytorch.pruning.simulated_annealing_pruner.SimulatedAnnealingPruner
:members:
Quantizers
^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.quantization.quantizers.NaiveQuantizer
:members:
.. autoclass:: nni.algorithms.compression.pytorch.quantization.quantizers.QAT_Quantizer
:members:
.. autoclass:: nni.algorithms.compression.pytorch.quantization.quantizers.DoReFaQuantizer
:members:
.. autoclass:: nni.algorithms.compression.pytorch.quantization.quantizers.BNNQuantizer
:members:
压缩工具
--------------------- ---------------------
灵敏度工具
^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.utils.sensitivity_analysis.SensitivityAnalysis .. autoclass:: nni.compression.pytorch.utils.sensitivity_analysis.SensitivityAnalysis
:members: :members:
拓扑结构工具 拓扑结构工具
------------------ ^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.utils.shape_dependency.ChannelDependency .. autoclass:: nni.compression.pytorch.utils.shape_dependency.ChannelDependency
:members: :members:
...@@ -28,6 +133,6 @@ ...@@ -28,6 +133,6 @@
:members: :members:
模型 FLOPs 和参数计数器 模型 FLOPs 和参数计数器
------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: nni.compression.pytorch.utils.counter.count_flops_params .. autofunction:: nni.compression.pytorch.utils.counter.count_flops_params
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
为了简化实现新压缩算法的过程,NNI 设计了简单灵活,同时支持剪枝和量化的接口。 首先会介绍如何自定义新的剪枝算法,然后介绍如何自定义新的量化算法。 为了简化实现新压缩算法的过程,NNI 设计了简单灵活,同时支持剪枝和量化的接口。 首先会介绍如何自定义新的剪枝算法,然后介绍如何自定义新的量化算法。
**重要说明**,为了更好的理解如何定制新的剪枝、量化算法,应先了解 NNI 中支持各种剪枝算法的框架。 参考 `模型压缩框架概述 </Compression/Framework.html>`__。 **重要说明**,为了更好的理解如何定制新的剪枝、量化算法,应先了解 NNI 中支持各种剪枝算法的框架。 参考 `模型压缩框架概述 <../Compression/Framework.rst>`__。
自定义剪枝算法 自定义剪枝算法
--------------------------------- ---------------------------------
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
# mask = ... # mask = ...
return {'weight_mask': mask} return {'weight_mask': mask}
参考 NNI 提供的 :githublink:`权重掩码 <src/sdk/pynni/nni/compression/pytorch/pruning/structured_pruning.py>` 来实现自己的权重掩码。 参考 NNI 提供的 :githublink:`权重掩码 <nni/algorithms/compression/pytorch/pruning/structured_pruning.py>` 来实现自己的权重掩码。
基础的 ``Pruner`` 如下所示: 基础的 ``Pruner`` 如下所示:
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
wrapper.if_calculated = True wrapper.if_calculated = True
return masks return masks
参考 NNI 提供的 :githublink:`Pruner <src/sdk/pynni/nni/compression/pytorch/pruning/one_shot.py>` 来实现自己的 Pruner。 参考 NNI 提供的 :githublink:`Pruner <nni/algorithms/compression/pytorch/pruning/one_shot.py>` 来实现自己的 Pruner。
---- ----
......
...@@ -62,7 +62,6 @@ ...@@ -62,7 +62,6 @@
pruner.compress() pruner.compress()
评估 评估
---------- ----------
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
out = model(dummy_input) out = model(dummy_input)
print('elapsed time: ', time.time() - start) print('elapsed time: ', time.time() - start)
完整示例参考 :githublink:`这里 <examples/model_compress/model_speedup.py>`。 完整示例参考 :githublink:`这里 <examples/model_compress/pruning/model_speedup.py>`。
注意:当前支持 PyTorch 1.3.1 或更高版本。 注意:当前支持 PyTorch 1.3.1 或更高版本。
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
示例的加速结果 示例的加速结果
--------------------------- ---------------------------
实验代码在 :githublink:`这里 <examples/model_compress/model_speedup.py>`。 实验代码在 :githublink:`这里 <examples/model_compress/pruning/model_speedup.py>`。
slim Pruner 示例 slim Pruner 示例
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
...@@ -188,3 +188,13 @@ APoZ Pruner 示例 ...@@ -188,3 +188,13 @@ APoZ Pruner 示例
- 0.12421 - 0.12421
- 0.087113 - 0.087113
SimulatedAnnealing Pruner 示例
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
这个实验使用了 SimulatedAnnealing Pruner 在 cifar10 数据集上裁剪 resnet18 模型。
我们评估了剪枝模型在不同稀疏比下的延迟和精度,如下图所示。
在一块 V100 GPU 上,输入张量为 ``torch.randn(128, 3, 32, 32)``。
.. image:: ../../img/SA_latency_accuracy.png
\ No newline at end of file
...@@ -32,39 +32,39 @@ NNI 的模型压缩工具包,提供了最先进的模型压缩算法和策略 ...@@ -32,39 +32,39 @@ NNI 的模型压缩工具包,提供了最先进的模型压缩算法和策略
* - 名称 * - 名称
- 算法简介 - 算法简介
* - `Level Pruner </Compression/Pruner.html#level-pruner>`__ * - `Level Pruner <Pruner.rst#level-pruner>`__
- 根据权重的绝对值,来按比例修剪权重。 - 根据权重的绝对值,来按比例修剪权重。
* - `AGP Pruner </Compression/Pruner.html#agp-pruner>`__ * - `AGP Pruner <../Compression/Pruner.rst#agp-pruner>`__
- 自动的逐步剪枝(是否剪枝的判断:基于对模型剪枝的效果)`参考论文 <https://arxiv.org/abs/1710.01878>`__ - 自动的逐步剪枝(是否剪枝的判断:基于对模型剪枝的效果)`参考论文 <https://arxiv.org/abs/1710.01878>`__
* - `Lottery Ticket Pruner </Compression/Pruner.html#lottery-ticket-hypothesis>`__ * - `Lottery Ticket Pruner <../Compression/Pruner.rst#lottery-ticket-hypothesis>`__
- "The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks" 提出的剪枝过程。 它会反复修剪模型。 `参考论文 <https://arxiv.org/abs/1803.03635>`__ - "The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks" 提出的剪枝过程。 它会反复修剪模型。 `参考论文 <https://arxiv.org/abs/1803.03635>`__
* - `FPGM Pruner </Compression/Pruner.html#fpgm-pruner>`__ * - `FPGM Pruner <../Compression/Pruner.rst#fpgm-pruner>`__
- Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration `参考论文 <https://arxiv.org/pdf/1811.00250.pdf>`__ - Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration `参考论文 <https://arxiv.org/pdf/1811.00250.pdf>`__
* - `L1Filter Pruner </Compression/Pruner.html#l1filter-pruner>`__ * - `L1Filter Pruner <../Compression/Pruner.rst#l1filter-pruner>`__
- 在卷积层中具有最小 L1 权重规范的剪枝滤波器(用于 Efficient Convnets 的剪枝滤波器) `参考论文 <https://arxiv.org/abs/1608.08710>`__ - 在卷积层中具有最小 L1 权重规范的剪枝滤波器(用于 Efficient Convnets 的剪枝滤波器) `参考论文 <https://arxiv.org/abs/1608.08710>`__
* - `L2Filter Pruner </Compression/Pruner.html#l2filter-pruner>`__ * - `L2Filter Pruner <../Compression/Pruner.rst#l2filter-pruner>`__
- 在卷积层中具有最小 L2 权重规范的剪枝滤波器 - 在卷积层中具有最小 L2 权重规范的剪枝滤波器
* - `ActivationAPoZRankFilterPruner </Compression/Pruner.html#activationapozrankfilterpruner>`__ * - `ActivationAPoZRankFilterPruner <../Compression/Pruner.rst#activationapozrankfilter-pruner>`__
- 基于指标 APoZ(平均百分比零)的剪枝滤波器,该指标测量(卷积)图层激活中零的百分比。 `参考论文 <https://arxiv.org/abs/1607.03250>`__ - 基于指标 APoZ(平均百分比零)的剪枝滤波器,该指标测量(卷积)图层激活中零的百分比。 `参考论文 <https://arxiv.org/abs/1607.03250>`__
* - `ActivationMeanRankFilterPruner </Compression/Pruner.html#activationmeanrankfilterpruner>`__ * - `ActivationMeanRankFilterPruner <../Compression/Pruner.rst#activationmeanrankfilter-pruner>`__
- 基于计算输出激活最小平均值指标的剪枝滤波器 - 基于计算输出激活最小平均值指标的剪枝滤波器
* - `Slim Pruner </Compression/Pruner.html#slim-pruner>`__ * - `Slim Pruner <../Compression/Pruner.rst#slim-pruner>`__
- 通过修剪 BN 层中的缩放因子来修剪卷积层中的通道 (Learning Efficient Convolutional Networks through Network Slimming) `参考论文 <https://arxiv.org/abs/1708.06519>`__ - 通过修剪 BN 层中的缩放因子来修剪卷积层中的通道 (Learning Efficient Convolutional Networks through Network Slimming) `参考论文 <https://arxiv.org/abs/1708.06519>`__
* - `TaylorFO Pruner </Compression/Pruner.html#taylorfoweightfilterpruner>`__ * - `TaylorFO Pruner <../Compression/Pruner.rst#taylorfoweightfilter-pruner>`__
- 基于一阶泰勒展开的权重对滤波器剪枝 (Importance Estimation for Neural Network Pruning) `参考论文 <http://jankautz.com/publications/Importance4NNPruning_CVPR19.pdf>`__ - 基于一阶泰勒展开的权重对滤波器剪枝 (Importance Estimation for Neural Network Pruning) `参考论文 <http://jankautz.com/publications/Importance4NNPruning_CVPR19.pdf>`__
* - `ADMM Pruner </Compression/Pruner.html#admm-pruner>`__ * - `ADMM Pruner <../Compression/Pruner.rst#admm-pruner>`__
- 基于 ADMM 优化技术的剪枝 `参考论文 <https://arxiv.org/abs/1804.03294>`__ - 基于 ADMM 优化技术的剪枝 `参考论文 <https://arxiv.org/abs/1804.03294>`__
* - `NetAdapt Pruner </Compression/Pruner.html#netadapt-pruner>`__ * - `NetAdapt Pruner <../Compression/Pruner.rst#netadapt-pruner>`__
- 在满足计算资源预算的情况下,对预训练的网络迭代剪枝 `参考论文 <https://arxiv.org/abs/1804.03230>`__ - 在满足计算资源预算的情况下,对预训练的网络迭代剪枝 `参考论文 <https://arxiv.org/abs/1804.03230>`__
* - `SimulatedAnnealing Pruner </Compression/Pruner.html#simulatedannealing-pruner>`__ * - `SimulatedAnnealing Pruner <../Compression/Pruner.rst#simulatedannealing-pruner>`__
- 通过启发式的模拟退火算法进行自动剪枝 `参考论文 <https://arxiv.org/abs/1907.03141>`__ - 通过启发式的模拟退火算法进行自动剪枝 `参考论文 <https://arxiv.org/abs/1907.03141>`__
* - `AutoCompress Pruner </Compression/Pruner.html#autocompress-pruner>`__ * - `AutoCompress Pruner <../Compression/Pruner.rst#autocompress-pruner>`__
- 通过迭代调用 SimulatedAnnealing Pruner 和 ADMM Pruner 进行自动剪枝 `参考论文 - <https://arxiv.org/abs/1907.03141>`__ - 通过迭代调用 SimulatedAnnealing Pruner 和 ADMM Pruner 进行自动剪枝 `参考论文 - <https://arxiv.org/abs/1907.03141>`__
* - `AMC Pruner </Compression/Pruner.html#amc-pruner>`__ * - `AMC Pruner <../Compression/Pruner.rst#amc-pruner>`__
- AMC:移动设备的模型压缩和加速 `参考论文 <https://arxiv.org/pdf/1802.03494.pdf>`__ - AMC:移动设备的模型压缩和加速 `参考论文 <https://arxiv.org/pdf/1802.03494.pdf>`__
参考此 `基准测试 <../CommunitySharings/ModelCompressionComparison.rst>`__ 来查看这些剪枝器在一些基准问题上的表现。 参考此 :githublink:`基准测试 <../CommunitySharings/ModelCompressionComparison.rst>` 来查看这些剪枝器在一些基准问题上的表现。
量化算法 量化算法
^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
...@@ -77,21 +77,16 @@ NNI 的模型压缩工具包,提供了最先进的模型压缩算法和策略 ...@@ -77,21 +77,16 @@ NNI 的模型压缩工具包,提供了最先进的模型压缩算法和策略
* - 名称 * - 名称
- 算法简介 - 算法简介
* - `Naive Quantizer </Compression/Quantizer.html#naive-quantizer>`__ * - `Naive Quantizer <../Compression/Quantizer.rst#naive-quantizer>`__
- 默认将权重量化为 8 位 - 默认将权重量化为 8 位
* - `QAT Quantizer </Compression/Quantizer.html#qat-quantizer>`__ * - `QAT Quantizer <../Compression/Quantizer.rst#qat-quantizer>`__
- 为 Efficient Integer-Arithmetic-Only Inference 量化并训练神经网络。 `参考论文 <http://openaccess.thecvf.com/content_cvpr_2018/papers/Jacob_Quantization_and_Training_CVPR_2018_paper.pdf>`__ - 为 Efficient Integer-Arithmetic-Only Inference 量化并训练神经网络。 `参考论文 <http://openaccess.thecvf.com/content_cvpr_2018/papers/Jacob_Quantization_and_Training_CVPR_2018_paper.pdf>`__
* - `DoReFa Quantizer </Compression/Quantizer.html#dorefa-quantizer>`__ * - `DoReFa Quantizer <../Compression/Quantizer.rst#dorefa-quantizer>`__
- DoReFa-Net: 通过低位宽的梯度算法来训练低位宽的卷积神经网络。 `参考论文 <https://arxiv.org/abs/1606.06160>`__ - DoReFa-Net: 通过低位宽的梯度算法来训练低位宽的卷积神经网络。 `参考论文 <https://arxiv.org/abs/1606.06160>`__
* - `BNN Quantizer </Compression/Quantizer.html#bnn-quantizer>`__ * - `BNN Quantizer <../Compression/Quantizer.rst#bnn-quantizer>`__
- 二进制神经网络:使用权重和激活限制为 +1 或 -1 的深度神经网络。 `参考论文 <https://arxiv.org/abs/1602.02830>`__ - 二进制神经网络:使用权重和激活限制为 +1 或 -1 的深度神经网络。 `参考论文 <https://arxiv.org/abs/1602.02830>`__
自动模型压缩
---------------------------
有时,给定的目标压缩率很难通过一次压缩就得到最好的结果。 自动模型压缩算法,通常需要通过对不同层采用不同的稀疏度来探索可压缩的空间。 NNI 提供了这样的算法,来帮助用户在模型中为每一层指定压缩度。 此外,还可利用 NNI 的自动调参功能来自动的压缩模型。 详细文档参考 `这里 <./AutoPruningUsingTuners.rst>`__。
模型加速 模型加速
------------- -------------
...@@ -102,10 +97,11 @@ NNI 的模型压缩工具包,提供了最先进的模型压缩算法和策略 ...@@ -102,10 +97,11 @@ NNI 的模型压缩工具包,提供了最先进的模型压缩算法和策略
压缩工具包括了一些有用的工具,能帮助用户理解并分析要压缩的模型。 例如,可检查每层对剪枝的敏感度。 可很容易的计算模型的 FLOPs 和参数数量。 `点击这里 <./CompressionUtils.rst>`__,查看压缩工具的完整列表。 压缩工具包括了一些有用的工具,能帮助用户理解并分析要压缩的模型。 例如,可检查每层对剪枝的敏感度。 可很容易的计算模型的 FLOPs 和参数数量。 `点击这里 <./CompressionUtils.rst>`__,查看压缩工具的完整列表。
自定义压缩算法 高级用法
----------------------------------------- --------------
NNI 模型压缩提供了简洁的接口,用于自定义新的压缩算法。 接口的设计理念是,将框架相关的实现细节包装起来,让用户能聚焦于压缩逻辑。 用户可以进一步了解我们的压缩框架,并根据我们的框架定制新的压缩算法(剪枝算法或量化算法)。 此外,还可利用 NNI 的自动调参功能来自动的压缩模型。 参考 `这里 <./advanced.rst>`__ 了解更多细节。
NNI 模型压缩提供了简洁的接口,用于自定义新的压缩算法。 接口的设计理念是,将框架相关的实现细节包装起来,让用户能聚焦于压缩逻辑。 点击 `这里 <./Framework.rst>`__,查看自定义新压缩算法(包括剪枝和量化算法)的详细教程。
参考和反馈 参考和反馈
---------------------- ----------------------
......
NNI 支持的剪枝算法 NNI 支持的剪枝算法
=================================== ===================================
NNI 提供了一些支持细粒度权重剪枝和结构化的滤波器剪枝算法。 **细粒度剪枝** 通常会导致非结构化模型,这需要特定的硬件或软件来加速这样的稀疏网络。 NNI 还提供了算法来进行 **剪枝规划** NNI 提供了一些支持细粒度权重剪枝和结构化的滤波器剪枝算法。 **细粒度剪枝** 通常会生成非结构化模型,这需要专门的硬件或软件来加速稀疏网络。 **滤波器剪枝** 通过移除整个滤波器来实现加速。 一些剪枝算法使用 One-Shot 的方法,即根据重要性指标一次性剪枝权重。 其他剪枝算法控制在优化过程中剪枝权重的 **剪枝调度**,包括一些自动剪枝算法
**细粒度剪枝**
**细粒度剪枝**
* `Level Pruner <#level-pruner>`__ * `Level Pruner <#level-pruner>`__
**滤波器剪枝** **滤波器剪枝**
* `Slim Pruner <#slim-pruner>`__ * `Slim Pruner <#slim-pruner>`__
* `FPGM Pruner <#fpgm-pruner>`__ * `FPGM Pruner <#fpgm-pruner>`__
* `L1Filter Pruner <#l1filter-pruner>`__ * `L1Filter Pruner <#l1filter-pruner>`__
...@@ -21,7 +20,6 @@ NNI 提供了一些支持细粒度权重剪枝和结构化的滤波器剪枝算 ...@@ -21,7 +20,6 @@ NNI 提供了一些支持细粒度权重剪枝和结构化的滤波器剪枝算
**剪枝计划** **剪枝计划**
* `AGP Pruner <#agp-pruner>`__ * `AGP Pruner <#agp-pruner>`__
* `NetAdapt Pruner <#netadapt-pruner>`__ * `NetAdapt Pruner <#netadapt-pruner>`__
* `SimulatedAnnealing Pruner <#simulatedannealing-pruner>`__ * `SimulatedAnnealing Pruner <#simulatedannealing-pruner>`__
...@@ -31,7 +29,6 @@ NNI 提供了一些支持细粒度权重剪枝和结构化的滤波器剪枝算 ...@@ -31,7 +29,6 @@ NNI 提供了一些支持细粒度权重剪枝和结构化的滤波器剪枝算
**其它** **其它**
* `ADMM Pruner <#admm-pruner>`__ * `ADMM Pruner <#admm-pruner>`__
* `Lottery Ticket Hypothesis <#lottery-ticket-hypothesis>`__ * `Lottery Ticket Hypothesis <#lottery-ticket-hypothesis>`__
...@@ -45,15 +42,6 @@ Level Pruner ...@@ -45,15 +42,6 @@ Level Pruner
用法 用法
^^^^^ ^^^^^
TensorFlow 代码
.. code-block:: python
from nni.algorithms.compression.tensorflow.pruning import LevelPruner
config_list = [{ 'sparsity': 0.8, 'op_types': ['default'] }]
pruner = LevelPruner(model, config_list)
pruner.compress()
PyTorch 代码 PyTorch 代码
.. code-block:: python .. code-block:: python
...@@ -70,26 +58,14 @@ PyTorch ...@@ -70,26 +58,14 @@ PyTorch
.. autoclass:: nni.algorithms.compression.pytorch.pruning.LevelPruner .. autoclass:: nni.algorithms.compression.pytorch.pruning.LevelPruner
TensorFlow **TensorFlow**
""""""""""
.. autoclass:: nni.algorithms.compression.tensorflow.pruning.LevelPruner .. autoclass:: nni.algorithms.compression.tensorflow.pruning.LevelPruner
Slim Pruner Slim Pruner
----------- -----------
这是 One-Shot Pruner,它在训练过程中对 batch normalization(BN)层的比例因子进行稀疏正则化,以识别不重要的通道。 比例因子值较小的通道将被修剪。 更多细节,请参考论文 `'Learning Efficient Convolutional Networks through Network Slimming' <https://arxiv.org/pdf/1708.06519.pdf>`__\。
这是一次性的 Pruner,在 `Learning Efficient Convolutional Networks through Network Slimming <https://arxiv.org/pdf/1708.06519.pdf>`__ 中提出,作者 Zhuang Liu, Jianguo Li, Zhiqiang Shen, Gao Huang, Shoumeng Yan 以及 Changshui Zhang。
.. image:: ../../img/slim_pruner.png
:target: ../../img/slim_pruner.png
:alt:
..
Slim Pruner **会遮盖卷据层通道之后 BN 层对应的缩放因子**,训练时在缩放因子上的 L1 正规化应在批量正规化 (BN) 层之后来做。BN 层的缩放因子在修剪时,是 **全局排序的**,因此稀疏模型能自动找到给定的稀疏度。
用法 用法
^^^^^ ^^^^^
...@@ -124,36 +100,29 @@ Slim Pruner 的用户配置 ...@@ -124,36 +100,29 @@ Slim Pruner 的用户配置
- 参数量 - 参数量
- 剪除率 - 剪除率
* - VGGNet * - VGGNet
- 6.34/6.40 - 6.34/6.69
- 20.04M - 20.04M
- -
* - Pruned-VGGNet * - Pruned-VGGNet
- 6.20/6.26 - 6.20/6.34
- 2.03M - 2.03M
- 88.5% - 88.5%
实验代码在 :githublink:`这里 <examples/model_compress/>` 实验代码在 :githublink:`examples/model_compress/pruning/basic_pruners_torch.py <examples/model_compress/pruning/basic_pruners_torch.py>`
----
FPGM Pruner
-----------
这是一种一次性的 Pruner,FPGM Pruner 是论文 `Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration <https://arxiv.org/pdf/1811.00250.pdf>`__ 的实现
具有最小几何中位数的 FPGMPruner 修剪滤波器。
.. code-block:: python
.. image:: ../../img/fpgm_fig1.png python basic_pruners_torch.py --pruner slim --model vgg19 --sparsity 0.7 --speed-up
:target: ../../img/fpgm_fig1.png
:alt:
.. ----
以前的方法使用 “smaller-norm-less-important” 准则来修剪卷积神经网络中规范值较小的。 本文中,分析了基于规范的准则,并指出其所依赖的两个条件不能总是满足:(1) 过滤器的规范偏差应该较大;(2) 过滤器的最小规范化值应该很小。 为了解决此问题,提出了新的过滤器修建方法,即 Filter Pruning via Geometric Median (FPGM),可不考虑这两个要求来压缩模型。 与以前的方法不同,FPGM 通过修剪冗余的,而不是相关性更小的部分来压缩 CNN 模型。 FPGM Pruner
-----------
这是一个 One-Shot Pruner,用最小的几何中值修剪滤波器。 FPGM 选择最可替换的滤波器。
更多细节,请参考 `Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration <https://arxiv.org/pdf/1811.00250.pdf>`__ 。
我们还为这个 Pruner 提供了一个依赖感知模式,以更好地提高修剪的速度。 请参考 `dependency-aware <./DependencyAware.rst>`__ 获取更多信息。 我们还为这个 Pruner 提供了一个依赖感知模式,以更好地提高修剪的速度。 请参考 `dependency-aware <./DependencyAware.rst>`__ 获取更多信息。
...@@ -182,21 +151,11 @@ FPGM Pruner 的用户配置 ...@@ -182,21 +151,11 @@ FPGM Pruner 的用户配置
L1Filter Pruner L1Filter Pruner
--------------- ---------------
这是一种一次性的 Pruner,由 `PRUNING FILTERS FOR EFFICIENT CONVNETS <https://arxiv.org/abs/1608.08710>`__ 提出,作者 Hao Li, Asim Kadav, Igor Durdanovic, Hanan Samet 和 Hans Peter Graf。 这是一个 One-Shot Pruner,它修剪 **卷积层** 中的滤波器。
.. image:: ../../img/l1filter_pruner.png
:target: ../../img/l1filter_pruner.png
:alt:
.. ..
L1Filter Pruner 修剪 **卷积层** 中的过滤器
从第 i 个卷积层修剪 m 个过滤器的过程如下: 从第 i 个卷积层修剪 m 个过滤器的过程如下:
#. 对于每个滤波器 :math:`F_{i,j}`,计算其绝对内核权重之和 :math:`s_j=\sum_{l=1}^{n_i}\sum|K_l|`. #. 对于每个滤波器 :math:`F_{i,j}`,计算其绝对内核权重之和 :math:`s_j=\sum_{l=1}^{n_i}\sum|K_l|`.
#. 将滤波器按 by :math:`s_j` 排序 #. 将滤波器按 by :math:`s_j` 排序
...@@ -207,6 +166,9 @@ L1Filter Pruner ...@@ -207,6 +166,9 @@ L1Filter Pruner
#. 为第 :math:`i` 层和第 :math:`i+1` 层创建新的内核权重, #. 为第 :math:`i` 层和第 :math:`i+1` 层创建新的内核权重,
并保留剩余的内核 权重,复制到新模型中。 并保留剩余的内核 权重,复制到新模型中。
更多细节,请参考 `PRUNING FILTERS FOR EFFICIENT CONVNETS <https://arxiv.org/abs/1608.08710>`__ 。
此外,我们还为 L1FilterPruner 提供了依赖感知模式。 参考 `dependency-aware mode <./DependencyAware.rst>`__ 获取依赖感知模式的更多细节。 此外,我们还为 L1FilterPruner 提供了依赖感知模式。 参考 `dependency-aware mode <./DependencyAware.rst>`__ 获取依赖感知模式的更多细节。
...@@ -252,7 +214,11 @@ L1Filter Pruner 的用户配置 ...@@ -252,7 +214,11 @@ L1Filter Pruner 的用户配置
- 64.0% - 64.0%
实验代码在 :githublink:`这里 <examples/model_compress/>` 实验代码在 :githublink:`examples/model_compress/pruning/basic_pruners_torch.py <examples/model_compress/pruning/basic_pruners_torch.py>`
.. code-block:: python
python basic_pruners_torch.py --pruner l1filter --model vgg16 --speed-up
---- ----
...@@ -291,10 +257,7 @@ ActivationAPoZRankFilter Pruner 是从卷积层激活的输出,用最小的重 ...@@ -291,10 +257,7 @@ ActivationAPoZRankFilter Pruner 是从卷积层激活的输出,用最小的重
APoZ 定义为: APoZ 定义为:
:math:`APoZ_{c}^{(i)} = APoZ\left(O_{c}^{(i)}\right)=\frac{\sum_{k}^{N} \sum_{j}^{M} f\left(O_{c, j}^{(i)}(k)=0\right)}{N \times M}`
.. image:: ../../img/apoz.png
:target: ../../img/apoz.png
:alt:
我们还为这个 Pruner 提供了一个依赖感知模式,以更好地提高修剪的速度。 请参考 `dependency-aware <./DependencyAware.rst>`__ 获取更多信息。 我们还为这个 Pruner 提供了一个依赖感知模式,以更好地提高修剪的速度。 请参考 `dependency-aware <./DependencyAware.rst>`__ 获取更多信息。
...@@ -316,7 +279,7 @@ PyTorch 代码 ...@@ -316,7 +279,7 @@ PyTorch 代码
注意:ActivationAPoZRankFilterPruner 用于修剪深度神经网络中的卷积层,因此 ``op_types`` 字段仅支持卷积层。 注意:ActivationAPoZRankFilterPruner 用于修剪深度神经网络中的卷积层,因此 ``op_types`` 字段仅支持卷积层。
参考 :githublink:`示例 <examples/model_compress/model_prune_torch.py>` 了解更多信息。 参考 :githublink:`示例 <examples/model_compress/pruning/basic_pruners_torch.py>` 获取更多信息。
ActivationAPoZRankFilterPruner 的用户配置 ActivationAPoZRankFilterPruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -352,7 +315,7 @@ PyTorch 代码 ...@@ -352,7 +315,7 @@ PyTorch 代码
注意:ActivationMeanRankFilterPruner 用于修剪深度神经网络中的卷积层,因此 ``op_types`` 字段仅支持卷积层。 注意:ActivationMeanRankFilterPruner 用于修剪深度神经网络中的卷积层,因此 ``op_types`` 字段仅支持卷积层。
参考 :githublink:`示例 <examples/model_compress/model_prune_torch.py>` 了解更多信息。 参考 :githublink:`示例 <examples/model_compress/pruning/basic_pruners_torch.py>` 获取更多信息。
ActivationMeanRankFilterPruner 的用户配置 ActivationMeanRankFilterPruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -370,13 +333,7 @@ TaylorFOWeightFilter Pruner 根据权重上的一阶泰勒展开式,来估计 ...@@ -370,13 +333,7 @@ TaylorFOWeightFilter Pruner 根据权重上的一阶泰勒展开式,来估计
.. ..
:math:`\widehat{\mathcal{I}}_{\mathcal{S}}^{(1)}(\mathbf{W}) \triangleq \sum_{s \in \mathcal{S}} \mathcal{I}_{s}^{(1)}(\mathbf{W})=\sum_{s \in \mathcal{S}}\left(g_{s} w_{s}\right)^{2}`
.. image:: ../../img/importance_estimation_sum.png
:target: ../../img/importance_estimation_sum.png
:alt:
我们还为这个 Pruner 提供了一个依赖感知模式,以更好地提高修剪的速度。 请参考 `dependency-aware <./DependencyAware.rst>`__ 获取更多信息。 我们还为这个 Pruner 提供了一个依赖感知模式,以更好地提高修剪的速度。 请参考 `dependency-aware <./DependencyAware.rst>`__ 获取更多信息。
...@@ -408,18 +365,11 @@ TaylorFOWeightFilter Pruner 的用户配置 ...@@ -408,18 +365,11 @@ TaylorFOWeightFilter Pruner 的用户配置
AGP Pruner AGP Pruner
---------- ----------
这是一种迭代的 Pruner,在 `To prune, or not to prune: exploring the efficacy of pruning for model compression <https://arxiv.org/abs/1710.01878>`__ 中,作者 Michael Zhu 和 Suyog Gupta 提出了一种逐渐修建权重的算法。 这是一种新的自动逐步剪枝算法,在 n 个剪枝步骤中,稀疏度从初始的稀疏度值 si(通常为 0)增加到最终的稀疏度值 sf,从训练步骤 :math:`t_{0}` 开始,剪枝频率 :math:`\Delta t` :
..
引入了一种新的自动逐步剪枝算法,在 n 个剪枝步骤中,稀疏度从初始的稀疏度值 si(通常为 0)增加到最终的稀疏度值 sf,从训练步骤 t0 开始,剪枝频率 ∆t:
.. image:: ../../img/agp_pruner.png
:target: ../../img/agp_pruner.png
:alt:
:math:`s_{t}=s_{f}+\left(s_{i}-s_{f}\right)\left(1-\frac{t-t_{0}}{n \Delta t}\right)^{3} \text { for } t \in\left\{t_{0}, t_{0}+\Delta t, \ldots, t_{0} + n \Delta t\right\}`
在训练网络时,每隔 ∆t 步更新二值权重掩码,以逐渐增加网络的稀疏性,同时允许网络训练步骤从任何剪枝导致的精度损失中恢复。 根据我们的经验,∆t 设为 100 到 1000 个训练步骤之间时,对于模型最终精度的影响可忽略不计。 一旦模型达到了稀疏度目标 sf,权重掩码将不再更新。 背后的稀疏函数直觉在公式(1) 参考 `To prune, or not to prune: exploring the efficacy of pruning for model compression <https://arxiv.org/abs/1710.01878>`__\ 获取更多细节信息
用法 用法
...@@ -472,7 +422,6 @@ PyTorch 代码 ...@@ -472,7 +422,6 @@ PyTorch 代码
pruner.update_epoch(epoch) pruner.update_epoch(epoch)
参考 :githublink:`示例 <examples/model_compress/model_prune_torch.py>` 了解更多信息。
AGP Pruner 的用户配置 AGP Pruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -492,11 +441,6 @@ NetAdapt 在满足资源预算的情况下,自动简化预训练的网络。 ...@@ -492,11 +441,6 @@ NetAdapt 在满足资源预算的情况下,自动简化预训练的网络。
参考 `NetAdapt: Platform-Aware Neural Network Adaptation for Mobile Applications <https://arxiv.org/abs/1804.03230>`__ 了解详细信息。 参考 `NetAdapt: Platform-Aware Neural Network Adaptation for Mobile Applications <https://arxiv.org/abs/1804.03230>`__ 了解详细信息。
.. image:: ../../img/algo_NetAdapt.png
:target: ../../img/algo_NetAdapt.png
:alt:
用法 用法
^^^^^ ^^^^^
...@@ -512,7 +456,7 @@ PyTorch 代码 ...@@ -512,7 +456,7 @@ PyTorch 代码
pruner = NetAdaptPruner(model, config_list, short_term_fine_tuner=short_term_fine_tuner, evaluator=evaluator,base_algo='l1', experiment_data_dir='./') pruner = NetAdaptPruner(model, config_list, short_term_fine_tuner=short_term_fine_tuner, evaluator=evaluator,base_algo='l1', experiment_data_dir='./')
pruner.compress() pruner.compress()
参考 :githublink:`示例 <examples/model_compress/auto_pruners_torch.py>` 了解更多信息。 参考 :githublink:`示例 <examples/model_compress/pruning/auto_pruners_torch.py>` 了解更多信息。
NetAdapt Pruner 的用户配置 NetAdapt Pruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -553,7 +497,7 @@ PyTorch 代码 ...@@ -553,7 +497,7 @@ PyTorch 代码
pruner = SimulatedAnnealingPruner(model, config_list, evaluator=evaluator, base_algo='l1', cool_down_rate=0.9, experiment_data_dir='./') pruner = SimulatedAnnealingPruner(model, config_list, evaluator=evaluator, base_algo='l1', cool_down_rate=0.9, experiment_data_dir='./')
pruner.compress() pruner.compress()
参考 :githublink:`示例 <examples/model_compress/auto_pruners_torch.py>` 了解更多信息。 参考 :githublink:`示例 <examples/model_compress/pruning/auto_pruners_torch.py>` 了解更多信息。
SimulatedAnnealing Pruner 的用户配置 SimulatedAnnealing Pruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -583,7 +527,7 @@ PyTorch 代码 ...@@ -583,7 +527,7 @@ PyTorch 代码
.. code-block:: python .. code-block:: python
from nni.algorithms.compression.pytorch.pruning import ADMMPruner from nni.algorithms.compression.pytorch.pruning import AutoCompressPruner
config_list = [{ config_list = [{
'sparsity': 0.5, 'sparsity': 0.5,
'op_types': ['Conv2d'] 'op_types': ['Conv2d']
...@@ -594,7 +538,7 @@ PyTorch 代码 ...@@ -594,7 +538,7 @@ PyTorch 代码
cool_down_rate=0.9, admm_num_iterations=30, admm_training_epochs=5, experiment_data_dir='./') cool_down_rate=0.9, admm_num_iterations=30, admm_training_epochs=5, experiment_data_dir='./')
pruner.compress() pruner.compress()
参考 :githublink:`示例 <examples/model_compress/auto_pruners_torch.py>` 了解更多信息。 参考 :githublink:`示例 <examples/model_compress/pruning/auto_pruners_torch.py>` 了解更多信息。
AutoCompress Pruner 的用户配置 AutoCompress Pruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -611,11 +555,6 @@ AMC Pruner 利用强化学习来提供模型压缩策略。 ...@@ -611,11 +555,6 @@ AMC Pruner 利用强化学习来提供模型压缩策略。
更好地保存了精度,节省了人力。 更好地保存了精度,节省了人力。
.. image:: ../../img/amc_pruner.jpg
:target: ../../img/amc_pruner.jpg
:alt:
更多信息请参考 `AMC: AutoML for Model Compression and Acceleration on Mobile Devices <https://arxiv.org/pdf/1802.03494.pdf>`__。 更多信息请参考 `AMC: AutoML for Model Compression and Acceleration on Mobile Devices <https://arxiv.org/pdf/1802.03494.pdf>`__。
用法 用法
...@@ -632,9 +571,9 @@ PyTorch 代码 ...@@ -632,9 +571,9 @@ PyTorch 代码
pruner = AMCPruner(model, config_list, evaluator, val_loader, flops_ratio=0.5) pruner = AMCPruner(model, config_list, evaluator, val_loader, flops_ratio=0.5)
pruner.compress() pruner.compress()
你可以参考 :githublink:`示例 <examples/model_compress/amc/>` 获取更多信息。 你可以参考 :githublink:`示例 <examples/model_compress/pruning/amc/>` 获取更多信息。
AutoCompress Pruner 的用户配置 AMC Pruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**PyTorch** **PyTorch**
...@@ -660,7 +599,7 @@ AutoCompress Pruner 的用户配置 ...@@ -660,7 +599,7 @@ AutoCompress Pruner 的用户配置
- 50% - 50%
实验代码在 :githublink:`这里 <examples/model_compress/amc/>`。 实验代码在 :githublink:`这里 <examples/model_compress/pruning/amc/>`。
ADMM Pruner ADMM Pruner
----------- -----------
...@@ -694,7 +633,7 @@ PyTorch 代码 ...@@ -694,7 +633,7 @@ PyTorch 代码
pruner = ADMMPruner(model, config_list, trainer=trainer, num_iterations=30, epochs=5) pruner = ADMMPruner(model, config_list, trainer=trainer, num_iterations=30, epochs=5)
pruner.compress() pruner.compress()
参考 :githublink:`示例 <examples/model_compress/auto_pruners_torch.py>` 了解更多信息。 参考 :githublink:`示例 <examples/model_compress/pruning/auto_pruners_torch.py>` 了解更多信息。
ADMM Pruner 的用户配置 ADMM Pruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -743,7 +682,6 @@ PyTorch 代码 ...@@ -743,7 +682,6 @@ PyTorch 代码
上述配置意味着有 5 次迭代修剪。 由于在同一次运行中执行了 5 次修剪,LotteryTicketPruner 需要 ``model`` 和 ``optimizer`` ( **注意,如果使用 ``lr_scheduler``,也需要添加** ) 来在每次开始新的修剪迭代时,将其状态重置为初始值。 使用 ``get_prune_iterations`` 来获取修建迭代,并在每次迭代开始时调用 ``prune_iteration_start``。 为了模型能较好收敛,``epoch_num`` 最好足够大。因为假设是在后几轮中具有较高稀疏度的性能(准确度)可与第一轮获得的相当。 上述配置意味着有 5 次迭代修剪。 由于在同一次运行中执行了 5 次修剪,LotteryTicketPruner 需要 ``model`` 和 ``optimizer`` ( **注意,如果使用 ``lr_scheduler``,也需要添加** ) 来在每次开始新的修剪迭代时,将其状态重置为初始值。 使用 ``get_prune_iterations`` 来获取修建迭代,并在每次迭代开始时调用 ``prune_iteration_start``。 为了模型能较好收敛,``epoch_num`` 最好足够大。因为假设是在后几轮中具有较高稀疏度的性能(准确度)可与第一轮获得的相当。
*稍后支持 TensorFlow 版本。*
LotteryTicket Pruner 的用户配置 LotteryTicket Pruner 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -755,7 +693,7 @@ LotteryTicket Pruner 的用户配置 ...@@ -755,7 +693,7 @@ LotteryTicket Pruner 的用户配置
复现实验 复现实验
^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
在重现时,在 MNIST 使用了与论文相同的配置。 实验代码在 :githublink:`这里 <examples/model_compress/lottery_torch_mnist_fc.py>` 在次实验中,修剪了10次,在每次修剪后,训练了 50 个 epoch。 在重现时,在 MNIST 使用了与论文相同的配置。 实验代码在 :githublink:`这里 <examples/model_compress/pruning/lottery_torch_mnist_fc.py>`. 在次实验中,修剪了10次,在每次修剪后,训练了 50 个 epoch。
.. image:: ../../img/lottery_ticket_mnist_fc.png .. image:: ../../img/lottery_ticket_mnist_fc.png
......
...@@ -157,7 +157,7 @@ PyTorch 代码 ...@@ -157,7 +157,7 @@ PyTorch 代码
quantizer = BNNQuantizer(model, configure_list) quantizer = BNNQuantizer(model, configure_list)
model = quantizer.compress() model = quantizer.compress()
可以查看 :githublink:`示例 <examples/model_compress/BNN_quantizer_cifar10.py>` 了解更多信息。 可以查看 :githublink:`示例 <examples/model_compress/quantization/BNN_quantizer_cifar10.py>` 了解更多信息。
BNN Quantizer 的用户配置 BNN Quantizer 的用户配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -181,4 +181,4 @@ BNN Quantizer 的用户配置 ...@@ -181,4 +181,4 @@ BNN Quantizer 的用户配置
- 86.93% - 86.93%
实验代码在 :githublink:`examples/model_compress/BNN_quantizer_cifar10.py <examples/model_compress/BNN_quantizer_cifar10.py>` 实验代码在 :githublink:`examples/model_compress/BNN_quantizer_cifar10.py <examples/model_compress/quantization/BNN_quantizer_cifar10.py>`
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment