LLaMA-Factory-310P3/examples/README_zh.md

228 lines
4.9 KiB
Markdown
Raw Normal View History

2024-04-15 22:14:34 +08:00
我们提供了多样化的大模型微调示例脚本。
2024-04-02 20:58:45 +08:00
2024-05-06 23:07:55 +08:00
请确保在 `LLaMA-Factory` 目录下执行下述命令。
## 目录
2024-06-13 03:15:06 +08:00
- [LoRA 微调](#lora-微调)
- [QLoRA 微调](#qlora-微调)
- [全参数微调](#全参数微调)
2024-05-06 23:07:55 +08:00
- [合并 LoRA 适配器与模型量化](#合并-lora-适配器与模型量化)
- [推理 LoRA 模型](#推理-lora-模型)
- [杂项](#杂项)
2024-06-13 03:26:10 +08:00
使用 `CUDA_VISIBLE_DEVICES`GPU`ASCEND_RT_VISIBLE_DEVICES`NPU选择计算设备。
2024-05-06 23:07:55 +08:00
## 示例
2024-06-13 03:15:06 +08:00
### LoRA 微调
2024-05-06 22:51:02 +08:00
#### (增量)预训练
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_lora_pretrain.yaml
2024-05-06 22:51:02 +08:00
```
#### 指令监督微调
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
2024-05-06 22:51:02 +08:00
```
2024-05-13 20:39:36 +08:00
#### 多模态指令监督微调
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llava1_5_lora_sft.yaml
2024-05-13 20:39:36 +08:00
```
2024-05-06 22:51:02 +08:00
#### 奖励模型训练
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_lora_reward.yaml
2024-05-06 22:51:02 +08:00
```
#### PPO 训练
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_lora_ppo.yaml
2024-05-06 22:51:02 +08:00
```
2024-05-26 23:46:33 +08:00
#### DPO/ORPO/SimPO 训练
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_lora_dpo.yaml
2024-05-06 22:51:02 +08:00
```
2024-05-18 03:44:56 +08:00
#### KTO 训练
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_lora_kto.yaml
2024-05-18 03:44:56 +08:00
```
2024-05-06 22:51:02 +08:00
#### 预处理数据集
对于大数据集有帮助,在配置中使用 `tokenized_path` 以加载预处理后的数据集。
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_preprocess.yaml
2024-05-06 22:51:02 +08:00
```
#### 在 MMLU/CMMLU/C-Eval 上评估
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli eval examples/train_lora/llama3_lora_eval.yaml
2024-05-06 22:51:02 +08:00
```
#### 批量预测并计算 BLEU 和 ROUGE 分数
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_lora/llama3_lora_predict.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-13 03:15:06 +08:00
#### 多机指令监督微调
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:15:06 +08:00
FORCE_TORCHRUN=1 NNODES=2 RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
FORCE_TORCHRUN=1 NNODES=2 RANK=1 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-13 03:15:06 +08:00
#### 使用 DeepSpeed ZeRO-3 平均分配显存
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:26:10 +08:00
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_lora/llama3_lora_sft_ds3.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-13 03:15:06 +08:00
### QLoRA 微调
2024-05-06 22:51:02 +08:00
2024-06-27 00:53:33 +08:00
#### 基于 4/8 比特 Bitsandbytes/HQQ/EETQ 量化进行指令监督微调(推荐)
2024-05-06 22:51:02 +08:00
```bash
2024-06-27 00:53:33 +08:00
llamafactory-cli train examples/train_qlora/llama3_lora_sft_otfq.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-13 03:15:06 +08:00
#### 基于 4/8 比特 GPTQ 量化进行指令监督微调
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_qlora/llama3_lora_sft_gptq.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-13 03:15:06 +08:00
#### 基于 4 比特 AWQ 量化进行指令监督微调
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_qlora/llama3_lora_sft_awq.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-13 03:15:06 +08:00
#### 基于 2 比特 AQLM 量化进行指令监督微调
2024-05-15 00:05:17 +08:00
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_qlora/llama3_lora_sft_aqlm.yaml
2024-05-15 00:05:17 +08:00
```
2024-06-13 03:15:06 +08:00
### 全参数微调
2024-05-06 22:51:02 +08:00
2024-06-03 19:12:29 +08:00
#### 在单机上进行指令监督微调
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:26:10 +08:00
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/llama3_full_sft_ds3.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-03 19:12:29 +08:00
#### 在多机上进行指令监督微调
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:26:10 +08:00
FORCE_TORCHRUN=1 NNODES=2 RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/llama3_full_sft_ds3.yaml
FORCE_TORCHRUN=1 NNODES=2 RANK=1 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/llama3_full_sft_ds3.yaml
2024-05-06 22:51:02 +08:00
```
#### 批量预测并计算 BLEU 和 ROUGE 分数
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/train_full/llama3_full_predict.yaml
2024-05-06 22:51:02 +08:00
```
### 合并 LoRA 适配器与模型量化
#### 合并 LoRA 适配器
2024-05-07 17:50:27 +08:00
注:请勿使用量化后的模型或 `quantization_bit` 参数来合并 LoRA 适配器。
2024-05-06 22:51:02 +08:00
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli export examples/merge_lora/llama3_lora_sft.yaml
2024-05-06 22:51:02 +08:00
```
#### 使用 AutoGPTQ 量化模型
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli export examples/merge_lora/llama3_gptq.yaml
2024-05-06 22:51:02 +08:00
```
### 推理 LoRA 模型
#### 使用命令行接口
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli chat examples/inference/llama3_lora_sft.yaml
2024-04-02 20:58:45 +08:00
```
2024-05-06 22:51:02 +08:00
#### 使用浏览器界面
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli webchat examples/inference/llama3_lora_sft.yaml
2024-05-06 22:51:02 +08:00
```
#### 启动 OpenAI 风格 API
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli api examples/inference/llama3_lora_sft.yaml
2024-05-06 22:51:02 +08:00
```
### 杂项
#### 使用 GaLore 进行全参数训练
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/extras/galore/llama3_full_sft.yaml
2024-05-06 22:51:02 +08:00
```
#### 使用 BAdam 进行全参数训练
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/extras/badam/llama3_full_sft.yaml
2024-05-06 22:51:02 +08:00
```
2024-08-09 20:02:03 +08:00
#### 使用 Adam-mini 进行全参数训练
```bash
2024-08-09 20:13:46 +08:00
llamafactory-cli train examples/extras/adam_mini/qwen2_full_sft.yaml
2024-08-09 20:02:03 +08:00
```
2024-05-06 22:51:02 +08:00
#### LoRA+ 微调
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/extras/loraplus/llama3_lora_sft.yaml
2024-05-06 22:51:02 +08:00
```
2024-06-17 17:47:25 +08:00
#### PiSSA 微调
```bash
llamafactory-cli train examples/extras/pissa/llama3_lora_sft.yaml
```
2024-05-06 22:51:02 +08:00
#### 深度混合微调
```bash
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/extras/mod/llama3_full_sft.yaml
2024-05-06 22:51:02 +08:00
```
#### LLaMA-Pro 微调
```bash
bash examples/extras/llama_pro/expand.sh
2024-06-13 03:15:06 +08:00
llamafactory-cli train examples/extras/llama_pro/llama3_freeze_sft.yaml
2024-05-06 22:51:02 +08:00
```
#### FSDP+QLoRA 微调
```bash
2024-06-17 17:47:25 +08:00
bash examples/extras/fsdp_qlora/train.sh
2024-06-16 01:08:12 +08:00
```