19
19
20
20
## 🛠️ 支持模型列表 🛠️
21
21
22
- | Model | Pretrain | SFT | LoRA | Prefix Tuning | Quantization | Weight convert |
23
- | --- | --- | --- | --- | --- | --- | --- |
24
- | [ LLaMA/LLaMA2 ] ( ./llama ) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
25
- | [ Baichuan/Baichuan2 ] ( ./llama ) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
26
- | [ ChatGLM-6B ] ( ./chatglm ) | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ |
27
- | [ ChatGLM2/ChatGLM3 ] ( ./chatglm2 ) | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
28
- | [ Qwen ] ( ./qwen ) | ✅ | ✅ | ✅ | ✅ | 🚧 | ✅ |j
29
- | [ Bloom ] ( ./bloom ) | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
30
- | [ GPT-3 ] ( ./gpt-3 ) | ✅ | ✅ | 🚧 | 🚧 | 🚧 | ✅ |
31
- | [ OPT ] ( ./opt ) | 🚧 | ✅ | ✅ | 🚧 | 🚧 | ✅ |
32
- | [ GLM ] ( ./glm ) | ❌ | ✅ | ✅ | 🚧 | 🚧 | ✅ |
22
+ | Model | Pretrain | SFT | LoRA | Prefix Tuning | DPO | Quantization | Weight convert |
23
+ | --- | --- | --- | --- | --- | --- | --- | --- |
24
+ | [ LLaMA] ( ./llama ) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
25
+ | [ Qwen ] ( ./qwen ) | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | ✅ |
26
+ | [ Mixtral ] ( ./mixtral ) | ✅ | ✅ | ✅ | ❌ | 🚧 | 🚧 | 🚧 |
27
+ | [ Baichuan/Baichuan2 ] ( ./llama ) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
28
+ | [ ChatGLM-6B ] ( ./chatglm ) | ❌ | ✅ | ✅ | ✅ | 🚧 | ✅ | ❌ |
29
+ | [ ChatGLM2/ChatGLM3 ] ( ./chatglm2 ) | ❌ | ✅ | ✅ | ✅ | 🚧 | ✅ | ✅ |
30
+ | [ Bloom ] ( ./bloom ) | ❌ | ✅ | ✅ | ✅ | 🚧 | ✅ | ✅ |
31
+ | [ GPT-3 ] ( ./gpt-3 ) | ✅ | ✅ | 🚧 | 🚧 | 🚧 | 🚧 | ✅ |
32
+ | [ OPT ] ( ./opt ) | 🚧 | ✅ | ✅ | 🚧 | 🚧 | 🚧 | ✅ |
33
33
34
34
* ✅: Supported
35
35
* 🚧: In Progress
39
39
## 🚀 快速开始 🚀
40
40
41
41
### 1. 预训练
42
- PaddleNLP将飞桨4D并行策略加入到Trainer API中, 用户只需修改Trainer配置即可使用不同的分布式策略。目前工具链提供[ LLaMA/LLaMA2] ( ./llama ) 、[ GPT-3] ( ./gpt-3 ) 、[ Qwen] ( ./qwen ) 、[ Baichuan/Baichuan2] ( ./llama ) 等模型预训练功能,更多模型支持持续更新中。
42
+ PaddleNLP将飞桨4D并行策略加入到Trainer API中, 用户只需修改Trainer配置即可使用不同的分布式策略。目前工具链提供[ LLaMA/LLaMA2] ( ./llama ) 、[ GPT-3] ( ./gpt-3 ) 、[ Qwen] ( ./qwen ) 、[ Baichuan/Baichuan2] ( ./llama ) 、 [ Mixtral ] ( ./mixtral ) 等模型预训练功能,更多模型支持持续更新中。
43
43
44
44
<div align =" center " >
45
45
<img width="500" alt="llm" src="https://github.com/PaddlePaddle/PaddleNLP/assets/37530985/a2f0261d-7f76-4faf-ae01-cc9d37d5fcc0">
@@ -54,7 +54,7 @@ PaddleNLP将飞桨4D并行策略加入到Trainer API中, 用户只需修改Tra
54
54
我们在此处提供了更详细的[ 预训练数据制作] ( ) ,[ 分布式策略支持情况] ( https://paddlenlp.readthedocs.io/zh/latest/llm/pretraining/index.html#model-capability ) ,[ 性能测试报告文档] ( https://paddlenlp.readthedocs.io/zh/latest/llm/pretraining/index.html#model-performance ) ,参见: https://paddlenlp.readthedocs.io/zh/latest/llm/pretraining/index.html . 大模型权重列表参见[ 此处] ( https://paddlenlp.readthedocs.io/zh/latest/llm/pretraining/index.html#model-weight )
55
55
56
56
57
- 此项目支持了LLaMA、GPT-3、BaiChuan、Qwen 等大模型的预训练。用户切换配置config文件,即可一键运行。
57
+ 此项目支持了LLaMA、GPT-3、BaiChuan、Qwen、Mixtral 等大模型的预训练。用户切换配置config文件,即可一键运行。
58
58
59
59
数据详细制作流程可参考[ 此处] ( https://paddlenlp.readthedocs.io/zh/latest/llm/pretraining/dataset.html ) : https://paddlenlp.readthedocs.io/zh/latest/llm/pretraining/dataset.html
60
60
@@ -79,30 +79,26 @@ mv llama_openwebtext_100k.idx ./data
79
79
80
80
``` shell
81
81
# 编译自定义算子,可选
82
- cd ../model_zoo/gpt-3/external_ops/ && python3 setup.py install && cd -
82
+ cd ..legacy /model_zoo/gpt-3/external_ops/ && python3 setup.py install && cd -
83
83
84
- # llama 模型预训练
85
- python -u -m paddle.distributed.launch --gpus " 0,1,2,3,4,5,6,7" run_pretrain.py ./llama/pretrain-llama2_7b-tp2sd4_stage2.json
86
-
87
- # Qwen 模型预训练
88
- python -u -m paddle.distributed.launch --gpus " 0,1,2,3,4,5,6,7" run_pretrain.py ./qwen/pretrain_argument_stage2.json
84
+ # 模型预训练参考
85
+ python -u -m paddle.distributed.launch --gpus " 0,1,2,3,4,5,6,7" run_pretrain.py ./config/llama/pretrain_argument.json
89
86
```
90
87
91
88
注意:
92
89
1 . 建议使用paddle develop版本训练,需要安装` pip install tool_helpers visualdl==2.5.3 ` 等相关缺失whl包
93
90
2 . ` use_flash_attention ` 需要在A100机器开启,建议使用cuda11.8环境。
94
- 3 . ` use_fused_rms_norm ` 需要安装 [ 此目录 ] ( https://github.com/PaddlePaddle/PaddleNLP/tree/develop/model_zoo/gpt-3/external_ops ) 下的自定义OP, ` python setup.py install ` 。如果安装后仍然找不到算子,需要额外设置PYTHONPATH
91
+ 3 . ` use_fused_rms_norm ` 需要安装自定义算子 。如果安装后仍然找不到算子,需要额外设置PYTHONPATH
95
92
4 . ` continue_training ` 表示从现有的预训练模型加载训练。7b模型初始loss大概为2.xx, 随机初始化模型loss从11.x左右下降。
96
- 5 . 当前脚本为sharding版本,需要4D并行训练(数据、sharding、张量、流水线并行)的用户,请参考 ` run_trainer_tp4pp2.sh ` 脚本。
97
- 6 . 多机训练时,若各机器使用的训练数据文件位置相同(例如挂载共享硬盘情况),请指定` --share_folder true ` 使全局0号卡制作缓存数据。否则默认各台机器的0号卡独立制作缓存数据,
98
- 7 . 若数据集文件夹中存在默认缓存文件夹` index-cache/ ` ,则额外指定的` --data_cache ` 不生效,训练时优先加载默认缓存文件夹中的内容。
93
+ 5 . 多机训练时,若各机器使用的训练数据文件位置相同(例如挂载共享硬盘情况),请指定` --share_folder true ` 使全局0号卡制作缓存数据。否则默认各台机器的0号卡独立制作缓存数据,
94
+ 6 . 若数据集文件夹中存在默认缓存文件夹` index-cache/ ` ,则额外指定的` --data_cache ` 不生效,训练时优先加载默认缓存文件夹中的内容。
99
95
100
96
101
97
102
98
### 2. 精调
103
99
PaddleNLP支持多个主流大模型的SFT、LoRA、Prefix Tuning等精调策略,提供统一、高效精调方案:
104
100
- ** 统一训练入口** 。飞桨大模型套件精调方案可适配业界主流大模型,用户只需修改配置文件,即能在单卡或多卡(支持4D并行分布式策略)进行多种大模型精调。
105
- - ** 高效数据和分布式策略** 。Zero Padding零填充优化策略有效减少了pad token的占比,提高模型训练效率高达100% 。独创PEFT结合低比特和分布式并行策略,大幅降低大模型精调硬件门槛,支持单卡(A100 80G)百亿模型微调、单机(A100 80G * 8)千亿模型微调。
101
+ - ** 高效数据和分布式策略** 。Zero Padding零填充优化策略结合FlashMask策略有效提升模型训练效率 。独创PEFT结合低比特和分布式并行策略,大幅降低大模型精调硬件门槛,支持单卡(A100 80G)百亿模型微调、单机(A100 80G * 8)千亿模型微调。
106
102
- ** 支持多轮对话** 。支持统一对话模板,支持多轮对话高效训练,详参[ 多轮对话文档] ( ./docs/chat_template.md ) 。
107
103
108
104
@@ -137,26 +133,26 @@ tar -zxvf AdvertiseGen.tar.gz
137
133
138
134
** 全参精调:SFT**
139
135
``` bash
140
- # 四卡llama SFT启动命令参考
141
- python -u -m paddle.distributed.launch --gpus " 0,1,2,3" finetune_generation .py ./llama/sft_argument.json
136
+ # SFT启动命令参考
137
+ python -u -m paddle.distributed.launch --gpus " 0,1,2,3,4,5,6,7 " run_finetune .py ./config /llama/sft_argument.json
142
138
```
143
139
144
140
** LoRA**
145
141
``` bash
146
- # 单卡llama LoRA启动命令参考
147
- python finetune_generation .py ./llama/lora_argument.json
142
+ # LoRA启动命令参考
143
+ python run_finetune .py ./config /llama/lora_argument.json
148
144
```
149
145
150
146
** Prefix Tuning**
151
147
``` bash
152
- # 单卡llama Prefix Tuning启动命令参考
153
- python finetune_generation .py ./llama/pt_argument.json
148
+ # Prefix Tuning启动命令参考
149
+ python run_finetune .py ./config /llama/pt_argument.json
154
150
```
155
151
156
152
更多大模型精调分布式使用文档、训练细节和效果请参见[ 大模型精调教程] ( ./docs/finetune.md ) 。
157
153
158
154
### 3. 对齐
159
- 我们支持DPO等偏好对齐策略。
155
+ 我们支持DPO等偏好对齐策略。DPO策略采用zero_padding策略,结合FlashMask策略,有效提升模型训练效率。
160
156
161
157
** 数据准备** :
162
158
@@ -189,10 +185,10 @@ wget https://bj.bcebos.com/paddlenlp/datasets/examples/ultrafeedback_binarized.t
189
185
tar -zxvf ultrafeedback_binarized.tar.gz
190
186
```
191
187
192
- ** 全参精调:SFT **
188
+ ** 全参DPO **
193
189
``` bash
194
- # 四卡llama SFT启动命令参考
195
- python -u -m paddle.distributed.launch --gpus " 0,1,2,3,4,5,6,7" dpo_train. py ./llama/dpo_argument.json
190
+ # DPO启动命令参考
191
+ python -u -m paddle.distributed.launch --gpus " 0,1,2,3,4,5,6,7" ./dpo/run_dpo. py ./config /llama/dpo_argument.json
196
192
```
197
193
198
194
### 4. 量化
@@ -215,10 +211,10 @@ python -u -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" dpo_train.py ./
215
211
216
212
```
217
213
# PTQ 量化启动命令参考
218
- python finetune_generation .py ./llama/ptq_argument.json
214
+ python run_finetune .py ./config /llama/ptq_argument.json
219
215
220
216
# GPTQ 量化启动命令参考
221
- python finetune_generation .py ./llama/ptq_argument.json
217
+ python run_finetune .py ./config /llama/ptq_argument.json
222
218
```
223
219
224
220
更多技术细节和模型量化使用详见[ 量化文档] ( ./docs/quantization.md ) 。
@@ -231,13 +227,13 @@ PaddleNLP除了提供常用模型推理外,还提供了高性能推理,内
231
227
232
228
``` shell
233
229
# 动态图模型推理命令参考
234
- python predictor.py --model_name_or_path meta-llama/Llama-2-7b-chat --data_file ./data/dev.json --dtype float16
230
+ python ./predict/ predictor.py --model_name_or_path meta-llama/Llama-2-7b-chat --data_file ./data/dev.json --dtype float16
235
231
236
232
# 静态图模型推理命令参考
237
233
# step1 : 静态图导出
238
- python export_model.py --model_name_or_path meta-llama/Llama-2-7b-chat --output_path ./inference --dtype float16
234
+ python ./predict/ export_model.py --model_name_or_path meta-llama/Llama-2-7b-chat --output_path ./inference --dtype float16
239
235
# step2: 静态图推理
240
- python predictor.py --model_name_or_path ./inference --data_file ./data/dev.json --dtype float16 --mode static
236
+ python ./predict/ predictor.py --model_name_or_path ./inference --data_file ./data/dev.json --dtype float16 --mode static
241
237
```
242
238
243
239
- ** InferenceModel 高性能推理** :PaddleNLP 还提供了高性能推理模型加快并行推理的速度,同时支持FP16、Prefix Tuning、WINT8、A8W8多种推理方式。
@@ -253,13 +249,13 @@ python predictor.py --model_name_or_path ./inference --data_file ./data/dev.json
253
249
254
250
``` shell
255
251
# 高性能动态图模型推理命令参考
256
- python predictor.py --model_name_or_path meta-llama/Llama-2-7b-chat --inference_model --dtype float16
252
+ python ./predict/ predictor.py --model_name_or_path meta-llama/Llama-2-7b-chat --inference_model --dtype float16
257
253
258
254
# 高性能静态图模型推理命令参考
259
255
# step1 : 静态图导出
260
- python export_model.py --model_name_or_path meta-llama/Llama-2-7b-chat --inference_model --output_path ./inference --dtype float16
256
+ python ./predict/ export_model.py --model_name_or_path meta-llama/Llama-2-7b-chat --inference_model --output_path ./inference --dtype float16
261
257
# step2: 静态图推理
262
- python predictor.py --model_name_or_path ./inference --inference_model --dtype " float16" --mode " static"
258
+ python ./predict/ predictor.py --model_name_or_path ./inference --inference_model --dtype " float16" --mode " static"
263
259
```
264
260
265
261
更多常用模型推理和高性能模型使用方法详见[ 大模型推理文档] ( ./docs/inference.md ) 。
@@ -277,7 +273,7 @@ python predictor.py --model_name_or_path ./inference --inference_model --dtype "
277
273
我们提供了一套基于动态图推理的简单易用UI服务化部署脚本,用户可以快速部署服务化推理。
278
274
279
275
```
280
- python -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" flask_server.py \
276
+ python -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" ./predict/ flask_server.py \
281
277
--model_name_or_path meta-llama/Llama-2-7b-chat \
282
278
--port 8010 \
283
279
--flask_port 8011 \
@@ -287,7 +283,7 @@ python -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" flask_server.py \
287
283
- ` flask_port ` : Flask服务端口号,默认8010。
288
284
- 其他参数请参见[ 推理文档] ( ./docs/inference.md ) 中推理参数配置。
289
285
290
- 此外,如果想通过API脚本的方式跑推理,可参考:` ./request_flask_server.py ` 文件。
286
+ 此外,如果想通过API脚本的方式跑推理,可参考:` ./predict/ request_flask_server.py ` 文件。
291
287
292
288
</div ></details >
293
289
0 commit comments