Skip to content

Commit ddb0137

Browse files
authored
add train sft examples (#2491)
Co-authored-by: llbdyiu66 <[email protected]>
1 parent 23764af commit ddb0137

File tree

5 files changed

+1017
-0
lines changed

5 files changed

+1017
-0
lines changed

examples/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## 精调
2+
3+
### 数据准备
4+
5+
我们支持的精调数据格式是每行包含一个字典的 json 文件,每个字典包含以下字段:
6+
7+
- `src` : `str, List(str)`, 模型的输入指令(instruction)、提示(prompt),模型应该执行的任务。
8+
- `tgt` : `str, List(str)`, 模型的输出。
9+
10+
样例数据:
11+
12+
```text
13+
{"src": "Give three tips for staying healthy.", "tgt": "1.Eat a balanced diet and make sure to include plenty of fruits and vegetables. \n2. Exercise regularly to keep your body active and strong. \n3. Get enough sleep and maintain a consistent sleep schedule."}
14+
...
15+
```
16+
17+
为了方便测试,我们也提供了[tatsu-lab/alpaca](https://huggingface.co/datasets/tatsu-lab/alpaca)demo 数据集可以直接使用:
18+
19+
```shell
20+
wget https://bj.bcebos.com/paddlenlp/datasets/examples/alpaca_demo.gz
21+
tar -xvf alpaca_demo.gz
22+
```
23+
24+
### 全参精调:SFT
25+
26+
单卡
27+
```bash
28+
# 需要12G显存左右
29+
python -u run_finetune.py ./config/qwen/sft_argument_qwen2_0p5b.json
30+
```
31+
32+
多卡
33+
```bash
34+
python -u -m paddle.distributed.launch --devices "0,1,2,3,4,5,6,7" run_finetune.py ./config/qwen/sft_argument_qwen2_0p5b.json
35+
```
36+
37+
### LoRA
38+
39+
LoRA 启动命令参考
40+
```bash
41+
# 需要9G左右显存
42+
python -u run_finetune.py ./config/qwen/lora_argument_qwen2_0p5b.json
43+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"model_name_or_path": "PaddleNLP/Qwen2-0.5B-Instruct",
3+
"dataset_name_or_path": "./data/sft",
4+
"output_dir": "./checkpoints/qwen2_paddle_lora_ckpts",
5+
"per_device_train_batch_size": 1,
6+
"gradient_accumulation_steps": 4,
7+
"per_device_eval_batch_size": 8,
8+
"eval_accumulation_steps":16,
9+
"num_train_epochs": 1,
10+
"learning_rate": 3e-05,
11+
"warmup_steps": 10,
12+
"logging_steps": 1,
13+
"evaluation_strategy": "epoch",
14+
"save_strategy": "epoch",
15+
"src_length": 1024,
16+
"max_length": 2048,
17+
"fp16": true,
18+
"fp16_opt_level": "O2",
19+
"do_train": true,
20+
"do_eval": true,
21+
"disable_tqdm": true,
22+
"load_best_model_at_end": true,
23+
"eval_with_do_generation": false,
24+
"metric_for_best_model": "accuracy",
25+
"recompute": true,
26+
"save_total_limit": 1,
27+
"tensor_parallel_degree": 1,
28+
"pipeline_parallel_degree": 1,
29+
"sharding": "stage2",
30+
"lora": true,
31+
"zero_padding": false,
32+
"unified_checkpoint": true,
33+
"use_flash_attention": false,
34+
"pissa": false,
35+
"use_mora": false
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"model_name_or_path": "PaddleNLP/Qwen2-0.5B-Instruct",
3+
"dataset_name_or_path": "./data/sft",
4+
"output_dir": "./checkpoints/qwen2_paddle_sft_ckpts",
5+
"per_device_train_batch_size": 1,
6+
"gradient_accumulation_steps": 4,
7+
"per_device_eval_batch_size": 8,
8+
"eval_accumulation_steps":16,
9+
"num_train_epochs": 1,
10+
"learning_rate": 3e-05,
11+
"warmup_steps": 10,
12+
"logging_steps": 1,
13+
"evaluation_strategy": "epoch",
14+
"save_strategy": "epoch",
15+
"src_length": 1024,
16+
"max_length": 2048,
17+
"fp16": true,
18+
"fp16_opt_level": "O2",
19+
"do_train": true,
20+
"do_eval": true,
21+
"disable_tqdm": true,
22+
"load_best_model_at_end": true,
23+
"eval_with_do_generation": false,
24+
"metric_for_best_model": "accuracy",
25+
"recompute": true,
26+
"save_total_limit": 1,
27+
"tensor_parallel_degree": 1,
28+
"pipeline_parallel_degree": 1,
29+
"sharding": "stage2",
30+
"zero_padding": false,
31+
"unified_checkpoint": true,
32+
"use_flash_attention": false
33+
}

0 commit comments

Comments
 (0)