2024-04-02 20:37:37 +08:00
|
|
|
We provide diverse examples about fine-tuning LLMs.
|
|
|
|
|
2024-05-06 23:07:55 +08:00
|
|
|
Make sure to execute these commands in the `LLaMA-Factory` directory.
|
|
|
|
|
|
|
|
## Table of Contents
|
|
|
|
|
2024-06-13 03:15:06 +08:00
|
|
|
- [LoRA Fine-Tuning](#lora-fine-tuning)
|
|
|
|
- [QLoRA Fine-Tuning](#qlora-fine-tuning)
|
|
|
|
- [Full-Parameter Fine-Tuning](#full-parameter-fine-tuning)
|
2024-05-06 23:07:55 +08:00
|
|
|
- [Merging LoRA Adapters and Quantization](#merging-lora-adapters-and-quantization)
|
|
|
|
- [Inferring LoRA Fine-Tuned Models](#inferring-lora-fine-tuned-models)
|
|
|
|
- [Extras](#extras)
|
|
|
|
|
2024-06-13 03:26:10 +08:00
|
|
|
Use `CUDA_VISIBLE_DEVICES` (GPU) or `ASCEND_RT_VISIBLE_DEVICES` (NPU) to choose computing devices.
|
|
|
|
|
2024-05-06 23:07:55 +08:00
|
|
|
## Examples
|
|
|
|
|
2024-06-13 03:15:06 +08:00
|
|
|
### LoRA Fine-Tuning
|
2024-05-06 22:51:02 +08:00
|
|
|
|
|
|
|
#### (Continuous) Pre-Training
|
|
|
|
|
|
|
|
```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
|
|
|
```
|
|
|
|
|
|
|
|
#### Supervised Fine-Tuning
|
|
|
|
|
|
|
|
```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
|
|
|
#### Multimodal Supervised Fine-Tuning
|
|
|
|
|
|
|
|
```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
|
|
|
#### Reward Modeling
|
|
|
|
|
|
|
|
```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 Training
|
|
|
|
|
|
|
|
```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 Training
|
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 Training
|
|
|
|
|
|
|
|
```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
|
|
|
#### Preprocess Dataset
|
|
|
|
|
|
|
|
It is useful for large dataset, use `tokenized_path` in config to load the preprocessed dataset.
|
|
|
|
|
|
|
|
```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
|
|
|
```
|
|
|
|
|
|
|
|
#### Evaluating on MMLU/CMMLU/C-Eval Benchmarks
|
|
|
|
|
|
|
|
```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
|
|
|
```
|
|
|
|
|
|
|
|
#### Batch Predicting and Computing BLEU and ROUGE Scores
|
|
|
|
|
|
|
|
```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
|
|
|
#### Supervised Fine-Tuning on Multiple Nodes
|
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
|
|
|
#### Supervised Fine-Tuning with DeepSpeed ZeRO-3 (Weight Sharding)
|
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 Fine-Tuning
|
2024-05-06 22:51:02 +08:00
|
|
|
|
2024-06-27 00:53:33 +08:00
|
|
|
#### Supervised Fine-Tuning with 4/8-bit Bitsandbytes/HQQ/EETQ Quantization (Recommended)
|
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
|
|
|
#### Supervised Fine-Tuning with 4/8-bit GPTQ Quantization
|
2024-05-06 22:51:02 +08:00
|
|
|
|
|
|
|
```bash
|
2024-06-13 16:02:21 +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
|
|
|
#### Supervised Fine-Tuning with 4-bit AWQ Quantization
|
2024-05-06 22:51:02 +08:00
|
|
|
|
|
|
|
```bash
|
2024-06-13 16:02:21 +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
|
|
|
#### Supervised Fine-Tuning with 2-bit AQLM Quantization
|
2024-05-15 00:05:17 +08:00
|
|
|
|
|
|
|
```bash
|
2024-06-13 16:02:21 +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
|
|
|
### Full-Parameter Fine-Tuning
|
2024-05-06 22:51:02 +08:00
|
|
|
|
2024-06-03 19:12:29 +08:00
|
|
|
#### Supervised Fine-Tuning on Single Node
|
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
|
|
|
#### Supervised Fine-Tuning on Multiple Nodes
|
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
|
|
|
```
|
|
|
|
|
|
|
|
#### Batch Predicting and Computing BLEU and ROUGE Scores
|
|
|
|
|
|
|
|
```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
|
|
|
```
|
|
|
|
|
|
|
|
### Merging LoRA Adapters and Quantization
|
|
|
|
|
|
|
|
#### Merge LoRA Adapters
|
|
|
|
|
2024-05-07 17:50:27 +08:00
|
|
|
Note: DO NOT use quantized model or `quantization_bit` when merging LoRA adapters.
|
|
|
|
|
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
|
|
|
```
|
|
|
|
|
|
|
|
#### Quantizing Model using 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
|
|
|
```
|
|
|
|
|
|
|
|
### Inferring LoRA Fine-Tuned Models
|
|
|
|
|
|
|
|
#### Use CLI
|
|
|
|
|
|
|
|
```bash
|
2024-06-13 03:15:06 +08:00
|
|
|
llamafactory-cli chat examples/inference/llama3_lora_sft.yaml
|
2024-05-06 22:51:02 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Use Web UI
|
|
|
|
|
|
|
|
```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
|
|
|
```
|
|
|
|
|
|
|
|
#### Launch OpenAI-style 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
|
|
|
```
|
|
|
|
|
|
|
|
### Extras
|
|
|
|
|
|
|
|
#### Full-Parameter Fine-Tuning using 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
|
|
|
```
|
|
|
|
|
|
|
|
#### Full-Parameter Fine-Tuning using 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
|
|
|
#### Full-Parameter Fine-Tuning using 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+ Fine-Tuning
|
|
|
|
|
|
|
|
```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 Fine-Tuning
|
|
|
|
|
|
|
|
```bash
|
|
|
|
llamafactory-cli train examples/extras/pissa/llama3_lora_sft.yaml
|
|
|
|
```
|
|
|
|
|
2024-05-06 22:51:02 +08:00
|
|
|
#### Mixture-of-Depths Fine-Tuning
|
|
|
|
|
|
|
|
```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 Fine-Tuning
|
|
|
|
|
|
|
|
```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 Fine-Tuning
|
|
|
|
|
2024-05-06 21:47:00 +08:00
|
|
|
```bash
|
2024-06-17 17:47:25 +08:00
|
|
|
bash examples/extras/fsdp_qlora/train.sh
|
2024-06-16 01:08:12 +08:00
|
|
|
```
|