Skip to content

Commit 55eec46

Browse files
authored
llm add chat (#24)
1 parent 331473b commit 55eec46

File tree

25 files changed

+436
-167
lines changed

25 files changed

+436
-167
lines changed

examples/pytorch/llm/README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
## Features
1818
1. supported sft method: [lora](https://arxiv.org/abs/2106.09685), [qlora](https://arxiv.org/abs/2305.14314), full(full parameter fine tuning), ...
19-
2. supported models: [**qwen-7b**](https://github.com/QwenLM/Qwen-7B), baichuan-7b, baichuan-13b, chatglm2-6b, chatglm2-6b-32k, llama2-7b, llama2-13b, llama2-70b, openbuddy-llama2-13b, openbuddy-llama-65b, polylm-13b, ...
19+
2. supported models: [**qwen-7b**](https://github.com/QwenLM/Qwen-7B), qwen-7b-chat, baichuan-7b, baichuan-13b, baichuan-13b-chat, chatglm2-6b, chatglm2-6b-32k, llama2-7b, llama2-7b-chat, llama2-13b, llama2-13b-chat, llama2-70b, llama2-70b-chat, openbuddy-llama2-13b, openbuddy-llama-65b, polylm-13b, ...
2020
3. supported feature: quantization, ddp, model parallelism(device map), gradient checkpoint, gradient accumulation steps, push to modelscope hub, custom datasets, ...
2121
4. supported datasets: alpaca-en(gpt4), alpaca-zh(gpt4), finance-en, multi-alpaca-all, code-en, instinwild-en, instinwild-zh, ...
22+
5. supported templates: chatml(qwen), baichuan, chatglm2, llama, openbuddy_llama, default, ...
2223

2324
## Prepare the Environment
2425
Experimental environment: A10, 3090, A100, ... (V100 does not support bf16, quantization)
@@ -58,20 +59,25 @@ cd swift/examples/pytorch/llm
5859
# sft(qlora) and infer qwen-7b, Requires 16GB VRAM.
5960
# If you want to use quantification, you need to `pip install bitsandbytes`
6061
# If you want to push weights into modelscope hub during training, you need to set '--push_to_hub true'
61-
bash scripts/qwen_7b/qlora/sft.sh
62-
bash scripts/qwen_7b/qlora/infer.sh
62+
bash scripts/qwen_7b_chat/qlora/sft.sh
63+
bash scripts/qwen_7b_chat/qlora/infer.sh
6364

6465
# sft(qlora+ddp) and infer qwen-7b, Requires 4*16GB VRAM.
65-
bash scripts/qwen_7b/qlora_ddp/sft.sh
66-
bash scripts/qwen_7b/qlora_ddp/infer.sh
66+
bash scripts/qwen_7b_chat/qlora_ddp/sft.sh
67+
bash scripts/qwen_7b_chat/qlora_ddp/infer.sh
68+
69+
# sft(lora+ddp) and infer qwen-7b, Requires 4*22GB VRAM.
70+
bash scripts/qwen_7b_chat/lora_ddp/sft.sh
71+
bash scripts/qwen_7b_chat/lora_ddp/infer.sh
6772

6873
# sft(full) and infer qwen-7b, Requires 95GB VRAM.
69-
bash scripts/qwen_7b/full/sft.sh
70-
bash scripts/qwen_7b/full/infer.sh
74+
bash scripts/qwen_7b_chat/full/sft.sh
75+
bash scripts/qwen_7b_chat/full/infer.sh
7176

7277
# For more scripts, please see `scripts/` folder
7378
```
7479

7580
## Extend Datasets
76-
1. If you need to extend the model, you can modify the `MODEL_MAPPING` in `utils/models.py`. `model_id` can be specified as a local path. In this case, `revision` doesn't work.
77-
2. If you need to extend or customize the dataset, you can modify the `DATASET_MAPPING` in `utils/datasets.py`. You need to customize the `get_*_dataset` function, which returns a dataset with two columns: `instruction`, `output`.
81+
1. If you need to extend the model, you can modify the `MODEL_MAPPING` in `utils/model.py`. `model_id` can be specified as a local path. In this case, `revision` doesn't work.
82+
2. If you need to extend or customize the dataset, you can modify the `DATASET_MAPPING` in `utils/dataset.py`. You need to customize the `get_*_dataset` function, which returns a dataset with two columns: `query`, `response`.
83+
3. If you need to extend the template, you can modify the `TEMPLATE_MAPPING` in `utils/preprocess.py`.

examples/pytorch/llm/README_CN.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
## 特性
1919
1. [lora](https://arxiv.org/abs/2106.09685), [qlora](https://arxiv.org/abs/2305.14314), 全参数微调, ...
20-
2. 支持的模型: [**qwen-7b**](https://github.com/QwenLM/Qwen-7B), baichuan-7b, baichuan-13b, chatglm2-6b, chatglm2-6b-32k, llama2-7b, llama2-13b, llama2-70b, openbuddy-llama2-13b, openbuddy-llama-65b, polylm-13b, ...
20+
2. 支持的模型: [**qwen-7b**](https://github.com/QwenLM/Qwen-7B), qwen-7b-chat, baichuan-7b, baichuan-13b, baichuan-13b-chat, chatglm2-6b, chatglm2-6b-32k, llama2-7b, llama2-7b-chat, llama2-13b, llama2-13b-chat, llama2-70b, llama2-70b-chat, openbuddy-llama2-13b, openbuddy-llama-65b, polylm-13b, ...
2121
3. 支持的特性: 模型量化, DDP, 模型并行(device_map), gradient checkpoint, 梯度累加, 支持推送modelscope hub, 支持自定义数据集, ...
2222
4. 支持的数据集: alpaca-en(gpt4), alpaca-zh(gpt4), finance-en, multi-alpaca-all, code-en, instinwild-en, instinwild-zh, ...
23-
23+
5. 支持的template: chatml(qwen), baichuan, chatglm2, llama, openbuddy_llama, default, ...
2424

2525
## 准备实验环境
2626
实验环境: A10, 3090, A100均可. (V100不支持bf16, 量化)
@@ -61,20 +61,25 @@ cd swift/examples/pytorch/llm
6161
# 微调(qlora)+推理 qwen-7b, 需要16GB显存.
6262
# 如果你想要使用量化, 你需要`pip install bitsandbytes`
6363
# 如果你想在训练时, 将权重push到modelscope hub中, 你需要设置`--push_to_hub true`
64-
bash scripts/qwen_7b/qlora/sft.sh
65-
bash scripts/qwen_7b/qlora/infer.sh
64+
bash scripts/qwen_7b_chat/qlora/sft.sh
65+
bash scripts/qwen_7b_chat/qlora/infer.sh
6666

6767
# 微调(qlora+ddp)+推理 qwen-7b, 需要4卡*16GB显存.
68-
bash scripts/qwen_7b/qlora_ddp/sft.sh
69-
bash scripts/qwen_7b/qlora_ddp/infer.sh
68+
bash scripts/qwen_7b_chat/qlora_ddp/sft.sh
69+
bash scripts/qwen_7b_chat/qlora_ddp/infer.sh
70+
71+
# 微调(lora+ddp)+推理 qwen-7b, 需要4卡*22GB显存.
72+
bash scripts/qwen_7b_chat/lora_ddp/sft.sh
73+
bash scripts/qwen_7b_chat/lora_ddp/infer.sh
7074

7175
# 微调(full)+推理 qwen-7b, 需要95G显存.
72-
bash scripts/qwen_7b/full/sft.sh
73-
bash scripts/qwen_7b/full/infer.sh
76+
bash scripts/qwen_7b_chat/full/sft.sh
77+
bash scripts/qwen_7b_chat/full/infer.sh
7478

7579
# 更多的scripts脚本, 可以看`scripts`文件夹
7680
```
7781

7882
## 拓展数据集
79-
1. 如果你想要拓展模型, 你可以修改`utils/models.py`文件中的`MODEL_MAPPING`. `model_id`可以指定为本地路径, 这种情况下, `revision`参数不起作用.
80-
2. 如果你想要拓展或使用自定义数据集, 你可以修改`utils/datasets.py`文件中的`DATASET_MAPPING`. 你需要自定义`get_*_dataset`函数, 并返回包含`instruction`, `output`两列的数据集.
83+
1. 如果你想要拓展模型, 你可以修改`utils/model.py`文件中的`MODEL_MAPPING`. `model_id`可以指定为本地路径, 这种情况下, `revision`参数不起作用.
84+
2. 如果你想要拓展或使用自定义数据集, 你可以修改`utils/dataset.py`文件中的`DATASET_MAPPING`. 你需要自定义`get_*_dataset`函数, 并返回包含`query`, `response`两列的数据集.
85+
3. 如果你想要拓展template, 你可以修改`utils/preprocess.py`文件中的`TEMPLATE_MAPPING`.

examples/pytorch/llm/scripts/baichuan_13b/qlora_ddp/infer.sh renamed to examples/pytorch/llm/scripts/baichuan_13b_chat/qlora_ddp/infer.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 12G
22
CUDA_VISIBLE_DEVICES=0 \
33
python src/llm_infer.py \
4-
--model_type baichuan-13b \
4+
--model_type baichuan-13b-chat \
55
--sft_type lora \
6-
--ckpt_dir "runs/baichuan-13b/vx_xxx/checkpoint-xxx" \
6+
--ckpt_dir "runs/baichuan-13b-chat/vx_xxx/checkpoint-xxx" \
77
--eval_human true \
88
--quantization_bit 4 \
99
--max_new_tokens 1024 \

examples/pytorch/llm/scripts/baichuan_13b/qlora_ddp/sft.sh renamed to examples/pytorch/llm/scripts/baichuan_13b_chat/qlora_ddp/sft.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ torchrun \
55
--nproc_per_node=$nproc_per_node \
66
--master_port 29500 \
77
src/llm_sft.py \
8-
--model_type baichuan-13b \
8+
--model_type baichuan-13b-chat \
99
--sft_type lora \
1010
--output_dir runs \
1111
--ddp_backend nccl \

examples/pytorch/llm/scripts/llama2_70b/qlora/infer.sh renamed to examples/pytorch/llm/scripts/llama2_70b_chat/qlora/infer.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 40G
22
CUDA_VISIBLE_DEVICES=0,1 \
33
python src/llm_infer.py \
4-
--model_type llama2-7b \
4+
--model_type llama2-7b-chat \
55
--sft_type lora \
6-
--ckpt_dir "runs/llama2-70b/vx_xxx/checkpoint-xxx" \
6+
--ckpt_dir "runs/llama2-70b-chat/vx_xxx/checkpoint-xxx" \
77
--eval_human true \
88
--quantization_bit 4 \
99
--max_new_tokens 1024 \

examples/pytorch/llm/scripts/llama2_70b/qlora/sft.sh renamed to examples/pytorch/llm/scripts/llama2_70b_chat/qlora/sft.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# llama2 is not good at Chinese
33
CUDA_VISIBLE_DEVICES=0,1 \
44
python src/llm_sft.py \
5-
--model_type llama2-70b \
5+
--model_type llama2-70b-chat \
66
--sft_type lora \
77
--output_dir runs \
8-
--dataset alpaca-en,alpaca-zh \
8+
--dataset alpaca-en \
99
--dataset_sample 20000 \
1010
--num_train_epochs 1 \
1111
--max_length 1024 \

examples/pytorch/llm/scripts/qwen_7b/qlora_ddp/infer.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ CUDA_VISIBLE_DEVICES=0 \
33
python src/llm_infer.py \
44
--model_type qwen-7b \
55
--sft_type lora \
6+
--template_type chatml \
67
--dtype bf16 \
78
--ckpt_dir "runs/qwen-7b/vx_xxx/checkpoint-xxx" \
89
--eval_human true \
910
--quantization_bit 4 \
11+
--bnb_4bit_comp_dtype bf16 \
1012
--max_new_tokens 1024 \
1113
--temperature 0.9 \
1214
--top_k 50 \

examples/pytorch/llm/scripts/qwen_7b/qlora_ddp/sft.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ torchrun \
77
src/llm_sft.py \
88
--model_type qwen-7b \
99
--sft_type lora \
10+
--template_type chatml \
1011
--dtype bf16 \
1112
--output_dir runs \
1213
--ddp_backend nccl \
@@ -15,6 +16,7 @@ torchrun \
1516
--num_train_epochs 1 \
1617
--max_length 1024 \
1718
--quantization_bit 4 \
19+
--bnb_4bit_comp_dtype bf16 \
1820
--lora_rank 64 \
1921
--lora_alpha 32 \
2022
--lora_dropout_p 0.05 \

examples/pytorch/llm/scripts/qwen_7b/full/infer.sh renamed to examples/pytorch/llm/scripts/qwen_7b_chat/full/infer.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# 19G
22
CUDA_VISIBLE_DEVICES=0 \
33
python src/llm_infer.py \
4-
--model_type qwen-7b \
4+
--model_type qwen-7b-chat \
55
--sft_type full \
6+
--template_type chatml \
67
--dtype bf16 \
7-
--ckpt_dir "runs/qwen-7b/vx_xxx/checkpoint-xxx" \
8+
--ckpt_dir "runs/qwen-7b-chat/vx_xxx/checkpoint-xxx" \
89
--eval_human true \
910
--max_new_tokens 1024 \
1011
--temperature 0.9 \

examples/pytorch/llm/scripts/qwen_7b/full/sft.sh renamed to examples/pytorch/llm/scripts/qwen_7b_chat/full/sft.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# Experimental environment: 8 * 3090
33
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5 \
44
python src/llm_sft.py \
5-
--model_type qwen-7b \
5+
--model_type qwen-7b-chat \
66
--sft_type full \
7+
--template_type chatml \
78
--dtype bf16 \
89
--output_dir runs \
910
--dataset alpaca-en,alpaca-zh \
@@ -22,6 +23,6 @@ python src/llm_sft.py \
2223
--logging_steps 10 \
2324
--use_flash_attn false \
2425
--push_to_hub false \
25-
--hub_model_id qwen-7b-full \
26+
--hub_model_id qwen-7b-chat-full \
2627
--hub_private_repo true \
2728
--hub_token 'your-sdk-token' \

0 commit comments

Comments
 (0)