This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Chinese documentation (#3886)
- Loading branch information
Showing
94 changed files
with
2,746 additions
and
2,542 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK --> | ||
|
||
## 安全 | ||
|
||
微软非常重视软件产品和服务的安全性,包括通过我们的 GitHub 组织管理的所有源代码库,其中涵盖 [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin),和 [我们 GitHub 的组织](https://opensource.microsoft.com/)。 | ||
|
||
如果你在任何微软拥有的资源库中发现了安全漏洞,并且符合 [微软对安全漏洞的定义](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)),请按照下文所述向我们报告。 | ||
|
||
## 报告安全问题 | ||
|
||
**请不要通过公开的 GitHub 问题报告安全漏洞。** | ||
|
||
相反,请向微软安全响应中心(MSRC)报告,链接是 [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report)。 | ||
|
||
如果您希望在不登录的情况下提交,请发送电子邮件至 [secure@microsoft.com](mailto:secure@microsoft.com)。 如果可能的话,请用我们的 PGP 密钥对您的信息进行加密;请从以下网站下载该密钥 [微软安全响应中心 PGP 密钥页面](https://www.microsoft.com/en-us/msrc/pgp-key-msrc)。 | ||
|
||
你应该在24小时内收到回复。 如果由于某些原因你没有收到,请通过电子邮件跟进,以确保我们收到你的原始信息。 其他信息可以在以下网站找到 [microsoft.com/msrc](https://www.microsoft.com/msrc)。 | ||
|
||
请包括以下所要求的信息(尽可能多地提供),以帮助我们更好地了解可能的问题的性质和范围。 | ||
|
||
* 问题类型(如缓冲区溢出、SQL 注入、跨站脚本等) | ||
* 与问题表现有关的源文件的完整路径 | ||
* 受影响的源代码位置(标签/分支/提交或 URL) | ||
* 重现该问题所需的任何特殊配置 | ||
* 重现该问题的分步骤说明 | ||
* 概念证明或漏洞代码(如果可能的话) | ||
* 该问题的影响,包括攻击者如何利用该问题 | ||
|
||
这些信息将帮助我们更快地对你的报告进行分流。 | ||
|
||
如果您需要报告错误赏金,更完整的报告可有助于获得更高的赏金奖励。 请访问我们的[微软漏洞赏金计划](https://microsoft.com/msrc/bounty)页面,以了解有关我们活动计划的更多详细信息。 | ||
|
||
## 首选语言 | ||
|
||
我们希望所有的交流都是用英语进行的。 | ||
|
||
## 政策 | ||
|
||
微软遵循[协调漏洞披露](https://www.microsoft.com/en-us/msrc/cvd)的原则。 | ||
|
||
<!-- END MICROSOFT SECURITY.MD BLOCK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
使用 NNI Experiment 自动压缩 | ||
================================================ | ||
|
||
如果你想压缩你的模型,但不知道该选择什么压缩算法,或者不知道什么稀疏度适合你的模型,或者只是想尝试更多的可能性,自动压缩可能会帮助你。 | ||
用户可以选择不同的压缩算法,并定义算法的搜索空间,然后自动压缩将启动一个 NNI 实验,并自动尝试不同稀疏度的压缩算法。 | ||
当然,除了稀疏度之外,用户还可以在搜索空间中引入其他相关参数。 | ||
如果你不知道什么是搜索空间或如何编写搜索空间,可以参考 `此教程 <./Tutorial/SearchSpaceSpec.rst>`__ 。 | ||
在 Python 中使用自动压缩与 NNI Experiment 很相似。 | ||
主要区别如下: | ||
|
||
* 使用生成器帮助生成搜索空间对象 | ||
* 需要提供要压缩的模型,并且模型应该已经过预训练 | ||
* 不需要设置 ``trial_command``,需要额外设置 ``auto_compress_module`` 作为 ``AutoCompressionExperiment`` 的输入。 | ||
|
||
生成搜索空间 | ||
--------------------- | ||
|
||
由于大量使用嵌套搜索空间,我们建议使用生成器来配置搜索空间。 | ||
示例如下: 使用 ``add_config()`` 增加子配置,然后 ``dumps()`` 搜索空间字典。 | ||
|
||
.. code-block:: python | ||
from nni.algorithms.compression.pytorch.auto_compress import AutoCompressionSearchSpaceGenerator | ||
generator = AutoCompressionSearchSpaceGenerator() | ||
generator.add_config('level', [ | ||
{ | ||
"sparsity": { | ||
"_type": "uniform", | ||
"_value": [0.01, 0.99] | ||
}, | ||
'op_types': ['default'] | ||
} | ||
]) | ||
generator.add_config('qat', [ | ||
{ | ||
'quant_types': ['weight', 'output'], | ||
'quant_bits': { | ||
'weight': 8, | ||
'output': 8 | ||
}, | ||
'op_types': ['Conv2d', 'Linear'] | ||
}]) | ||
search_space = generator.dumps() | ||
目前我们支持以下 Pruner 和 Quantizer: | ||
|
||
.. code-block:: python | ||
PRUNER_DICT = { | ||
'level': LevelPruner, | ||
'slim': SlimPruner, | ||
'l1': L1FilterPruner, | ||
'l2': L2FilterPruner, | ||
'fpgm': FPGMPruner, | ||
'taylorfo': TaylorFOWeightFilterPruner, | ||
'apoz': ActivationAPoZRankFilterPruner, | ||
'mean_activation': ActivationMeanRankFilterPruner | ||
} | ||
QUANTIZER_DICT = { | ||
'naive': NaiveQuantizer, | ||
'qat': QAT_Quantizer, | ||
'dorefa': DoReFaQuantizer, | ||
'bnn': BNNQuantizer | ||
} | ||
提供用户模型进行压缩 | ||
---------------------------------------------- | ||
|
||
用户需要继承 ``AbstractAutoCompressionModule`` 并重写抽象类的函数。 | ||
|
||
.. code-block:: python | ||
from nni.algorithms.compression.pytorch.auto_compress import AbstractAutoCompressionModule | ||
class AutoCompressionModule(AbstractAutoCompressionModule): | ||
@classmethod | ||
def model(cls) -> nn.Module: | ||
... | ||
return _model | ||
@classmethod | ||
def evaluator(cls) -> Callable[[nn.Module], float]: | ||
... | ||
return _evaluator | ||
用户至少需要实现 ``model()`` 和 ``evaluator()``。 | ||
如果使用迭代 Pruner,则需要额外实现 ``optimizer_factory()``, ``criterion()`` 和 ``sparsifying_trainer()``。 | ||
如果要在压缩后对模型进行微调,则需要实现 ``optimizer_factory()``, ``criterion()``, ``post_compress_finetuning_trainer()`` 和 ``post_compress_finetuning_epochs()``。 | ||
``optimizer_factory()`` 应该返回一个工厂函数,输入是一个可迭代变量,即, 你的 ``model.parameters()``,输出是 optimizer 实例。 | ||
这两种 ``trainer()`` 应该返回一个输出为 ``model, optimizer, criterion, current_epoch`` 的 Trainer。 | ||
完整的抽象接口在 :githublink:`interface.py <nni/algorithms/compression/pytorch/auto_compress/interface.py>`。 | ||
``AutoCompressionModule`` 实施的例子参考 :githublink:`auto_compress_module.py <examples/model_compress/auto_compress/torch/auto_compress_module.py>`。 | ||
|
||
发起 NNI Experiment | ||
--------------------- | ||
|
||
类似于从 python 启动,区别是不需要设置 ``trial_command`` 并把用户提供的 ``AutoCompressionModule`` 作为 ``AutoCompressionExperiment`` 的输入。 | ||
|
||
.. code-block:: python | ||
from pathlib import Path | ||
from nni.algorithms.compression.pytorch.auto_compress import AutoCompressionExperiment | ||
from auto_compress_module import AutoCompressionModule | ||
experiment = AutoCompressionExperiment(AutoCompressionModule, 'local') | ||
experiment.config.experiment_name = 'auto compression torch example' | ||
experiment.config.trial_concurrency = 1 | ||
experiment.config.max_trial_number = 10 | ||
experiment.config.search_space = search_space | ||
experiment.config.trial_code_directory = Path(__file__).parent | ||
experiment.config.tuner.name = 'TPE' | ||
experiment.config.tuner.class_args['optimize_mode'] = 'maximize' | ||
experiment.config.training_service.use_active_gpu = True | ||
experiment.run(8088) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.