Skip to content

Commit d66c832

Browse files
authored
Move faster_generation to top level. (#2150)
* Move faster_generation to top level. * Update links in README of faster_generation. * Update README of faster_generation and PLATO-XL. * Update plato_xl_sample.py * Move plato-xl to model_zoo.
1 parent f21829c commit d66c832

File tree

15 files changed

+212
-22
lines changed

15 files changed

+212
-22
lines changed

examples/dialogue/plato-xl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../model_zoo/plato-xl

examples/faster/faster_generation/README.md renamed to faster_generation/README.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FasterGeneration是PaddleNLP v2.2版本加入的文本生成高性能加速功
66

77

88
<p align="center">
9-
<img src="../../../docs/imgs/faster_generation.png" width="400" height ="600" />
9+
<img src="../docs/imgs/faster_generation.png" width="400" height ="600" />
1010
</p>
1111

1212
## Featrues
@@ -15,7 +15,7 @@ FasterGeneration是PaddleNLP v2.2版本加入的文本生成高性能加速功
1515
- 支持大多数主流解码策略。包括Beam Search、Sampling、Greedy Search。以及Diverse Sibling Search、Length Penalty等子策略。
1616
- 解码速度快。最高可达非加速版generate函数的**18倍****并支持FP16混合精度计算**
1717
- 易用性强。功能的入口为`model.generate`,与非加速版生成api的使用方法相同,当满足加速条件时使用jit即时编译高性能算子并用于生成,不满足则自动切换回非加速版生成api。
18-
- GPT模型支持高性能并行推理,在具备MPI和NCCL的环境中一行代码即可开启使用。
18+
- GPT、UnifiedTransformer和UNIMO-text模型支持高性能并行推理,在具备MPI和NCCL的环境中一行代码即可开启使用,允许通过多张小显存容量的 GPU 使用百亿大模型,预测速度较单卡也进一步提升。百亿模型四卡并行高性能推理速度达单卡高性能推理速度2+倍
1919

2020
### Inference Model Support
2121
下表为PaddleNLP FasterGeneration对预训练模型和解码策略的支持情况(GPU)。
@@ -47,19 +47,21 @@ FasterGeneration的高性能解码相比原版generate方法加速明显,并
4747
**BART** (bart-base, batch_size=4, max_length=32)
4848

4949
<p align="left">
50-
<img src="../../../docs/imgs/bart_perf.png" width="800" height ="400" />
50+
<img src="../docs/imgs/bart_perf.png" width="800" height ="400" />
5151
</p>
5252

5353
**GPT** (gpt2, batch_size=4, max_length=32)
5454

5555
<p align="left">
56-
<img src="../../../docs/imgs/gpt_perf.png" width="800" height ="400" />
56+
<img src="../docs/imgs/gpt_perf.png" width="800" height ="400" />
5757
</p>
5858

5959
更详细的性能数据请参见[这里](https://github.com/PaddlePaddle/PaddleNLP/tree/develop/examples/faster/faster_generation/perf)
6060

6161
## Quick Start
6262

63+
### 高性能推理
64+
6365
为体现FasterGeneration的易用性,我们在`samples`文件夹中内置了几个典型任务示例,下面以基于GPT模型的中文文本续写任务为例:
6466

6567
```sh
@@ -127,23 +129,14 @@ outputs, _ = model.generate(
127129

128130
关于该函数的详细介绍可以参考API文档[generate](https://paddlenlp.readthedocs.io/zh/latest/source/paddlenlp.transformers.generation_utils.html)**Aistudio教程[文本生成任务实战:如何使用PaddleNLP实现各种解码策略](https://aistudio.baidu.com/aistudio/projectdetail/3243711?contributionType=1)**`samples`文件夹中的其他示例的使用方法相同。
129131

130-
### **GPT 并行推理**
132+
### 并行推理
131133

132-
对于GPT模型下的文本生成,FasterGeneration除高性能加速外还集成了[NV FasterTransformer](https://github.com/NVIDIA/FasterTransformer)的模型并行推理能力,支持Tensor Parallel和Layer Parallel(Pipeline Parallel)两种并行策略的组合。关于这两种并行策略的详细介绍请参考[Megatron论文](https://arxiv.org/pdf/2104.04473.pdf)
134+
FasterGeneration对GPT、UnifiedTransformer和UNIMO-text模型在高性能推理的基础上还实现了模型并行功能,其中GPT支持Tensor Parallel和Layer Parallel(Pipeline Parallel)两种并行策略的组合,UnifiedTransformer和UNIMO-text支持Tensor Parallel。关于这两种并行策略的详细介绍请参考[Megatron论文](https://arxiv.org/pdf/2104.04473.pdf)
133135

134-
并行推理当前依赖MPI和NCCL,如需使用GPT高性能并行推理功能,还请先安装依赖。在使用时,相比上面的高性能加速,只需在`from_pretrained`创建加载模型之前加上一行代码,如下所示:
136+
并行推理当前依赖MPI([MPICH](https://www.mpich.org)[OpenMPI](https://www.open-mpi.org)均可)和[NCCL](https://developer.nvidia.com/nccl),如需使用还请先安装依赖。在使用时,相比上面的单卡高性能加速代码中也只增加了`from_pretrained`创建加载模型之前加上`enable_ft_para()`一行。
137+
#### GPT 并行推理
135138

136-
```
137-
enable_ft_para(tensor_para_size=2, layer_para_size=2)
138-
...
139-
model = GPTLMHeadModel.from_pretrained(model_name)
140-
...
141-
outputs, _ = model.generate(
142-
input_ids=inputs_ids, max_length=10, decode_strategy='greedy_search',
143-
use_faster=True)
144-
```
145-
146-
完整的使用示例已在`gpt_mp_sample.py`中提供,按照如下方式启动即可:
139+
GPT高性能并行推理的完整使用示例已在`gpt_mp_sample.py`中提供,按照如下方式启动即可:
147140

148141
```sh
149142
mpirun -n 4 python gpt_mp_sample.py --tensor_para_size 4 --layer_para_size 1
@@ -156,7 +149,17 @@ mpirun -n 4 python gpt_mp_sample.py --tensor_para_size 4 --layer_para_size 1
156149
- `topp` 用于Top-P采样策略,采样时将只从概率最高且累加概率不超过该值的token中采样,默认为1.0。
157150
- `temperature` 用于调整预测概率分布,默认为1.0,即保持模型原有的预测概率。
158151

159-
使用`gpt-cpm-larg-cn`和默认设置,在V100上4卡Tensor Parallel较单卡高性能预测速度提升约40%。
152+
使用`gpt-cpm-larg-cn`(2.6B)和默认设置,在V100上4卡Tensor Parallel较单卡高性能预测速度提升约40%。
153+
154+
#### PLATO-XL 并行推理
155+
156+
PLATO-XL百亿对话预训练模型(11B UnifiedTransformer模型)高性能并行推理的完整使用示例已在`plato_xl_sample.py`中提供(当前只支持Tensor Parallel),按照如下方式启动即可:
157+
158+
```shell
159+
mpirun -n 4 python plato_xl_sample.py
160+
```
161+
162+
参数释义基本同上。在V100上4卡Tensor Parallel高性能预测为单卡高性能预测速度的2倍。
160163

161164
## Generate Examples
162165

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)