Skip to content

Fix some dead link #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/zh_cn/tutorials/nas/ernie_slim_ofa_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
5. 通过以上的方式来优化整个超网络参数,训练完成后选择满足加速要求和精度要求的子模型。

<p align="center">
<img src="../../images/algo/ofa_bert.jpg" width="950"/><br />
<img src="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/images/algo/ofa_bert.jpg" width="950"/><br />
整体流程图
</p>

## 基于ERNIE repo代码进行压缩
本教程基于PaddleSlim2.0及之后版本、Paddle1.8.5和ERNIE 0.0.4dev及之后版本,请确认已正确安装Paddle、PaddleSlim和ERNIE。
基于ERNIE repo中TinyERNIE的整体代码示例请参考:[TinyERNIE](../../../demo/ofa/ernie/README.md)
基于ERNIE repo中TinyERNIE的整体代码示例请参考:[TinyERNIE](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/demo/ofa/ernie/README.md)

### 1. 定义初始网络
定义原始TinyERNIE模型并定义一个字典保存原始模型参数。普通模型转换为超网络之后,由于其组网OP的改变导致原始模型加载的参数失效,所以需要定义一个字典保存原始模型的参数并用来初始化超网络。设置'return_additional_info'参数为True,返回中间层结果,便于添加蒸馏。
Expand Down Expand Up @@ -65,7 +65,7 @@ ofa_model = paddleslim.nas.ofa.OFA(model, distill_config=distill_config)
```

### 6. 计算神经元和head的重要性并根据其重要性重排序参数
基于Paddle 1.8.5实现的重要性计算代码位于:[importance.py](../../../demo/ofa/ernie/ernie_supernet/importance.py)
基于Paddle 1.8.5实现的重要性计算代码位于:[importance.py](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/demo/ofa/ernie/ernie_supernet/importance.py)
```python
head_importance, neuron_importance = compute_neuron_head_importance(
args,
Expand Down Expand Up @@ -126,6 +126,6 @@ ofa_model.model.clear_gradients()
---
**NOTE**

由于在计算head的重要性时会利用一个mask来收集梯度,所以需要通过monkey patch的方式重新实现一下TinyERNIE中一些相关类的forward函数。具体实现的forward可以参考:[model_ernie_supernet.py](../../../demo/ofa/ernie/ernie_supernet/modeling_ernie_supernet.py)
由于在计算head的重要性时会利用一个mask来收集梯度,所以需要通过monkey patch的方式重新实现一下TinyERNIE中一些相关类的forward函数。具体实现的forward可以参考:[model_ernie_supernet.py](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/demo/ofa/ernie/ernie_supernet/modeling_ernie_supernet.py)

---
6 changes: 3 additions & 3 deletions docs/zh_cn/tutorials/nas/nas_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ PaddleSlim提供了4种网络结构搜索的方法:基于模拟退火进行网
| 算法名称 | 算法简介 | 代表模型 |
|:---------:|:------------:|:--------:|
| [Once-For-All](nas_ofa.md) | OFA是一种基于One-Shot NAS的压缩方案。这种方式比较高效,其优势是只需要训练一个超网络就可以从中选择满足不同延时要求的子模型。 | Once-For-All |
| [SANAS](../../quick_start/static/nas_tutorial.md) | SANAS是基于模拟退火的方式进行网络结构搜索,在机器资源不多的情况下,选择这种方式一般能得到比强化学习更好的模型。 | \ |
| [RLNAS](./../api_cn/nas_api.rst) | RLNAS是基于强化学习的方式进行网络结构搜索,这种方式需要耗费大量机器资源。 | ENAS、NasNet、MNasNet |
| [DARTS/PCDARTS](../../api_cn/darts.rst) | DARTS是基于梯度进行网络结构搜索,这种方式比较高效,大大减少了搜索时间和所需要的机器资源。 |DARTS、PCDARTS、ProxylessNAS|
| [SANAS](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/quick_start/static/nas_tutorial.md) | SANAS是基于模拟退火的方式进行网络结构搜索,在机器资源不多的情况下,选择这种方式一般能得到比强化学习更好的模型。 | \ |
| [RLNAS](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/api_cn/static/nas/nas_api.rst) | RLNAS是基于强化学习的方式进行网络结构搜索,这种方式需要耗费大量机器资源。 | ENAS、NasNet、MNasNet |
| [DARTS/PCDARTS](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/zh_cn/api_cn/dygraph/nas/darts.rst) | DARTS是基于梯度进行网络结构搜索,这种方式比较高效,大大减少了搜索时间和所需要的机器资源。 |DARTS、PCDARTS、ProxylessNAS|


# 参考文献
Expand Down
4 changes: 2 additions & 2 deletions docs/zh_cn/tutorials/nas/paddlenlp_slim_ofa_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
5. 通过以上的方式来优化整个超网络参数,训练完成后选择满足加速要求和精度要求的子模型。

<p align="center">
<img src="../../images/algo/ofa_bert.jpg" width="950"/><br />
<img src="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/images/algo/ofa_bert.jpg" width="950"/><br />
整体流程图
</p>

## 基于PaddleNLP repo代码进行压缩
本教程基于PaddleSlim2.0及之后版本、Paddle2.0rc1及之后版本和PaddleNLP2.0beta及之后版本,请确认已正确安装Paddle、PaddleSlim和PaddleNLP。
基于PaddleNLP repo中BERT-base的整体代码示例请参考:[BERT-base](../../../demo/ofa/bert/README.md)
基于PaddleNLP repo中BERT-base的整体代码示例请参考:[BERT-base](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/demo/ofa/bert/README.md)

### 1. 定义初始网络
定义原始BERT-base模型并定义一个字典保存原始模型参数。普通模型转换为超网络之后,由于其组网OP的改变导致原始模型加载的参数失效,所以需要定义一个字典保存原始模型的参数并用来初始化超网络。
Expand Down