Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +15 -0
- .env.local +42 -0
- .gitattributes +201 -0
- .github/CODE_OF_CONDUCT.md +128 -0
- .github/CONTRIBUTING.md +67 -0
- .github/ISSUE_TEMPLATE/1-bug-report.yml +61 -0
- .github/ISSUE_TEMPLATE/2-feature-request.yml +41 -0
- .github/ISSUE_TEMPLATE/config.yml +8 -0
- .github/PULL_REQUEST_TEMPLATE.md +8 -0
- .github/SECURITY.md +7 -0
- .github/workflows/docker.yml +108 -0
- .github/workflows/label_issue.yml +32 -0
- .github/workflows/publish.yml +36 -0
- .github/workflows/tests.yml +99 -0
- .pre-commit-config.yaml +28 -0
- =0.10.0, +0 -0
- CITATION.cff +44 -0
- LICENSE +201 -0
- MANIFEST.in +1 -0
- Makefile +24 -0
- README.md +948 -0
- README_zh.md +949 -0
- SUMMARY_完成情况总结.md +164 -0
- analyze_token_logs.py +165 -0
- assets/alaya_new.svg +38 -0
- assets/logo.png +0 -0
- assets/wechat.jpg +3 -0
- assets/wechat_alaya.png +3 -0
- assets/wechat_npu.jpg +3 -0
- configs/ds_zero3.json +33 -0
- data/belle_multiturn/belle_multiturn.py +82 -0
- data/dataset/01_26/CUDA内存不足解决方案.md +146 -0
- data/dataset/01_26/NCCL错误解决方案.md +120 -0
- data/dataset/01_26/ZeRO-3使用说明.md +153 -0
- data/dataset/01_26/fix_cuda_oom.sh +88 -0
- data/dataset/01_26/token_statistics.json +18 -0
- data/dataset/01_26/token_statistics.txt +19 -0
- data/dataset/01_26/toollist1.jsonl +3 -0
- data/dataset/01_26/toollist1_sample.json +0 -0
- data/dataset/01_26/toollist2.jsonl +3 -0
- data/dataset/01_26/toollist2_sample.json +0 -0
- data/dataset/01_26/接续训练示例.md +110 -0
- data/dataset/01_26/训练命令.md +231 -0
- data/dataset/12_10/LLM输入一致性对比分析.md +234 -0
- data/dataset/12_10/origin.py +2192 -0
- data/dataset/12_10/overfit_data.json +92 -0
- data/dataset/12_10/testmix_dataset.json +0 -0
- data/dataset/12_10/格式问题分析与修正建议.md +214 -0
- data/dataset/12_10/训练与推理输入对比分析.md +415 -0
- data/dataset/12_15/GT_dataset.jsonl +3 -0
.dockerignore
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.vscode
|
| 2 |
+
.git
|
| 3 |
+
.github
|
| 4 |
+
.venv
|
| 5 |
+
cache
|
| 6 |
+
docker
|
| 7 |
+
saves
|
| 8 |
+
hf_cache
|
| 9 |
+
ms_cache
|
| 10 |
+
om_cache
|
| 11 |
+
shared_data
|
| 12 |
+
output
|
| 13 |
+
.dockerignore
|
| 14 |
+
.gitattributes
|
| 15 |
+
.gitignore
|
.env.local
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Note: actually we do not support .env, just for reference
|
| 2 |
+
# api
|
| 3 |
+
API_HOST=
|
| 4 |
+
API_PORT=
|
| 5 |
+
API_KEY=
|
| 6 |
+
API_MODEL_NAME=
|
| 7 |
+
API_VERBOSE=
|
| 8 |
+
FASTAPI_ROOT_PATH=
|
| 9 |
+
MAX_CONCURRENT=
|
| 10 |
+
# general
|
| 11 |
+
DISABLE_VERSION_CHECK=
|
| 12 |
+
FORCE_CHECK_IMPORTS=
|
| 13 |
+
ALLOW_EXTRA_ARGS=
|
| 14 |
+
LLAMAFACTORY_VERBOSITY=
|
| 15 |
+
USE_MODELSCOPE_HUB=
|
| 16 |
+
USE_OPENMIND_HUB=
|
| 17 |
+
USE_RAY=
|
| 18 |
+
RECORD_VRAM=
|
| 19 |
+
OPTIM_TORCH=
|
| 20 |
+
NPU_JIT_COMPILE=
|
| 21 |
+
# torchrun
|
| 22 |
+
FORCE_TORCHRUN=
|
| 23 |
+
MASTER_ADDR=
|
| 24 |
+
MASTER_PORT=
|
| 25 |
+
NNODES=
|
| 26 |
+
NODE_RANK=
|
| 27 |
+
NPROC_PER_NODE=
|
| 28 |
+
# wandb
|
| 29 |
+
WANDB_DISABLED=
|
| 30 |
+
WANDB_PROJECT=
|
| 31 |
+
WANDB_API_KEY=
|
| 32 |
+
# gradio ui
|
| 33 |
+
GRADIO_SHARE=
|
| 34 |
+
GRADIO_SERVER_NAME=
|
| 35 |
+
GRADIO_SERVER_PORT=
|
| 36 |
+
GRADIO_ROOT_PATH=
|
| 37 |
+
GRADIO_IPV6=
|
| 38 |
+
# setup
|
| 39 |
+
ENABLE_SHORT_CONSOLE=
|
| 40 |
+
# reserved (do not use)
|
| 41 |
+
LLAMABOARD_ENABLED=
|
| 42 |
+
LLAMABOARD_WORKDIR=
|
.gitattributes
CHANGED
|
@@ -33,3 +33,204 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/wechat.jpg filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/wechat_alaya.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/wechat_npu.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
data/dataset/01_26/toollist1.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
data/dataset/01_26/toollist2.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
data/dataset/12_15/GT_dataset.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
data/dataset/12_15/train_converted_APIGen.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
data/dataset/12_15/train_converted_alpaca.json filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
data/dataset/12_15/train_converted_alpaca_gt.json filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
data/dataset/12_24/yifan_toollist1.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
data/dataset/12_24/yifan_toollist2.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
data/dataset/12_27/toollist1_dataset.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
evaluation/data_evaluation_demo_0926_v19.json filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
evaluation/evaluation_checkpoint_demo_0929_v20.json filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
evaluation/multi_baseline_lora/result__data_models_Qwen3-8B.json filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
evaluation/multi_baseline_lora/result_my_lora.json filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
saves/Qwen3-8B/lora/train_2025-12-17-13-03/checkpoint-125/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
saves/Qwen3-8B/lora/train_2025-12-17-13-03/monitoring_logs/label_analysis_20251217_130423.log filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
saves/Qwen3-8B/lora/train_2025-12-17-13-03/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
saves/Qwen3-8B/lora/train_2025-12-18-22-07/checkpoint-152/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
saves/Qwen3-8B/lora/train_2025-12-18-22-07/monitoring_logs/label_analysis_20251218_220754.log filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
saves/Qwen3-8B/lora/train_2025-12-18-22-07/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
saves/Qwen3-8B/lora/train_2025-12-19-00-00/checkpoint-1000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
saves/Qwen3-8B/lora/train_2025-12-19-00-00/checkpoint-200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
saves/Qwen3-8B/lora/train_2025-12-19-00-00/checkpoint-400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
saves/Qwen3-8B/lora/train_2025-12-19-00-00/checkpoint-600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
saves/Qwen3-8B/lora/train_2025-12-19-00-00/monitoring_logs/label_analysis_20251219_000304.log filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
saves/Qwen3-8B/lora/train_2025-12-19-19-19/checkpoint-200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
saves/Qwen3-8B/lora/train_2025-12-19-19-19/checkpoint-304/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
saves/Qwen3-8B/lora/train_2025-12-19-19-19/monitoring_logs/label_analysis_20251219_191948.log filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
saves/Qwen3-8B/lora/train_2025-12-19-19-19/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
saves/Qwen3-8B/lora/train_2025-12-24-14-25/checkpoint-123/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
saves/Qwen3-8B/lora/train_2025-12-24-14-25/monitoring_logs/label_analysis_20251224_142538.log filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
saves/Qwen3-8B/lora/train_2025-12-24-14-25/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
saves/Qwen3-8B/lora/train_2025-12-24-14-27/checkpoint-123/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
saves/Qwen3-8B/lora/train_2025-12-24-14-27/monitoring_logs/label_analysis_20251224_142750.log filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
saves/Qwen3-8B/lora/train_2025-12-24-14-27/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
saves/Qwen3-8B/lora/train_2025-12-25-12-00/checkpoint-125/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
saves/Qwen3-8B/lora/train_2025-12-25-12-00/monitoring_logs/label_analysis_20251225_120027.log filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
saves/Qwen3-8B/lora/train_2025-12-25-12-00/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-1000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-1200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-1400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-1600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-1800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-2000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-2200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-2400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-2600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/checkpoint-800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/monitoring_logs/label_analysis_20260126_153852.log filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
saves/Qwen3-8B/lora/train_2026-01-26-15-35/monitoring_logs/label_analysis_20260126_153853.log filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
saves/Qwen3-8B/lora/train_2026-01-27-15-49/checkpoint-2800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 92 |
+
saves/Qwen3-8B/lora/train_2026-01-27-15-49/checkpoint-3000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 93 |
+
saves/Qwen3-8B/lora/train_2026-01-27-15-49/monitoring_logs/label_analysis_20260127_155716.log filter=lfs diff=lfs merge=lfs -text
|
| 94 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-3200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 95 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-3400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 96 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-3600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 97 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-3800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 98 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-4000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 99 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-4200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 100 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-4400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 101 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-4600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 102 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-4800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-5000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-5200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-5400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 106 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-5600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 107 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/checkpoint-5800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 108 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/monitoring_logs/label_analysis_20260127_211415.log filter=lfs diff=lfs merge=lfs -text
|
| 109 |
+
saves/Qwen3-8B/lora/train_2026-01-27-21-01/monitoring_logs/label_analysis_20260127_211416.log filter=lfs diff=lfs merge=lfs -text
|
| 110 |
+
saves/Qwen3-8B/lora/train_2026-01-28-18-13/checkpoint-6000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 111 |
+
saves/Qwen3-8B/lora/train_2026-01-28-18-13/monitoring_logs/label_analysis_20260128_181359.log filter=lfs diff=lfs merge=lfs -text
|
| 112 |
+
saves/Qwen3-8B/lora/train_2026-01-29-09-32/checkpoint-6200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 113 |
+
saves/Qwen3-8B/lora/train_2026-01-29-09-32/checkpoint-6400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 114 |
+
saves/Qwen3-8B/lora/train_2026-01-29-09-32/monitoring_logs/label_analysis_20260129_093236.log filter=lfs diff=lfs merge=lfs -text
|
| 115 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-10000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 116 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-10200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 117 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-10400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 118 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-10600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 119 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-10800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 120 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-11000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 121 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-11200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 122 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-6600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 123 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-6800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 124 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-7000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 125 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-7200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 126 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-7400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 127 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-7600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 128 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-7800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 129 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-8000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 130 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-8200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 131 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-8400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 132 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-8600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 133 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-8800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 134 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-9000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 135 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-9200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 136 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-9400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 137 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-9600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 138 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-9800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 139 |
+
saves/Qwen3-8B/lora/train_2026-01-29-20-31/monitoring_logs/label_analysis_20260129_203222.log filter=lfs diff=lfs merge=lfs -text
|
| 140 |
+
saves/Qwen3-8B/lora/train_2026-01-30-16-41/checkpoint-200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 141 |
+
saves/Qwen3-8B/lora/train_2026-01-30-16-41/checkpoint-400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 142 |
+
saves/Qwen3-8B/lora/train_2026-01-30-16-41/monitoring_logs/label_analysis_20260130_164253.log filter=lfs diff=lfs merge=lfs -text
|
| 143 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-1000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 144 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-1200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 145 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-1400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 146 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-1600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 147 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-1800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 148 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 149 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-2000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 150 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-2200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 151 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-2400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 152 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-2600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 153 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-2800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 154 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-3000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 155 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-3200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 156 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-3400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 157 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-3600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 158 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-3800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 159 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 160 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-4000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 161 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-4200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 162 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-4400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 163 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-4600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 164 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-4800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 165 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-5000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 166 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-5200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 167 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-5400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 168 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-5600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 169 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-5800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 170 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 171 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-6000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 172 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-6200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 173 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-6400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 174 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-6600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 175 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-6800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 176 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-7000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 177 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-7200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 178 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-7400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 179 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-7600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 180 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-7800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 181 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 182 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-8000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 183 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-8200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 184 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-8400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 185 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-8600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 186 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/checkpoint-8800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 187 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/monitoring_logs/label_analysis_20260130_205039.log filter=lfs diff=lfs merge=lfs -text
|
| 188 |
+
saves/Qwen3-8B/lora/train_2026-01-30-20-50/monitoring_logs/label_analysis_20260130_205040.log filter=lfs diff=lfs merge=lfs -text
|
| 189 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-1000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 190 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-1200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 191 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-1400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 192 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-1600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 193 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-1800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 194 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 195 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-2000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 196 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-2200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 197 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-2400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 198 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-2600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 199 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-2800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 200 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-3000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 201 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-3200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 202 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-3400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 203 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-3600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 204 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-3800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 205 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 206 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-4000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 207 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-4200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 208 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-4400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 209 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-4600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 210 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-4800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 211 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-5000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 212 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-5200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 213 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-5400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 214 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-5600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 215 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-5800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 216 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 217 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-6000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 218 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-6200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 219 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-6400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 220 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-6600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 221 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-6800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 222 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-7000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 223 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-7200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 224 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-7400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 225 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-7600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 226 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-7800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 227 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-800/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 228 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-8000/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 229 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-8200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 230 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-8400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 231 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/checkpoint-8600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 232 |
+
saves/Qwen3-8B/lora/train_2026-01-31-16-26/monitoring_logs/label_analysis_20260131_163852.log filter=lfs diff=lfs merge=lfs -text
|
| 233 |
+
saves/Qwen3-8B/lora/train_2026-02-01-19-27/checkpoint-200/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 234 |
+
saves/Qwen3-8B/lora/train_2026-02-01-19-27/checkpoint-400/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 235 |
+
saves/Qwen3-8B/lora/train_2026-02-01-19-27/checkpoint-600/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 236 |
+
saves/Qwen3-8B/lora/train_2026-02-01-19-27/monitoring_logs/label_analysis_20260201_192731.log filter=lfs diff=lfs merge=lfs -text
|
.github/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributor Covenant Code of Conduct
|
| 2 |
+
|
| 3 |
+
## Our Pledge
|
| 4 |
+
|
| 5 |
+
We as members, contributors, and leaders pledge to make participation in our
|
| 6 |
+
community a harassment-free experience for everyone, regardless of age, body
|
| 7 |
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
| 8 |
+
identity and expression, level of experience, education, socio-economic status,
|
| 9 |
+
nationality, personal appearance, race, religion, or sexual identity
|
| 10 |
+
and orientation.
|
| 11 |
+
|
| 12 |
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
| 13 |
+
diverse, inclusive, and healthy community.
|
| 14 |
+
|
| 15 |
+
## Our Standards
|
| 16 |
+
|
| 17 |
+
Examples of behavior that contributes to a positive environment for our
|
| 18 |
+
community include:
|
| 19 |
+
|
| 20 |
+
* Demonstrating empathy and kindness toward other people
|
| 21 |
+
* Being respectful of differing opinions, viewpoints, and experiences
|
| 22 |
+
* Giving and gracefully accepting constructive feedback
|
| 23 |
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
| 24 |
+
and learning from the experience
|
| 25 |
+
* Focusing on what is best not just for us as individuals, but for the
|
| 26 |
+
overall community
|
| 27 |
+
|
| 28 |
+
Examples of unacceptable behavior include:
|
| 29 |
+
|
| 30 |
+
* The use of sexualized language or imagery, and sexual attention or
|
| 31 |
+
advances of any kind
|
| 32 |
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
| 33 |
+
* Public or private harassment
|
| 34 |
+
* Publishing others' private information, such as a physical or email
|
| 35 |
+
address, without their explicit permission
|
| 36 |
+
* Other conduct which could reasonably be considered inappropriate in a
|
| 37 |
+
professional setting
|
| 38 |
+
|
| 39 |
+
## Enforcement Responsibilities
|
| 40 |
+
|
| 41 |
+
Community leaders are responsible for clarifying and enforcing our standards of
|
| 42 |
+
acceptable behavior and will take appropriate and fair corrective action in
|
| 43 |
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
| 44 |
+
or harmful.
|
| 45 |
+
|
| 46 |
+
Community leaders have the right and responsibility to remove, edit, or reject
|
| 47 |
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
| 48 |
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
| 49 |
+
decisions when appropriate.
|
| 50 |
+
|
| 51 |
+
## Scope
|
| 52 |
+
|
| 53 |
+
This Code of Conduct applies within all community spaces, and also applies when
|
| 54 |
+
an individual is officially representing the community in public spaces.
|
| 55 |
+
Examples of representing our community include using an official e-mail address,
|
| 56 |
+
posting via an official social media account, or acting as an appointed
|
| 57 |
+
representative at an online or offline event.
|
| 58 |
+
|
| 59 |
+
## Enforcement
|
| 60 |
+
|
| 61 |
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
| 62 |
+
reported to the community leaders responsible for enforcement at
|
| 63 |
+
`hoshihiyouga AT gmail DOT com`.
|
| 64 |
+
All complaints will be reviewed and investigated promptly and fairly.
|
| 65 |
+
|
| 66 |
+
All community leaders are obligated to respect the privacy and security of the
|
| 67 |
+
reporter of any incident.
|
| 68 |
+
|
| 69 |
+
## Enforcement Guidelines
|
| 70 |
+
|
| 71 |
+
Community leaders will follow these Community Impact Guidelines in determining
|
| 72 |
+
the consequences for any action they deem in violation of this Code of Conduct:
|
| 73 |
+
|
| 74 |
+
### 1. Correction
|
| 75 |
+
|
| 76 |
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
| 77 |
+
unprofessional or unwelcome in the community.
|
| 78 |
+
|
| 79 |
+
**Consequence**: A private, written warning from community leaders, providing
|
| 80 |
+
clarity around the nature of the violation and an explanation of why the
|
| 81 |
+
behavior was inappropriate. A public apology may be requested.
|
| 82 |
+
|
| 83 |
+
### 2. Warning
|
| 84 |
+
|
| 85 |
+
**Community Impact**: A violation through a single incident or series
|
| 86 |
+
of actions.
|
| 87 |
+
|
| 88 |
+
**Consequence**: A warning with consequences for continued behavior. No
|
| 89 |
+
interaction with the people involved, including unsolicited interaction with
|
| 90 |
+
those enforcing the Code of Conduct, for a specified period of time. This
|
| 91 |
+
includes avoiding interactions in community spaces as well as external channels
|
| 92 |
+
like social media. Violating these terms may lead to a temporary or
|
| 93 |
+
permanent ban.
|
| 94 |
+
|
| 95 |
+
### 3. Temporary Ban
|
| 96 |
+
|
| 97 |
+
**Community Impact**: A serious violation of community standards, including
|
| 98 |
+
sustained inappropriate behavior.
|
| 99 |
+
|
| 100 |
+
**Consequence**: A temporary ban from any sort of interaction or public
|
| 101 |
+
communication with the community for a specified period of time. No public or
|
| 102 |
+
private interaction with the people involved, including unsolicited interaction
|
| 103 |
+
with those enforcing the Code of Conduct, is allowed during this period.
|
| 104 |
+
Violating these terms may lead to a permanent ban.
|
| 105 |
+
|
| 106 |
+
### 4. Permanent Ban
|
| 107 |
+
|
| 108 |
+
**Community Impact**: Demonstrating a pattern of violation of community
|
| 109 |
+
standards, including sustained inappropriate behavior, harassment of an
|
| 110 |
+
individual, or aggression toward or disparagement of classes of individuals.
|
| 111 |
+
|
| 112 |
+
**Consequence**: A permanent ban from any sort of public interaction within
|
| 113 |
+
the community.
|
| 114 |
+
|
| 115 |
+
## Attribution
|
| 116 |
+
|
| 117 |
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
| 118 |
+
version 2.0, available at
|
| 119 |
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
| 120 |
+
|
| 121 |
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
| 122 |
+
enforcement ladder](https://github.com/mozilla/diversity).
|
| 123 |
+
|
| 124 |
+
[homepage]: https://www.contributor-covenant.org
|
| 125 |
+
|
| 126 |
+
For answers to common questions about this code of conduct, see the FAQ at
|
| 127 |
+
https://www.contributor-covenant.org/faq. Translations are available at
|
| 128 |
+
https://www.contributor-covenant.org/translations.
|
.github/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributing to LLaMA Factory
|
| 2 |
+
|
| 3 |
+
Everyone is welcome to contribute, and we value everybody's contribution. Code contributions are not the only way to help the community. Answering questions, helping others, and improving the documentation are also immensely valuable.
|
| 4 |
+
|
| 5 |
+
It also helps us if you spread the word! Reference the library in blog posts about the awesome projects it made possible, shout out on Twitter every time it has helped you, or simply ⭐️ the repository to say thank you.
|
| 6 |
+
|
| 7 |
+
However you choose to contribute, please be mindful and respect our [code of conduct](CODE_OF_CONDUCT.md).
|
| 8 |
+
|
| 9 |
+
**This guide was heavily inspired by [transformers guide to contributing](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).**
|
| 10 |
+
|
| 11 |
+
## Ways to contribute
|
| 12 |
+
|
| 13 |
+
There are several ways you can contribute to LLaMA Factory:
|
| 14 |
+
|
| 15 |
+
* Fix outstanding issues with the existing code.
|
| 16 |
+
* Submit issues related to bugs or desired new features.
|
| 17 |
+
* Contribute to the examples or to the documentation.
|
| 18 |
+
|
| 19 |
+
### Style guide
|
| 20 |
+
|
| 21 |
+
LLaMA Factory follows the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html), check it for details.
|
| 22 |
+
|
| 23 |
+
### Create a Pull Request
|
| 24 |
+
|
| 25 |
+
1. Fork the [repository](https://github.com/hiyouga/LLaMA-Factory) by clicking on the [Fork](https://github.com/hiyouga/LLaMA-Factory/fork) button on the repository's page. This creates a copy of the code under your GitHub user account.
|
| 26 |
+
|
| 27 |
+
2. Clone your fork to your local disk, and add the base repository as a remote:
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
git clone git@github.com:[username]/LLaMA-Factory.git
|
| 31 |
+
cd LLaMA-Factory
|
| 32 |
+
git remote add upstream https://github.com/hiyouga/LLaMA-Factory.git
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
3. Create a new branch to hold your development changes:
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
git checkout -b dev_your_branch
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
4. Set up a development environment by running the following command in a virtual environment:
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
pip install -e ".[dev]"
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
If LLaMA Factory was already installed in the virtual environment, remove it with `pip uninstall llamafactory` before reinstalling it in editable mode with the -e flag.
|
| 48 |
+
|
| 49 |
+
5. Check code before commit:
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
make commit
|
| 53 |
+
make style && make quality
|
| 54 |
+
make test
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
6. Submit changes:
|
| 58 |
+
|
| 59 |
+
```bash
|
| 60 |
+
git add .
|
| 61 |
+
git commit -m "commit message"
|
| 62 |
+
git fetch upstream
|
| 63 |
+
git rebase upstream/main
|
| 64 |
+
git push -u origin dev_your_branch
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
7. Create a merge request from your branch `dev_your_branch` at [origin repo](https://github.com/hiyouga/LLaMA-Factory).
|
.github/ISSUE_TEMPLATE/1-bug-report.yml
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: "\U0001F41B Bug / help"
|
| 2 |
+
description: Create a report to help us improve the LLaMA Factory
|
| 3 |
+
labels: ["bug", "pending"]
|
| 4 |
+
body:
|
| 5 |
+
- type: markdown
|
| 6 |
+
attributes:
|
| 7 |
+
value: |
|
| 8 |
+
Issues included in **[FAQs](https://github.com/hiyouga/LLaMA-Factory/issues/4614)** or those with **insufficient** information may be closed without a response.
|
| 9 |
+
已经包含在 **[常见问题](https://github.com/hiyouga/LLaMA-Factory/issues/4614)** 内或提供信息**不完整**的 issues 可能不会被回复。
|
| 10 |
+
|
| 11 |
+
- type: markdown
|
| 12 |
+
attributes:
|
| 13 |
+
value: |
|
| 14 |
+
Please do not create issues that are not related to framework bugs under this category, use **[Discussions](https://github.com/hiyouga/LLaMA-Factory/discussions/categories/q-a)** instead.
|
| 15 |
+
请勿在此分类下创建和框架 bug 无关的 issues,训练问题求助请使用 **[讨论区](https://github.com/hiyouga/LLaMA-Factory/discussions/categories/q-a)**。
|
| 16 |
+
|
| 17 |
+
- type: checkboxes
|
| 18 |
+
id: reminder
|
| 19 |
+
attributes:
|
| 20 |
+
label: Reminder
|
| 21 |
+
description: |
|
| 22 |
+
Please ensure you have read the above rules carefully and searched the existing issues (including FAQs).
|
| 23 |
+
请确保您已经认真阅读了上述规则并且搜索过现有的 issues(包括常见问题)。
|
| 24 |
+
|
| 25 |
+
options:
|
| 26 |
+
- label: I have read the above rules and searched the existing issues.
|
| 27 |
+
required: true
|
| 28 |
+
|
| 29 |
+
- type: textarea
|
| 30 |
+
id: system-info
|
| 31 |
+
validations:
|
| 32 |
+
required: true
|
| 33 |
+
attributes:
|
| 34 |
+
label: System Info
|
| 35 |
+
description: |
|
| 36 |
+
Please share your system info with us. You can run the command **llamafactory-cli env** and copy-paste its output below.
|
| 37 |
+
请提供您的系统信息。您可以在命令行运行 **llamafactory-cli env** 并将其输出复制到该文本框中。
|
| 38 |
+
|
| 39 |
+
placeholder: llamafactory version, platform, python version, ...
|
| 40 |
+
|
| 41 |
+
- type: textarea
|
| 42 |
+
id: reproduction
|
| 43 |
+
validations:
|
| 44 |
+
required: true
|
| 45 |
+
attributes:
|
| 46 |
+
label: Reproduction
|
| 47 |
+
description: |
|
| 48 |
+
Please provide entry arguments, error messages and stack traces that reproduces the problem.
|
| 49 |
+
请提供入口参数,错误日志以及异常堆栈以便于我们复现问题。
|
| 50 |
+
|
| 51 |
+
value: |
|
| 52 |
+
```text
|
| 53 |
+
Put your message here.
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
- type: textarea
|
| 57 |
+
id: others
|
| 58 |
+
validations:
|
| 59 |
+
required: false
|
| 60 |
+
attributes:
|
| 61 |
+
label: Others
|
.github/ISSUE_TEMPLATE/2-feature-request.yml
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: "\U0001F680 Feature request"
|
| 2 |
+
description: Submit a request for a new feature
|
| 3 |
+
labels: ["enhancement", "pending"]
|
| 4 |
+
body:
|
| 5 |
+
- type: markdown
|
| 6 |
+
attributes:
|
| 7 |
+
value: |
|
| 8 |
+
Please do not create issues that are not related to new features under this category.
|
| 9 |
+
请勿在此分类下创建和新特性无关的 issues。
|
| 10 |
+
|
| 11 |
+
- type: checkboxes
|
| 12 |
+
id: reminder
|
| 13 |
+
attributes:
|
| 14 |
+
label: Reminder
|
| 15 |
+
description: |
|
| 16 |
+
Please ensure you have read the above rules carefully and searched the existing issues.
|
| 17 |
+
请确保您已经认真阅读了上述规则并且搜索过现有的 issues。
|
| 18 |
+
|
| 19 |
+
options:
|
| 20 |
+
- label: I have read the above rules and searched the existing issues.
|
| 21 |
+
required: true
|
| 22 |
+
|
| 23 |
+
- type: textarea
|
| 24 |
+
id: description
|
| 25 |
+
validations:
|
| 26 |
+
required: true
|
| 27 |
+
attributes:
|
| 28 |
+
label: Description
|
| 29 |
+
description: |
|
| 30 |
+
A clear and concise description of the feature proposal.
|
| 31 |
+
请详细描述您希望加入的新功能特性。
|
| 32 |
+
|
| 33 |
+
- type: textarea
|
| 34 |
+
id: contribution
|
| 35 |
+
validations:
|
| 36 |
+
required: false
|
| 37 |
+
attributes:
|
| 38 |
+
label: Pull Request
|
| 39 |
+
description: |
|
| 40 |
+
Have you already created the relevant PR and submitted the code?
|
| 41 |
+
您是否已经创建了相关 PR 并提交了代码?
|
.github/ISSUE_TEMPLATE/config.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
blank_issues_enabled: false
|
| 2 |
+
contact_links:
|
| 3 |
+
- name: 📚 FAQs | 常见问题
|
| 4 |
+
url: https://github.com/hiyouga/LLaMA-Factory/issues/4614
|
| 5 |
+
about: Reading in advance is recommended | 建议提前阅读
|
| 6 |
+
- name: Discussions | 讨论区
|
| 7 |
+
url: https://github.com/hiyouga/LLaMA-Factory/discussions
|
| 8 |
+
about: Please ask fine-tuning questions here | 请在这里讨论训练问题
|
.github/PULL_REQUEST_TEMPLATE.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# What does this PR do?
|
| 2 |
+
|
| 3 |
+
Fixes # (issue)
|
| 4 |
+
|
| 5 |
+
## Before submitting
|
| 6 |
+
|
| 7 |
+
- [ ] Did you read the [contributor guideline](https://github.com/hiyouga/LLaMA-Factory/blob/main/.github/CONTRIBUTING.md)?
|
| 8 |
+
- [ ] Did you write any new necessary tests?
|
.github/SECURITY.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Reporting Security Issues
|
| 2 |
+
|
| 3 |
+
To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/hiyouga/LLaMA-Factory/security/advisories/new) tab.
|
| 4 |
+
|
| 5 |
+
We will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance.
|
| 6 |
+
|
| 7 |
+
Report security bugs in third-party modules to the person or team maintaining the module.
|
.github/workflows/docker.yml
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: docker
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
workflow_dispatch:
|
| 5 |
+
push:
|
| 6 |
+
branches:
|
| 7 |
+
- "main"
|
| 8 |
+
paths:
|
| 9 |
+
- "**/*.py"
|
| 10 |
+
- "requirements.txt"
|
| 11 |
+
- "docker/**"
|
| 12 |
+
- ".github/workflows/*.yml"
|
| 13 |
+
pull_request:
|
| 14 |
+
branches:
|
| 15 |
+
- "main"
|
| 16 |
+
paths:
|
| 17 |
+
- "**/*.py"
|
| 18 |
+
- "requirements.txt"
|
| 19 |
+
- "docker/**"
|
| 20 |
+
- ".github/workflows/*.yml"
|
| 21 |
+
|
| 22 |
+
jobs:
|
| 23 |
+
build:
|
| 24 |
+
strategy:
|
| 25 |
+
fail-fast: false
|
| 26 |
+
matrix:
|
| 27 |
+
device:
|
| 28 |
+
- "cuda"
|
| 29 |
+
- "npu"
|
| 30 |
+
|
| 31 |
+
runs-on: ubuntu-latest
|
| 32 |
+
|
| 33 |
+
concurrency:
|
| 34 |
+
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.device }}
|
| 35 |
+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
| 36 |
+
|
| 37 |
+
environment:
|
| 38 |
+
name: docker
|
| 39 |
+
url: https://hub.docker.com/r/hiyouga/llamafactory
|
| 40 |
+
|
| 41 |
+
steps:
|
| 42 |
+
- name: Free up disk space
|
| 43 |
+
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
|
| 44 |
+
with:
|
| 45 |
+
tool-cache: true
|
| 46 |
+
docker-images: false
|
| 47 |
+
|
| 48 |
+
- name: Checkout
|
| 49 |
+
uses: actions/checkout@v4
|
| 50 |
+
|
| 51 |
+
- name: Set up Python
|
| 52 |
+
uses: actions/setup-python@v5
|
| 53 |
+
with:
|
| 54 |
+
python-version: "3.9"
|
| 55 |
+
|
| 56 |
+
- name: Get llamafactory version
|
| 57 |
+
id: version
|
| 58 |
+
run: |
|
| 59 |
+
echo "tag=$(python setup.py --version | sed 's/\.dev0//')" >> "$GITHUB_OUTPUT"
|
| 60 |
+
|
| 61 |
+
- name: Set up Docker Buildx
|
| 62 |
+
uses: docker/setup-buildx-action@v3
|
| 63 |
+
|
| 64 |
+
- name: Login to Docker Hub
|
| 65 |
+
if: ${{ github.event_name != 'pull_request' }}
|
| 66 |
+
uses: docker/login-action@v3
|
| 67 |
+
with:
|
| 68 |
+
username: ${{ vars.DOCKERHUB_USERNAME }}
|
| 69 |
+
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
| 70 |
+
|
| 71 |
+
- name: Login to Quay
|
| 72 |
+
if: ${{ github.event_name != 'pull_request' && matrix.device == 'npu' }}
|
| 73 |
+
uses: docker/login-action@v3
|
| 74 |
+
with:
|
| 75 |
+
registry: quay.io
|
| 76 |
+
username: ${{ vars.QUAY_ASCEND_USERNAME }}
|
| 77 |
+
password: ${{ secrets.QUAY_ASCEND_TOKEN }}
|
| 78 |
+
|
| 79 |
+
- name: Build and push Docker image (CUDA)
|
| 80 |
+
if: ${{ matrix.device == 'cuda' }}
|
| 81 |
+
uses: docker/build-push-action@v6
|
| 82 |
+
with:
|
| 83 |
+
context: .
|
| 84 |
+
file: ./docker/docker-cuda/Dockerfile
|
| 85 |
+
build-args: |
|
| 86 |
+
EXTRAS=metrics,deepspeed,liger-kernel
|
| 87 |
+
push: ${{ github.event_name != 'pull_request' }}
|
| 88 |
+
tags: |
|
| 89 |
+
docker.io/hiyouga/llamafactory:latest
|
| 90 |
+
docker.io/hiyouga/llamafactory:${{ steps.version.outputs.tag }}
|
| 91 |
+
cache-from: type=gha
|
| 92 |
+
cache-to: type=gha,mode=max
|
| 93 |
+
|
| 94 |
+
- name: Build and push Docker image (NPU)
|
| 95 |
+
if: ${{ matrix.device == 'npu' }}
|
| 96 |
+
uses: docker/build-push-action@v6
|
| 97 |
+
with:
|
| 98 |
+
context: .
|
| 99 |
+
platforms: linux/amd64,linux/arm64
|
| 100 |
+
file: ./docker/docker-npu/Dockerfile
|
| 101 |
+
push: ${{ github.event_name != 'pull_request' }}
|
| 102 |
+
tags: |
|
| 103 |
+
docker.io/hiyouga/llamafactory:latest-npu-a2
|
| 104 |
+
docker.io/hiyouga/llamafactory:${{ steps.version.outputs.tag }}-npu-a2
|
| 105 |
+
quay.io/ascend/llamafactory:latest-npu-a2
|
| 106 |
+
quay.io/ascend/llamafactory:${{ steps.version.outputs.tag }}-npu-a2
|
| 107 |
+
cache-from: type=gha
|
| 108 |
+
cache-to: type=gha,mode=max
|
.github/workflows/label_issue.yml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: label_issue
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
issues:
|
| 5 |
+
types:
|
| 6 |
+
- opened
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
label_issue:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
permissions:
|
| 13 |
+
issues: write
|
| 14 |
+
|
| 15 |
+
steps:
|
| 16 |
+
- env:
|
| 17 |
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
| 18 |
+
ISSUE_URL: ${{ github.event.issue.html_url }}
|
| 19 |
+
ISSUE_TITLE: ${{ github.event.issue.title }}
|
| 20 |
+
run: |
|
| 21 |
+
LABEL=""
|
| 22 |
+
NPU_KEYWORDS=(npu huawei ascend 华为 昇腾 910)
|
| 23 |
+
ISSUE_TITLE_LOWER=$(echo $ISSUE_TITLE | tr '[:upper:]' '[:lower:]')
|
| 24 |
+
for KEYWORD in ${NPU_KEYWORDS[@]}; do
|
| 25 |
+
if [[ $ISSUE_TITLE_LOWER == *$KEYWORD* ]] && [[ $ISSUE_TITLE_LOWER != *input* ]]; then
|
| 26 |
+
LABEL="npu"
|
| 27 |
+
break
|
| 28 |
+
fi
|
| 29 |
+
done
|
| 30 |
+
if [ -n "$LABEL" ]; then
|
| 31 |
+
gh issue edit $ISSUE_URL --add-label $LABEL
|
| 32 |
+
fi
|
.github/workflows/publish.yml
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: publish
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
workflow_dispatch:
|
| 5 |
+
release:
|
| 6 |
+
types:
|
| 7 |
+
- published
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
publish:
|
| 11 |
+
name: Upload release to PyPI
|
| 12 |
+
|
| 13 |
+
runs-on: ubuntu-latest
|
| 14 |
+
|
| 15 |
+
environment:
|
| 16 |
+
name: release
|
| 17 |
+
url: https://pypi.org/p/llamafactory
|
| 18 |
+
|
| 19 |
+
permissions:
|
| 20 |
+
id-token: write
|
| 21 |
+
|
| 22 |
+
steps:
|
| 23 |
+
- name: Checkout
|
| 24 |
+
uses: actions/checkout@v4
|
| 25 |
+
|
| 26 |
+
- name: Set up Python
|
| 27 |
+
uses: actions/setup-python@v5
|
| 28 |
+
with:
|
| 29 |
+
python-version: "3.9"
|
| 30 |
+
|
| 31 |
+
- name: Build package
|
| 32 |
+
run: |
|
| 33 |
+
make build
|
| 34 |
+
|
| 35 |
+
- name: Publish package
|
| 36 |
+
uses: pypa/gh-action-pypi-publish@release/v1
|
.github/workflows/tests.yml
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: tests
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
workflow_dispatch:
|
| 5 |
+
push:
|
| 6 |
+
branches:
|
| 7 |
+
- "main"
|
| 8 |
+
paths:
|
| 9 |
+
- "**/*.py"
|
| 10 |
+
- "requirements.txt"
|
| 11 |
+
- ".github/workflows/*.yml"
|
| 12 |
+
pull_request:
|
| 13 |
+
branches:
|
| 14 |
+
- "main"
|
| 15 |
+
paths:
|
| 16 |
+
- "**/*.py"
|
| 17 |
+
- "requirements.txt"
|
| 18 |
+
- ".github/workflows/*.yml"
|
| 19 |
+
|
| 20 |
+
jobs:
|
| 21 |
+
tests:
|
| 22 |
+
strategy:
|
| 23 |
+
fail-fast: false
|
| 24 |
+
matrix:
|
| 25 |
+
python:
|
| 26 |
+
- "3.9"
|
| 27 |
+
- "3.10"
|
| 28 |
+
- "3.11"
|
| 29 |
+
- "3.12"
|
| 30 |
+
os:
|
| 31 |
+
- "ubuntu-latest"
|
| 32 |
+
- "windows-latest"
|
| 33 |
+
- "macos-13"
|
| 34 |
+
transformers:
|
| 35 |
+
- null
|
| 36 |
+
include: # test backward compatibility
|
| 37 |
+
- python: "3.9"
|
| 38 |
+
os: "ubuntu-latest"
|
| 39 |
+
transformers: "4.49.0"
|
| 40 |
+
- python: "3.9"
|
| 41 |
+
os: "ubuntu-latest"
|
| 42 |
+
transformers: "4.51.0"
|
| 43 |
+
|
| 44 |
+
runs-on: ${{ matrix.os }}
|
| 45 |
+
|
| 46 |
+
concurrency:
|
| 47 |
+
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python }}-${{ matrix.transformers }}
|
| 48 |
+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
| 49 |
+
|
| 50 |
+
env:
|
| 51 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 52 |
+
OS_NAME: ${{ matrix.os }}
|
| 53 |
+
|
| 54 |
+
steps:
|
| 55 |
+
- name: Checkout
|
| 56 |
+
uses: actions/checkout@v4
|
| 57 |
+
|
| 58 |
+
- name: Set up Python
|
| 59 |
+
uses: actions/setup-python@v5
|
| 60 |
+
with:
|
| 61 |
+
python-version: ${{ matrix.python }}
|
| 62 |
+
cache: "pip"
|
| 63 |
+
cache-dependency-path: "**/requirements*.txt"
|
| 64 |
+
|
| 65 |
+
- name: Install dependencies
|
| 66 |
+
run: |
|
| 67 |
+
python -m pip install --upgrade pip
|
| 68 |
+
python -m pip install ".[torch,dev]"
|
| 69 |
+
|
| 70 |
+
- name: Install transformers
|
| 71 |
+
if: ${{ matrix.transformers }}
|
| 72 |
+
run: |
|
| 73 |
+
python -m pip install "transformers==${{ matrix.transformers }}"
|
| 74 |
+
|
| 75 |
+
- name: Cache files
|
| 76 |
+
id: hf-hub-cache
|
| 77 |
+
uses: actions/cache@v4
|
| 78 |
+
with:
|
| 79 |
+
path: ${{ runner.temp }}/huggingface
|
| 80 |
+
key: huggingface-${{ matrix.os }}-${{ matrix.python }}-${{ matrix.transformers }}-${{ hashFiles('tests/version.txt') }}
|
| 81 |
+
|
| 82 |
+
- name: Check quality
|
| 83 |
+
run: |
|
| 84 |
+
make style && make quality
|
| 85 |
+
|
| 86 |
+
- name: Check license
|
| 87 |
+
run: |
|
| 88 |
+
make license
|
| 89 |
+
|
| 90 |
+
- name: Check build
|
| 91 |
+
run: |
|
| 92 |
+
make build
|
| 93 |
+
|
| 94 |
+
- name: Test with pytest
|
| 95 |
+
run: |
|
| 96 |
+
make test
|
| 97 |
+
env:
|
| 98 |
+
HF_HOME: ${{ runner.temp }}/huggingface
|
| 99 |
+
HF_HUB_OFFLINE: "${{ steps.hf-hub-cache.outputs.cache-hit == 'true' && '1' || '0' }}"
|
.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
repos:
|
| 2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
| 3 |
+
rev: v5.0.0
|
| 4 |
+
hooks:
|
| 5 |
+
- id: check-ast
|
| 6 |
+
- id: check-added-large-files
|
| 7 |
+
args: ['--maxkb=25000']
|
| 8 |
+
- id: check-merge-conflict
|
| 9 |
+
- id: check-yaml
|
| 10 |
+
- id: debug-statements
|
| 11 |
+
- id: end-of-file-fixer
|
| 12 |
+
- id: trailing-whitespace
|
| 13 |
+
args: [--markdown-linebreak-ext=md]
|
| 14 |
+
- id: no-commit-to-branch
|
| 15 |
+
args: ['--branch', 'main']
|
| 16 |
+
|
| 17 |
+
- repo: https://github.com/asottile/pyupgrade
|
| 18 |
+
rev: v3.17.0
|
| 19 |
+
hooks:
|
| 20 |
+
- id: pyupgrade
|
| 21 |
+
args: [--py38-plus]
|
| 22 |
+
|
| 23 |
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
| 24 |
+
rev: v0.6.9
|
| 25 |
+
hooks:
|
| 26 |
+
- id: ruff
|
| 27 |
+
args: [--fix]
|
| 28 |
+
- id: ruff-format
|
=0.10.0,
ADDED
|
File without changes
|
CITATION.cff
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cff-version: 1.2.0
|
| 2 |
+
date-released: 2024-03
|
| 3 |
+
message: "If you use this software, please cite it as below."
|
| 4 |
+
authors:
|
| 5 |
+
- family-names: "Zheng"
|
| 6 |
+
given-names: "Yaowei"
|
| 7 |
+
- family-names: "Zhang"
|
| 8 |
+
given-names: "Richong"
|
| 9 |
+
- family-names: "Zhang"
|
| 10 |
+
given-names: "Junhao"
|
| 11 |
+
- family-names: "Ye"
|
| 12 |
+
given-names: "Yanhan"
|
| 13 |
+
- family-names: "Luo"
|
| 14 |
+
given-names: "Zheyan"
|
| 15 |
+
- family-names: "Feng"
|
| 16 |
+
given-names: "Zhangchi"
|
| 17 |
+
- family-names: "Ma"
|
| 18 |
+
given-names: "Yongqiang"
|
| 19 |
+
title: "LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models"
|
| 20 |
+
url: "https://arxiv.org/abs/2403.13372"
|
| 21 |
+
preferred-citation:
|
| 22 |
+
type: conference-paper
|
| 23 |
+
conference:
|
| 24 |
+
name: "Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)"
|
| 25 |
+
authors:
|
| 26 |
+
- family-names: "Zheng"
|
| 27 |
+
given-names: "Yaowei"
|
| 28 |
+
- family-names: "Zhang"
|
| 29 |
+
given-names: "Richong"
|
| 30 |
+
- family-names: "Zhang"
|
| 31 |
+
given-names: "Junhao"
|
| 32 |
+
- family-names: "Ye"
|
| 33 |
+
given-names: "Yanhan"
|
| 34 |
+
- family-names: "Luo"
|
| 35 |
+
given-names: "Zheyan"
|
| 36 |
+
- family-names: "Feng"
|
| 37 |
+
given-names: "Zhangchi"
|
| 38 |
+
- family-names: "Ma"
|
| 39 |
+
given-names: "Yongqiang"
|
| 40 |
+
title: "LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models"
|
| 41 |
+
url: "https://arxiv.org/abs/2403.13372"
|
| 42 |
+
year: 2024
|
| 43 |
+
publisher: "Association for Computational Linguistics"
|
| 44 |
+
address: "Bangkok, Thailand"
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
MANIFEST.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
include LICENSE requirements.txt
|
Makefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.PHONY: build commit license quality style test
|
| 2 |
+
|
| 3 |
+
check_dirs := scripts src tests setup.py
|
| 4 |
+
|
| 5 |
+
build:
|
| 6 |
+
pip3 install build && python3 -m build
|
| 7 |
+
|
| 8 |
+
commit:
|
| 9 |
+
pre-commit install
|
| 10 |
+
pre-commit run --all-files
|
| 11 |
+
|
| 12 |
+
license:
|
| 13 |
+
python3 tests/check_license.py $(check_dirs)
|
| 14 |
+
|
| 15 |
+
quality:
|
| 16 |
+
ruff check $(check_dirs)
|
| 17 |
+
ruff format --check $(check_dirs)
|
| 18 |
+
|
| 19 |
+
style:
|
| 20 |
+
ruff check $(check_dirs) --fix
|
| 21 |
+
ruff format $(check_dirs)
|
| 22 |
+
|
| 23 |
+
test:
|
| 24 |
+
CUDA_VISIBLE_DEVICES= WANDB_DISABLED=true pytest -vv tests/
|
README.md
ADDED
|
@@ -0,0 +1,948 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 2 |
+
|
| 3 |
+
[](https://github.com/hiyouga/LLaMA-Factory/stargazers)
|
| 4 |
+
[](https://github.com/hiyouga/LLaMA-Factory/commits/main)
|
| 5 |
+
[](https://github.com/hiyouga/LLaMA-Factory/graphs/contributors)
|
| 6 |
+
[](https://github.com/hiyouga/LLaMA-Factory/actions/workflows/tests.yml)
|
| 7 |
+
[](https://pypi.org/project/llamafactory/)
|
| 8 |
+
[](https://scholar.google.com/scholar?cites=12620864006390196564)
|
| 9 |
+
[](https://hub.docker.com/r/hiyouga/llamafactory/tags)
|
| 10 |
+
|
| 11 |
+
[](https://twitter.com/llamafactory_ai)
|
| 12 |
+
[](https://discord.gg/rKfvV9r9FK)
|
| 13 |
+
[](https://gitcode.com/zhengyaowei/LLaMA-Factory)
|
| 14 |
+
|
| 15 |
+
[](https://colab.research.google.com/drive/1eRTPn37ltBbYsISy9Aw2NuI2Aq5CQrD9?usp=sharing)
|
| 16 |
+
[](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory)
|
| 17 |
+
[](https://docs.alayanew.com/docs/documents/newActivities/llamafactory/?utm_source=LLaMA-Factory)
|
| 18 |
+
[](https://huggingface.co/spaces/hiyouga/LLaMA-Board)
|
| 19 |
+
[](https://modelscope.cn/studios/hiyouga/LLaMA-Board)
|
| 20 |
+
[](https://novita.ai/templates-library/105981?sharer=88115474-394e-4bda-968e-b88e123d0c47)
|
| 21 |
+
|
| 22 |
+
### Used by [Amazon](https://aws.amazon.com/cn/blogs/machine-learning/how-apoidea-group-enhances-visual-information-extraction-from-banking-documents-with-multimodal-models-using-llama-factory-on-amazon-sagemaker-hyperpod/), [NVIDIA](https://developer.nvidia.com/rtx/ai-toolkit), [Aliyun](https://help.aliyun.com/zh/pai/use-cases/fine-tune-a-llama-3-model-with-llama-factory), etc.
|
| 23 |
+
|
| 24 |
+
<div align="center" markdown="1">
|
| 25 |
+
|
| 26 |
+
### Supporters ❤️
|
| 27 |
+
|
| 28 |
+
<a href="https://warp.dev/llama-factory">
|
| 29 |
+
<img alt="Warp sponsorship" width="400" src="https://github.com/user-attachments/assets/ab8dd143-b0fd-4904-bdc5-dd7ecac94eae">
|
| 30 |
+
</a>
|
| 31 |
+
|
| 32 |
+
#### [Warp, the agentic terminal for developers](https://warp.dev/llama-factory)
|
| 33 |
+
|
| 34 |
+
[Available for MacOS, Linux, & Windows](https://warp.dev/llama-factory)
|
| 35 |
+
|
| 36 |
+
----
|
| 37 |
+
|
| 38 |
+
### Easily fine-tune 100+ large language models with zero-code [CLI](#quickstart) and [Web UI](#fine-tuning-with-llama-board-gui-powered-by-gradio)
|
| 39 |
+
|
| 40 |
+

|
| 41 |
+
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
👋 Join our [WeChat group](assets/wechat.jpg), [NPU user group](assets/wechat_npu.jpg) or [Alaya NeW user group](assets/wechat_alaya.png).
|
| 45 |
+
|
| 46 |
+
\[ English | [中文](README_zh.md) \]
|
| 47 |
+
|
| 48 |
+
**Fine-tuning a large language model can be easy as...**
|
| 49 |
+
|
| 50 |
+
https://github.com/user-attachments/assets/3991a3a8-4276-4d30-9cab-4cb0c4b9b99e
|
| 51 |
+
|
| 52 |
+
Choose your path:
|
| 53 |
+
|
| 54 |
+
- **Documentation (WIP)**: https://llamafactory.readthedocs.io/en/latest/
|
| 55 |
+
- **Documentation (AMD GPU)**: https://rocm.docs.amd.com/projects/ai-developer-hub/en/latest/notebooks/fine_tune/llama_factory_llama3.html
|
| 56 |
+
- **Colab (free)**: https://colab.research.google.com/drive/1eRTPn37ltBbYsISy9Aw2NuI2Aq5CQrD9?usp=sharing
|
| 57 |
+
- **Local machine**: Please refer to [usage](#getting-started)
|
| 58 |
+
- **PAI-DSW (free trial)**: https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory
|
| 59 |
+
- **Alaya NeW (cloud GPU deal)**: https://docs.alayanew.com/docs/documents/useGuide/LLaMAFactory/mutiple/?utm_source=LLaMA-Factory
|
| 60 |
+
|
| 61 |
+
> [!NOTE]
|
| 62 |
+
> Except for the above links, all other websites are unauthorized third-party websites. Please carefully use them.
|
| 63 |
+
|
| 64 |
+
## Table of Contents
|
| 65 |
+
|
| 66 |
+
- [Features](#features)
|
| 67 |
+
- [Blogs](#blogs)
|
| 68 |
+
- [Changelog](#changelog)
|
| 69 |
+
- [Supported Models](#supported-models)
|
| 70 |
+
- [Supported Training Approaches](#supported-training-approaches)
|
| 71 |
+
- [Provided Datasets](#provided-datasets)
|
| 72 |
+
- [Requirement](#requirement)
|
| 73 |
+
- [Getting Started](#getting-started)
|
| 74 |
+
- [Installation](#installation)
|
| 75 |
+
- [Data Preparation](#data-preparation)
|
| 76 |
+
- [Quickstart](#quickstart)
|
| 77 |
+
- [Fine-Tuning with LLaMA Board GUI](#fine-tuning-with-llama-board-gui-powered-by-gradio)
|
| 78 |
+
- [Build Docker](#build-docker)
|
| 79 |
+
- [Deploy with OpenAI-style API and vLLM](#deploy-with-openai-style-api-and-vllm)
|
| 80 |
+
- [Download from ModelScope Hub](#download-from-modelscope-hub)
|
| 81 |
+
- [Download from Modelers Hub](#download-from-modelers-hub)
|
| 82 |
+
- [Use W&B Logger](#use-wb-logger)
|
| 83 |
+
- [Use SwanLab Logger](#use-swanlab-logger)
|
| 84 |
+
- [Projects using LLaMA Factory](#projects-using-llama-factory)
|
| 85 |
+
- [License](#license)
|
| 86 |
+
- [Citation](#citation)
|
| 87 |
+
- [Acknowledgement](#acknowledgement)
|
| 88 |
+
|
| 89 |
+
## Features
|
| 90 |
+
|
| 91 |
+
- **Various models**: LLaMA, LLaVA, Mistral, Mixtral-MoE, Qwen, Qwen2-VL, DeepSeek, Yi, Gemma, ChatGLM, Phi, etc.
|
| 92 |
+
- **Integrated methods**: (Continuous) pre-training, (multimodal) supervised fine-tuning, reward modeling, PPO, DPO, KTO, ORPO, etc.
|
| 93 |
+
- **Scalable resources**: 16-bit full-tuning, freeze-tuning, LoRA and 2/3/4/5/6/8-bit QLoRA via AQLM/AWQ/GPTQ/LLM.int8/HQQ/EETQ.
|
| 94 |
+
- **Advanced algorithms**: [GaLore](https://github.com/jiaweizzhao/GaLore), [BAdam](https://github.com/Ledzy/BAdam), [APOLLO](https://github.com/zhuhanqing/APOLLO), [Adam-mini](https://github.com/zyushun/Adam-mini), [Muon](https://github.com/KellerJordan/Muon), DoRA, LongLoRA, LLaMA Pro, Mixture-of-Depths, LoRA+, LoftQ and PiSSA.
|
| 95 |
+
- **Practical tricks**: [FlashAttention-2](https://github.com/Dao-AILab/flash-attention), [Unsloth](https://github.com/unslothai/unsloth), [Liger Kernel](https://github.com/linkedin/Liger-Kernel), RoPE scaling, NEFTune and rsLoRA.
|
| 96 |
+
- **Wide tasks**: Multi-turn dialogue, tool using, image understanding, visual grounding, video recognition, audio understanding, etc.
|
| 97 |
+
- **Experiment monitors**: LlamaBoard, TensorBoard, Wandb, MLflow, [SwanLab](https://github.com/SwanHubX/SwanLab), etc.
|
| 98 |
+
- **Faster inference**: OpenAI-style API, Gradio UI and CLI with [vLLM worker](https://github.com/vllm-project/vllm) or [SGLang worker](https://github.com/sgl-project/sglang).
|
| 99 |
+
|
| 100 |
+
### Day-N Support for Fine-Tuning Cutting-Edge Models
|
| 101 |
+
|
| 102 |
+
| Support Date | Model Name |
|
| 103 |
+
| ------------ | -------------------------------------------------------------------- |
|
| 104 |
+
| Day 0 | Qwen3 / Qwen2.5-VL / Gemma 3 / GLM-4.1V / InternLM 3 / MiniCPM-o-2.6 |
|
| 105 |
+
| Day 1 | Llama 3 / GLM-4 / Mistral Small / PaliGemma2 / Llama 4 |
|
| 106 |
+
|
| 107 |
+
## Blogs
|
| 108 |
+
|
| 109 |
+
- [A One-Stop Code-Free Model Reinforcement Learning and Deployment Platform based on LLaMA-Factory and EasyR1](https://aws.amazon.com/cn/blogs/china/building-llm-model-hub-based-on-llamafactory-and-easyr1/) (Chinese)
|
| 110 |
+
- [Fine-tune Qwen2.5-VL for Autonomous Driving using LLaMA-Factory](https://docs.alayanew.com/docs/documents/useGuide/LLaMAFactory/mutiple/?utm_source=LLaMA-Factory) (Chinese)
|
| 111 |
+
- [How Apoidea Group enhances visual information extraction from banking documents with multimodal models using LLaMA-Factory on Amazon SageMaker HyperPod](https://aws.amazon.com/cn/blogs/machine-learning/how-apoidea-group-enhances-visual-information-extraction-from-banking-documents-with-multimodal-models-using-llama-factory-on-amazon-sagemaker-hyperpod/) (English)
|
| 112 |
+
- [Easy Dataset × LLaMA Factory: Enabling LLMs to Efficiently Learn Domain Knowledge](https://buaa-act.feishu.cn/wiki/GVzlwYcRFiR8OLkHbL6cQpYin7g) (English)
|
| 113 |
+
|
| 114 |
+
<details><summary>All Blogs</summary>
|
| 115 |
+
|
| 116 |
+
- [LLaMA Factory: Fine-tuning the DeepSeek-R1-Distill-Qwen-7B Model for News Classifier](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory_deepseek_r1_distill_7b) (Chinese)
|
| 117 |
+
- [A One-Stop Code-Free Model Fine-Tuning \& Deployment Platform based on SageMaker and LLaMA-Factory](https://aws.amazon.com/cn/blogs/china/a-one-stop-code-free-model-fine-tuning-deployment-platform-based-on-sagemaker-and-llama-factory/) (Chinese)
|
| 118 |
+
- [LLaMA Factory Multi-Modal Fine-Tuning Practice: Fine-Tuning Qwen2-VL for Personal Tourist Guide](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory_qwen2vl) (Chinese)
|
| 119 |
+
- [LLaMA Factory: Fine-tuning the LLaMA3 Model for Role-Playing](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory) (Chinese)
|
| 120 |
+
|
| 121 |
+
</details>
|
| 122 |
+
|
| 123 |
+
## Changelog
|
| 124 |
+
|
| 125 |
+
[25/07/02] We supported fine-tuning the **[GLM-4.1V-9B-Thinking](https://github.com/THUDM/GLM-4.1V-Thinking)** model. Please install transformers from **main** branch to use.
|
| 126 |
+
|
| 127 |
+
[25/04/28] We supported fine-tuning the **[Qwen3](https://qwenlm.github.io/blog/qwen3/)** model family.
|
| 128 |
+
|
| 129 |
+
[25/04/21] We supported the **[Muon](https://github.com/KellerJordan/Muon)** optimizer. See [examples](examples/README.md) for usage. Thank [@tianshijing](https://github.com/tianshijing)'s PR.
|
| 130 |
+
|
| 131 |
+
[25/04/16] We supported fine-tuning the **[InternVL3](https://huggingface.co/OpenGVLab/InternVL3-8B)** model. See [PR #7258](https://github.com/hiyouga/LLaMA-Factory/pull/7258) to get started.
|
| 132 |
+
|
| 133 |
+
[25/04/14] We supported fine-tuning the **[GLM-Z1](https://huggingface.co/THUDM/GLM-Z1-9B-0414)** and **[Kimi-VL](https://huggingface.co/moonshotai/Kimi-VL-A3B-Instruct)** models.
|
| 134 |
+
|
| 135 |
+
[25/04/06] We supported fine-tuning the **[Llama 4](https://ai.meta.com/blog/llama-4-multimodal-intelligence/)** model. See [PR #7611](https://github.com/hiyouga/LLaMA-Factory/pull/7611) to get started.
|
| 136 |
+
|
| 137 |
+
<details><summary>Full Changelog</summary>
|
| 138 |
+
|
| 139 |
+
[25/03/31] We supported fine-tuning the **[Qwen2.5 Omni](https://qwenlm.github.io/blog/qwen2.5-omni/)** model. See [PR #7537](https://github.com/hiyouga/LLaMA-Factory/pull/7537) to get started.
|
| 140 |
+
|
| 141 |
+
[25/03/15] We supported **[SGLang](https://github.com/sgl-project/sglang)** as inference backend. Try `infer_backend: sglang` to accelerate inference.
|
| 142 |
+
|
| 143 |
+
[25/03/12] We supported fine-tuning the **[Gemma 3](https://huggingface.co/blog/gemma3)** model.
|
| 144 |
+
|
| 145 |
+
[25/02/24] Announcing **[EasyR1](https://github.com/hiyouga/EasyR1)**, an efficient, scalable and multi-modality RL training framework for efficient GRPO training.
|
| 146 |
+
|
| 147 |
+
[25/02/11] We supported saving the **[Ollama](https://github.com/ollama/ollama)** modelfile when exporting the model checkpoints. See [examples](examples/README.md) for usage.
|
| 148 |
+
|
| 149 |
+
[25/02/05] We supported fine-tuning the **[Qwen2-Audio](Qwen/Qwen2-Audio-7B-Instruct)** and **[MiniCPM-o-2.6](https://huggingface.co/openbmb/MiniCPM-o-2_6)** on audio understanding tasks.
|
| 150 |
+
|
| 151 |
+
[25/01/31] We supported fine-tuning the **[DeepSeek-R1](https://huggingface.co/deepseek-ai/DeepSeek-R1)** and **[Qwen2.5-VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)** models.
|
| 152 |
+
|
| 153 |
+
[25/01/15] We supported **[APOLLO](https://arxiv.org/abs/2412.05270)** optimizer. See [examples](examples/README.md) for usage.
|
| 154 |
+
|
| 155 |
+
[25/01/14] We supported fine-tuning the **[MiniCPM-o-2.6](https://huggingface.co/openbmb/MiniCPM-o-2_6)** and **[MiniCPM-V-2.6](https://huggingface.co/openbmb/MiniCPM-V-2_6)** models. Thank [@BUAADreamer](https://github.com/BUAADreamer)'s PR.
|
| 156 |
+
|
| 157 |
+
[25/01/14] We supported fine-tuning the **[InternLM 3](https://huggingface.co/collections/internlm/)** models. Thank [@hhaAndroid](https://github.com/hhaAndroid)'s PR.
|
| 158 |
+
|
| 159 |
+
[25/01/10] We supported fine-tuning the **[Phi-4](https://huggingface.co/microsoft/phi-4)** model.
|
| 160 |
+
|
| 161 |
+
[24/12/21] We supported using **[SwanLab](https://github.com/SwanHubX/SwanLab)** for experiment tracking and visualization. See [this section](#use-swanlab-logger) for details.
|
| 162 |
+
|
| 163 |
+
[24/11/27] We supported fine-tuning the **[Skywork-o1](https://huggingface.co/Skywork/Skywork-o1-Open-Llama-3.1-8B)** model and the **[OpenO1](https://huggingface.co/datasets/O1-OPEN/OpenO1-SFT)** dataset.
|
| 164 |
+
|
| 165 |
+
[24/10/09] We supported downloading pre-trained models and datasets from the **[Modelers Hub](https://modelers.cn/models)**. See [this tutorial](#download-from-modelers-hub) for usage.
|
| 166 |
+
|
| 167 |
+
[24/09/19] We supported fine-tuning the **[Qwen2.5](https://qwenlm.github.io/blog/qwen2.5/)** models.
|
| 168 |
+
|
| 169 |
+
[24/08/30] We supported fine-tuning the **[Qwen2-VL](https://qwenlm.github.io/blog/qwen2-vl/)** models. Thank [@simonJJJ](https://github.com/simonJJJ)'s PR.
|
| 170 |
+
|
| 171 |
+
[24/08/27] We supported **[Liger Kernel](https://github.com/linkedin/Liger-Kernel)**. Try `enable_liger_kernel: true` for efficient training.
|
| 172 |
+
|
| 173 |
+
[24/08/09] We supported **[Adam-mini](https://github.com/zyushun/Adam-mini)** optimizer. See [examples](examples/README.md) for usage. Thank [@relic-yuexi](https://github.com/relic-yuexi)'s PR.
|
| 174 |
+
|
| 175 |
+
[24/07/04] We supported [contamination-free packed training](https://github.com/MeetKai/functionary/tree/main/functionary/train/packing). Use `neat_packing: true` to activate it. Thank [@chuan298](https://github.com/chuan298)'s PR.
|
| 176 |
+
|
| 177 |
+
[24/06/16] We supported **[PiSSA](https://arxiv.org/abs/2404.02948)** algorithm. See [examples](examples/README.md) for usage.
|
| 178 |
+
|
| 179 |
+
[24/06/07] We supported fine-tuning the **[Qwen2](https://qwenlm.github.io/blog/qwen2/)** and **[GLM-4](https://github.com/THUDM/GLM-4)** models.
|
| 180 |
+
|
| 181 |
+
[24/05/26] We supported **[SimPO](https://arxiv.org/abs/2405.14734)** algorithm for preference learning. See [examples](examples/README.md) for usage.
|
| 182 |
+
|
| 183 |
+
[24/05/20] We supported fine-tuning the **PaliGemma** series models. Note that the PaliGemma models are pre-trained models, you need to fine-tune them with `paligemma` template for chat completion.
|
| 184 |
+
|
| 185 |
+
[24/05/18] We supported **[KTO](https://arxiv.org/abs/2402.01306)** algorithm for preference learning. See [examples](examples/README.md) for usage.
|
| 186 |
+
|
| 187 |
+
[24/05/14] We supported training and inference on the Ascend NPU devices. Check [installation](#installation) section for details.
|
| 188 |
+
|
| 189 |
+
[24/04/26] We supported fine-tuning the **LLaVA-1.5** multimodal LLMs. See [examples](examples/README.md) for usage.
|
| 190 |
+
|
| 191 |
+
[24/04/22] We provided a **[Colab notebook](https://colab.research.google.com/drive/1eRTPn37ltBbYsISy9Aw2NuI2Aq5CQrD9?usp=sharing)** for fine-tuning the Llama-3 model on a free T4 GPU. Two Llama-3-derived models fine-tuned using LLaMA Factory are available at Hugging Face, check [Llama3-8B-Chinese-Chat](https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat) and [Llama3-Chinese](https://huggingface.co/zhichen/Llama3-Chinese) for details.
|
| 192 |
+
|
| 193 |
+
[24/04/21] We supported **[Mixture-of-Depths](https://arxiv.org/abs/2404.02258)** according to [AstraMindAI's implementation](https://github.com/astramind-ai/Mixture-of-depths). See [examples](examples/README.md) for usage.
|
| 194 |
+
|
| 195 |
+
[24/04/16] We supported **[BAdam](https://arxiv.org/abs/2404.02827)** optimizer. See [examples](examples/README.md) for usage.
|
| 196 |
+
|
| 197 |
+
[24/04/16] We supported **[unsloth](https://github.com/unslothai/unsloth)**'s long-sequence training (Llama-2-7B-56k within 24GB). It achieves **117%** speed and **50%** memory compared with FlashAttention-2, more benchmarks can be found in [this page](https://github.com/hiyouga/LLaMA-Factory/wiki/Performance-comparison).
|
| 198 |
+
|
| 199 |
+
[24/03/31] We supported **[ORPO](https://arxiv.org/abs/2403.07691)**. See [examples](examples/README.md) for usage.
|
| 200 |
+
|
| 201 |
+
[24/03/21] Our paper "[LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models](https://arxiv.org/abs/2403.13372)" is available at arXiv!
|
| 202 |
+
|
| 203 |
+
[24/03/20] We supported **FSDP+QLoRA** that fine-tunes a 70B model on 2x24GB GPUs. See [examples](examples/README.md) for usage.
|
| 204 |
+
|
| 205 |
+
[24/03/13] We supported **[LoRA+](https://arxiv.org/abs/2402.12354)**. See [examples](examples/README.md) for usage.
|
| 206 |
+
|
| 207 |
+
[24/03/07] We supported **[GaLore](https://arxiv.org/abs/2403.03507)** optimizer. See [examples](examples/README.md) for usage.
|
| 208 |
+
|
| 209 |
+
[24/03/07] We integrated **[vLLM](https://github.com/vllm-project/vllm)** for faster and concurrent inference. Try `infer_backend: vllm` to enjoy **270%** inference speed.
|
| 210 |
+
|
| 211 |
+
[24/02/28] We supported weight-decomposed LoRA (**[DoRA](https://arxiv.org/abs/2402.09353)**). Try `use_dora: true` to activate DoRA training.
|
| 212 |
+
|
| 213 |
+
[24/02/15] We supported **block expansion** proposed by [LLaMA Pro](https://github.com/TencentARC/LLaMA-Pro). See [examples](examples/README.md) for usage.
|
| 214 |
+
|
| 215 |
+
[24/02/05] Qwen1.5 (Qwen2 beta version) series models are supported in LLaMA-Factory. Check this [blog post](https://qwenlm.github.io/blog/qwen1.5/) for details.
|
| 216 |
+
|
| 217 |
+
[24/01/18] We supported **agent tuning** for most models, equipping model with tool using abilities by fine-tuning with `dataset: glaive_toolcall_en`.
|
| 218 |
+
|
| 219 |
+
[23/12/23] We supported **[unsloth](https://github.com/unslothai/unsloth)**'s implementation to boost LoRA tuning for the LLaMA, Mistral and Yi models. Try `use_unsloth: true` argument to activate unsloth patch. It achieves **170%** speed in our benchmark, check [this page](https://github.com/hiyouga/LLaMA-Factory/wiki/Performance-comparison) for details.
|
| 220 |
+
|
| 221 |
+
[23/12/12] We supported fine-tuning the latest MoE model **[Mixtral 8x7B](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1)** in our framework. See hardware requirement [here](#hardware-requirement).
|
| 222 |
+
|
| 223 |
+
[23/12/01] We supported downloading pre-trained models and datasets from the **[ModelScope Hub](https://modelscope.cn/models)**. See [this tutorial](#download-from-modelscope-hub) for usage.
|
| 224 |
+
|
| 225 |
+
[23/10/21] We supported **[NEFTune](https://arxiv.org/abs/2310.05914)** trick for fine-tuning. Try `neftune_noise_alpha: 5` argument to activate NEFTune.
|
| 226 |
+
|
| 227 |
+
[23/09/27] We supported **$S^2$-Attn** proposed by [LongLoRA](https://github.com/dvlab-research/LongLoRA) for the LLaMA models. Try `shift_attn: true` argument to enable shift short attention.
|
| 228 |
+
|
| 229 |
+
[23/09/23] We integrated MMLU, C-Eval and CMMLU benchmarks in this repo. See [examples](examples/README.md) for usage.
|
| 230 |
+
|
| 231 |
+
[23/09/10] We supported **[FlashAttention-2](https://github.com/Dao-AILab/flash-attention)**. Try `flash_attn: fa2` argument to enable FlashAttention-2 if you are using RTX4090, A100 or H100 GPUs.
|
| 232 |
+
|
| 233 |
+
[23/08/12] We supported **RoPE scaling** to extend the context length of the LLaMA models. Try `rope_scaling: linear` argument in training and `rope_scaling: dynamic` argument at inference to extrapolate the position embeddings.
|
| 234 |
+
|
| 235 |
+
[23/08/11] We supported **[DPO training](https://arxiv.org/abs/2305.18290)** for instruction-tuned models. See [examples](examples/README.md) for usage.
|
| 236 |
+
|
| 237 |
+
[23/07/31] We supported **dataset streaming**. Try `streaming: true` and `max_steps: 10000` arguments to load your dataset in streaming mode.
|
| 238 |
+
|
| 239 |
+
[23/07/29] We released two instruction-tuned 13B models at Hugging Face. See these Hugging Face Repos ([LLaMA-2](https://huggingface.co/hiyouga/Llama-2-Chinese-13b-chat) / [Baichuan](https://huggingface.co/hiyouga/Baichuan-13B-sft)) for details.
|
| 240 |
+
|
| 241 |
+
[23/07/18] We developed an **all-in-one Web UI** for training, evaluation and inference. Try `train_web.py` to fine-tune models in your Web browser. Thank [@KanadeSiina](https://github.com/KanadeSiina) and [@codemayq](https://github.com/codemayq) for their efforts in the development.
|
| 242 |
+
|
| 243 |
+
[23/07/09] We released **[FastEdit](https://github.com/hiyouga/FastEdit)** ⚡🩹, an easy-to-use package for editing the factual knowledge of large language models efficiently. Please follow [FastEdit](https://github.com/hiyouga/FastEdit) if you are interested.
|
| 244 |
+
|
| 245 |
+
[23/06/29] We provided a **reproducible example** of training a chat model using instruction-following datasets, see [Baichuan-7B-sft](https://huggingface.co/hiyouga/Baichuan-7B-sft) for details.
|
| 246 |
+
|
| 247 |
+
[23/06/22] We aligned the [demo API](src/api_demo.py) with the [OpenAI's](https://platform.openai.com/docs/api-reference/chat) format where you can insert the fine-tuned model in **arbitrary ChatGPT-based applications**.
|
| 248 |
+
|
| 249 |
+
[23/06/03] We supported quantized training and inference (aka **[QLoRA](https://github.com/artidoro/qlora)**). See [examples](examples/README.md) for usage.
|
| 250 |
+
|
| 251 |
+
</details>
|
| 252 |
+
|
| 253 |
+
> [!TIP]
|
| 254 |
+
> If you cannot use the latest feature, please pull the latest code and install LLaMA-Factory again.
|
| 255 |
+
|
| 256 |
+
## Supported Models
|
| 257 |
+
|
| 258 |
+
| Model | Model size | Template |
|
| 259 |
+
| ----------------------------------------------------------------- | -------------------------------- | ------------------- |
|
| 260 |
+
| [Baichuan 2](https://huggingface.co/baichuan-inc) | 7B/13B | baichuan2 |
|
| 261 |
+
| [BLOOM/BLOOMZ](https://huggingface.co/bigscience) | 560M/1.1B/1.7B/3B/7.1B/176B | - |
|
| 262 |
+
| [ChatGLM3](https://huggingface.co/THUDM) | 6B | chatglm3 |
|
| 263 |
+
| [Command R](https://huggingface.co/CohereForAI) | 35B/104B | cohere |
|
| 264 |
+
| [DeepSeek (Code/MoE)](https://huggingface.co/deepseek-ai) | 7B/16B/67B/236B | deepseek |
|
| 265 |
+
| [DeepSeek 2.5/3](https://huggingface.co/deepseek-ai) | 236B/671B | deepseek3 |
|
| 266 |
+
| [DeepSeek R1 (Distill)](https://huggingface.co/deepseek-ai) | 1.5B/7B/8B/14B/32B/70B/671B | deepseekr1 |
|
| 267 |
+
| [Falcon](https://huggingface.co/tiiuae) | 7B/11B/40B/180B | falcon |
|
| 268 |
+
| [Falcon-H1](https://huggingface.co/tiiuae) | 0.5B/1.5B/3B/7B/34B | falcon_h1 |
|
| 269 |
+
| [Gemma/Gemma 2/CodeGemma](https://huggingface.co/google) | 2B/7B/9B/27B | gemma/gemma2 |
|
| 270 |
+
| [Gemma 3/Gemma 3n](https://huggingface.co/google) | 1B/4B/6B/8B/12B/27B | gemma3/gemma3n |
|
| 271 |
+
| [GLM-4/GLM-4-0414/GLM-Z1](https://huggingface.co/THUDM) | 9B/32B | glm4/glmz1 |
|
| 272 |
+
| [GLM-4.1V](https://huggingface.co/THUDM)* | 9B | glm4v |
|
| 273 |
+
| [GPT-2](https://huggingface.co/openai-community) | 0.1B/0.4B/0.8B/1.5B | - |
|
| 274 |
+
| [Granite 3.0-3.3](https://huggingface.co/ibm-granite) | 1B/2B/3B/8B | granite3 |
|
| 275 |
+
| [Hunyuan](https://huggingface.co/tencent/) | 7B | hunyuan |
|
| 276 |
+
| [Index](https://huggingface.co/IndexTeam) | 1.9B | index |
|
| 277 |
+
| [InternLM 2-3](https://huggingface.co/internlm) | 7B/8B/20B | intern2 |
|
| 278 |
+
| [InternVL 2.5-3](https://huggingface.co/OpenGVLab) | 1B/2B/8B/14B/38B/78B | intern_vl |
|
| 279 |
+
| [Kimi-VL](https://huggingface.co/moonshotai) | 16B | kimi_vl |
|
| 280 |
+
| [Llama](https://github.com/facebookresearch/llama) | 7B/13B/33B/65B | - |
|
| 281 |
+
| [Llama 2](https://huggingface.co/meta-llama) | 7B/13B/70B | llama2 |
|
| 282 |
+
| [Llama 3-3.3](https://huggingface.co/meta-llama) | 1B/3B/8B/70B | llama3 |
|
| 283 |
+
| [Llama 4](https://huggingface.co/meta-llama) | 109B/402B | llama4 |
|
| 284 |
+
| [Llama 3.2 Vision](https://huggingface.co/meta-llama) | 11B/90B | mllama |
|
| 285 |
+
| [LLaVA-1.5](https://huggingface.co/llava-hf) | 7B/13B | llava |
|
| 286 |
+
| [LLaVA-NeXT](https://huggingface.co/llava-hf) | 7B/8B/13B/34B/72B/110B | llava_next |
|
| 287 |
+
| [LLaVA-NeXT-Video](https://huggingface.co/llava-hf) | 7B/34B | llava_next_video |
|
| 288 |
+
| [MiMo](https://huggingface.co/XiaomiMiMo) | 7B | mimo |
|
| 289 |
+
| [MiniCPM](https://huggingface.co/openbmb) | 0.5B/1B/2B/4B/8B | cpm/cpm3/cpm4 |
|
| 290 |
+
| [MiniCPM-o-2.6/MiniCPM-V-2.6](https://huggingface.co/openbmb) | 8B | minicpm_o/minicpm_v |
|
| 291 |
+
| [Ministral/Mistral-Nemo](https://huggingface.co/mistralai) | 8B/12B | ministral |
|
| 292 |
+
| [Mistral/Mixtral](https://huggingface.co/mistralai) | 7B/8x7B/8x22B | mistral |
|
| 293 |
+
| [Mistral Small](https://huggingface.co/mistralai) | 24B | mistral_small |
|
| 294 |
+
| [OLMo](https://huggingface.co/allenai) | 1B/7B | - |
|
| 295 |
+
| [PaliGemma/PaliGemma2](https://huggingface.co/google) | 3B/10B/28B | paligemma |
|
| 296 |
+
| [Phi-1.5/Phi-2](https://huggingface.co/microsoft) | 1.3B/2.7B | - |
|
| 297 |
+
| [Phi-3/Phi-3.5](https://huggingface.co/microsoft) | 4B/14B | phi |
|
| 298 |
+
| [Phi-3-small](https://huggingface.co/microsoft) | 7B | phi_small |
|
| 299 |
+
| [Phi-4](https://huggingface.co/microsoft) | 14B | phi4 |
|
| 300 |
+
| [Pixtral](https://huggingface.co/mistralai) | 12B | pixtral |
|
| 301 |
+
| [Qwen (1-2.5) (Code/Math/MoE/QwQ)](https://huggingface.co/Qwen) | 0.5B/1.5B/3B/7B/14B/32B/72B/110B | qwen |
|
| 302 |
+
| [Qwen3 (MoE)](https://huggingface.co/Qwen) | 0.6B/1.7B/4B/8B/14B/32B/235B | qwen3 |
|
| 303 |
+
| [Qwen2-Audio](https://huggingface.co/Qwen) | 7B | qwen2_audio |
|
| 304 |
+
| [Qwen2.5-Omni](https://huggingface.co/Qwen) | 3B/7B | qwen2_omni |
|
| 305 |
+
| [Qwen2-VL/Qwen2.5-VL/QVQ](https://huggingface.co/Qwen) | 2B/3B/7B/32B/72B | qwen2_vl |
|
| 306 |
+
| [Seed Coder](https://huggingface.co/ByteDance-Seed) | 8B | seed_coder |
|
| 307 |
+
| [Skywork o1](https://huggingface.co/Skywork) | 8B | skywork_o1 |
|
| 308 |
+
| [StarCoder 2](https://huggingface.co/bigcode) | 3B/7B/15B | - |
|
| 309 |
+
| [TeleChat2](https://huggingface.co/Tele-AI) | 3B/7B/35B/115B | telechat2 |
|
| 310 |
+
| [XVERSE](https://huggingface.co/xverse) | 7B/13B/65B | xverse |
|
| 311 |
+
| [Yi/Yi-1.5 (Code)](https://huggingface.co/01-ai) | 1.5B/6B/9B/34B | yi |
|
| 312 |
+
| [Yi-VL](https://huggingface.co/01-ai) | 6B/34B | yi_vl |
|
| 313 |
+
| [Yuan 2](https://huggingface.co/IEITYuan) | 2B/51B/102B | yuan |
|
| 314 |
+
|
| 315 |
+
> [!NOTE]
|
| 316 |
+
> For the "base" models, the `template` argument can be chosen from `default`, `alpaca`, `vicuna` etc. But make sure to use the **corresponding template** for the "instruct/chat" models.
|
| 317 |
+
>
|
| 318 |
+
> Remember to use the **SAME** template in training and inference.
|
| 319 |
+
>
|
| 320 |
+
> \*: You should install the `transformers` from main branch and use `DISABLE_VERSION_CHECK=1` to skip version check.
|
| 321 |
+
>
|
| 322 |
+
> \*\*: You need to install a specific version of `transformers` to use the corresponding model.
|
| 323 |
+
|
| 324 |
+
Please refer to [constants.py](src/llamafactory/extras/constants.py) for a full list of models we supported.
|
| 325 |
+
|
| 326 |
+
You also can add a custom chat template to [template.py](src/llamafactory/data/template.py).
|
| 327 |
+
|
| 328 |
+
## Supported Training Approaches
|
| 329 |
+
|
| 330 |
+
| Approach | Full-tuning | Freeze-tuning | LoRA | QLoRA |
|
| 331 |
+
| ---------------------- | ------------------ | ------------------ | ------------------ | ------------------ |
|
| 332 |
+
| Pre-Training | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 333 |
+
| Supervised Fine-Tuning | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 334 |
+
| Reward Modeling | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 335 |
+
| PPO Training | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 336 |
+
| DPO Training | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 337 |
+
| KTO Training | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 338 |
+
| ORPO Training | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 339 |
+
| SimPO Training | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 340 |
+
|
| 341 |
+
> [!TIP]
|
| 342 |
+
> The implementation details of PPO can be found in [this blog](https://newfacade.github.io/notes-on-reinforcement-learning/17-ppo-trl.html).
|
| 343 |
+
|
| 344 |
+
## Provided Datasets
|
| 345 |
+
|
| 346 |
+
<details><summary>Pre-training datasets</summary>
|
| 347 |
+
|
| 348 |
+
- [Wiki Demo (en)](data/wiki_demo.txt)
|
| 349 |
+
- [RefinedWeb (en)](https://huggingface.co/datasets/tiiuae/falcon-refinedweb)
|
| 350 |
+
- [RedPajama V2 (en)](https://huggingface.co/datasets/togethercomputer/RedPajama-Data-V2)
|
| 351 |
+
- [Wikipedia (en)](https://huggingface.co/datasets/olm/olm-wikipedia-20221220)
|
| 352 |
+
- [Wikipedia (zh)](https://huggingface.co/datasets/pleisto/wikipedia-cn-20230720-filtered)
|
| 353 |
+
- [Pile (en)](https://huggingface.co/datasets/EleutherAI/pile)
|
| 354 |
+
- [SkyPile (zh)](https://huggingface.co/datasets/Skywork/SkyPile-150B)
|
| 355 |
+
- [FineWeb (en)](https://huggingface.co/datasets/HuggingFaceFW/fineweb)
|
| 356 |
+
- [FineWeb-Edu (en)](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu)
|
| 357 |
+
- [The Stack (en)](https://huggingface.co/datasets/bigcode/the-stack)
|
| 358 |
+
- [StarCoder (en)](https://huggingface.co/datasets/bigcode/starcoderdata)
|
| 359 |
+
|
| 360 |
+
</details>
|
| 361 |
+
|
| 362 |
+
<details><summary>Supervised fine-tuning datasets</summary>
|
| 363 |
+
|
| 364 |
+
- [Identity (en&zh)](data/identity.json)
|
| 365 |
+
- [Stanford Alpaca (en)](https://github.com/tatsu-lab/stanford_alpaca)
|
| 366 |
+
- [Stanford Alpaca (zh)](https://github.com/ymcui/Chinese-LLaMA-Alpaca-3)
|
| 367 |
+
- [Alpaca GPT4 (en&zh)](https://github.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM)
|
| 368 |
+
- [Glaive Function Calling V2 (en&zh)](https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2)
|
| 369 |
+
- [LIMA (en)](https://huggingface.co/datasets/GAIR/lima)
|
| 370 |
+
- [Guanaco Dataset (multilingual)](https://huggingface.co/datasets/JosephusCheung/GuanacoDataset)
|
| 371 |
+
- [BELLE 2M (zh)](https://huggingface.co/datasets/BelleGroup/train_2M_CN)
|
| 372 |
+
- [BELLE 1M (zh)](https://huggingface.co/datasets/BelleGroup/train_1M_CN)
|
| 373 |
+
- [BELLE 0.5M (zh)](https://huggingface.co/datasets/BelleGroup/train_0.5M_CN)
|
| 374 |
+
- [BELLE Dialogue 0.4M (zh)](https://huggingface.co/datasets/BelleGroup/generated_chat_0.4M)
|
| 375 |
+
- [BELLE School Math 0.25M (zh)](https://huggingface.co/datasets/BelleGroup/school_math_0.25M)
|
| 376 |
+
- [BELLE Multiturn Chat 0.8M (zh)](https://huggingface.co/datasets/BelleGroup/multiturn_chat_0.8M)
|
| 377 |
+
- [UltraChat (en)](https://github.com/thunlp/UltraChat)
|
| 378 |
+
- [OpenPlatypus (en)](https://huggingface.co/datasets/garage-bAInd/Open-Platypus)
|
| 379 |
+
- [CodeAlpaca 20k (en)](https://huggingface.co/datasets/sahil2801/CodeAlpaca-20k)
|
| 380 |
+
- [Alpaca CoT (multilingual)](https://huggingface.co/datasets/QingyiSi/Alpaca-CoT)
|
| 381 |
+
- [OpenOrca (en)](https://huggingface.co/datasets/Open-Orca/OpenOrca)
|
| 382 |
+
- [SlimOrca (en)](https://huggingface.co/datasets/Open-Orca/SlimOrca)
|
| 383 |
+
- [MathInstruct (en)](https://huggingface.co/datasets/TIGER-Lab/MathInstruct)
|
| 384 |
+
- [Firefly 1.1M (zh)](https://huggingface.co/datasets/YeungNLP/firefly-train-1.1M)
|
| 385 |
+
- [Wiki QA (en)](https://huggingface.co/datasets/wiki_qa)
|
| 386 |
+
- [Web QA (zh)](https://huggingface.co/datasets/suolyer/webqa)
|
| 387 |
+
- [WebNovel (zh)](https://huggingface.co/datasets/zxbsmk/webnovel_cn)
|
| 388 |
+
- [Nectar (en)](https://huggingface.co/datasets/berkeley-nest/Nectar)
|
| 389 |
+
- [deepctrl (en&zh)](https://www.modelscope.cn/datasets/deepctrl/deepctrl-sft-data)
|
| 390 |
+
- [Advertise Generating (zh)](https://huggingface.co/datasets/HasturOfficial/adgen)
|
| 391 |
+
- [ShareGPT Hyperfiltered (en)](https://huggingface.co/datasets/totally-not-an-llm/sharegpt-hyperfiltered-3k)
|
| 392 |
+
- [ShareGPT4 (en&zh)](https://huggingface.co/datasets/shibing624/sharegpt_gpt4)
|
| 393 |
+
- [UltraChat 200k (en)](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k)
|
| 394 |
+
- [AgentInstruct (en)](https://huggingface.co/datasets/THUDM/AgentInstruct)
|
| 395 |
+
- [LMSYS Chat 1M (en)](https://huggingface.co/datasets/lmsys/lmsys-chat-1m)
|
| 396 |
+
- [Evol Instruct V2 (en)](https://huggingface.co/datasets/WizardLM/WizardLM_evol_instruct_V2_196k)
|
| 397 |
+
- [Cosmopedia (en)](https://huggingface.co/datasets/HuggingFaceTB/cosmopedia)
|
| 398 |
+
- [STEM (zh)](https://huggingface.co/datasets/hfl/stem_zh_instruction)
|
| 399 |
+
- [Ruozhiba (zh)](https://huggingface.co/datasets/hfl/ruozhiba_gpt4_turbo)
|
| 400 |
+
- [Neo-sft (zh)](https://huggingface.co/datasets/m-a-p/neo_sft_phase2)
|
| 401 |
+
- [Magpie-Pro-300K-Filtered (en)](https://huggingface.co/datasets/Magpie-Align/Magpie-Pro-300K-Filtered)
|
| 402 |
+
- [Magpie-ultra-v0.1 (en)](https://huggingface.co/datasets/argilla/magpie-ultra-v0.1)
|
| 403 |
+
- [WebInstructSub (en)](https://huggingface.co/datasets/TIGER-Lab/WebInstructSub)
|
| 404 |
+
- [OpenO1-SFT (en&zh)](https://huggingface.co/datasets/O1-OPEN/OpenO1-SFT)
|
| 405 |
+
- [Open-Thoughts (en)](https://huggingface.co/datasets/open-thoughts/OpenThoughts-114k)
|
| 406 |
+
- [Open-R1-Math (en)](https://huggingface.co/datasets/open-r1/OpenR1-Math-220k)
|
| 407 |
+
- [Chinese-DeepSeek-R1-Distill (zh)](https://huggingface.co/datasets/Congliu/Chinese-DeepSeek-R1-Distill-data-110k-SFT)
|
| 408 |
+
- [LLaVA mixed (en&zh)](https://huggingface.co/datasets/BUAADreamer/llava-en-zh-300k)
|
| 409 |
+
- [Pokemon-gpt4o-captions (en&zh)](https://huggingface.co/datasets/jugg1024/pokemon-gpt4o-captions)
|
| 410 |
+
- [Open Assistant (de)](https://huggingface.co/datasets/mayflowergmbh/oasst_de)
|
| 411 |
+
- [Dolly 15k (de)](https://huggingface.co/datasets/mayflowergmbh/dolly-15k_de)
|
| 412 |
+
- [Alpaca GPT4 (de)](https://huggingface.co/datasets/mayflowergmbh/alpaca-gpt4_de)
|
| 413 |
+
- [OpenSchnabeltier (de)](https://huggingface.co/datasets/mayflowergmbh/openschnabeltier_de)
|
| 414 |
+
- [Evol Instruct (de)](https://huggingface.co/datasets/mayflowergmbh/evol-instruct_de)
|
| 415 |
+
- [Dolphin (de)](https://huggingface.co/datasets/mayflowergmbh/dolphin_de)
|
| 416 |
+
- [Booksum (de)](https://huggingface.co/datasets/mayflowergmbh/booksum_de)
|
| 417 |
+
- [Airoboros (de)](https://huggingface.co/datasets/mayflowergmbh/airoboros-3.0_de)
|
| 418 |
+
- [Ultrachat (de)](https://huggingface.co/datasets/mayflowergmbh/ultra-chat_de)
|
| 419 |
+
|
| 420 |
+
</details>
|
| 421 |
+
|
| 422 |
+
<details><summary>Preference datasets</summary>
|
| 423 |
+
|
| 424 |
+
- [DPO mixed (en&zh)](https://huggingface.co/datasets/hiyouga/DPO-En-Zh-20k)
|
| 425 |
+
- [UltraFeedback (en)](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized)
|
| 426 |
+
- [COIG-P (zh)](https://huggingface.co/datasets/m-a-p/COIG-P)
|
| 427 |
+
- [RLHF-V (en)](https://huggingface.co/datasets/openbmb/RLHF-V-Dataset)
|
| 428 |
+
- [VLFeedback (en)](https://huggingface.co/datasets/Zhihui/VLFeedback)
|
| 429 |
+
- [RLAIF-V (en)](https://huggingface.co/datasets/openbmb/RLAIF-V-Dataset)
|
| 430 |
+
- [Orca DPO Pairs (en)](https://huggingface.co/datasets/Intel/orca_dpo_pairs)
|
| 431 |
+
- [HH-RLHF (en)](https://huggingface.co/datasets/Anthropic/hh-rlhf)
|
| 432 |
+
- [Nectar (en)](https://huggingface.co/datasets/berkeley-nest/Nectar)
|
| 433 |
+
- [Orca DPO (de)](https://huggingface.co/datasets/mayflowergmbh/intel_orca_dpo_pairs_de)
|
| 434 |
+
- [KTO mixed (en)](https://huggingface.co/datasets/argilla/kto-mix-15k)
|
| 435 |
+
|
| 436 |
+
</details>
|
| 437 |
+
|
| 438 |
+
Some datasets require confirmation before using them, so we recommend logging in with your Hugging Face account using these commands.
|
| 439 |
+
|
| 440 |
+
```bash
|
| 441 |
+
pip install --upgrade huggingface_hub
|
| 442 |
+
huggingface-cli login
|
| 443 |
+
```
|
| 444 |
+
|
| 445 |
+
## Requirement
|
| 446 |
+
|
| 447 |
+
| Mandatory | Minimum | Recommend |
|
| 448 |
+
| ------------ | ------- | --------- |
|
| 449 |
+
| python | 3.9 | 3.10 |
|
| 450 |
+
| torch | 2.0.0 | 2.6.0 |
|
| 451 |
+
| torchvision | 0.15.0 | 0.21.0 |
|
| 452 |
+
| transformers | 4.49.0 | 4.50.0 |
|
| 453 |
+
| datasets | 2.16.0 | 3.2.0 |
|
| 454 |
+
| accelerate | 0.34.0 | 1.2.1 |
|
| 455 |
+
| peft | 0.14.0 | 0.15.1 |
|
| 456 |
+
| trl | 0.8.6 | 0.9.6 |
|
| 457 |
+
|
| 458 |
+
| Optional | Minimum | Recommend |
|
| 459 |
+
| ------------ | ------- | --------- |
|
| 460 |
+
| CUDA | 11.6 | 12.2 |
|
| 461 |
+
| deepspeed | 0.10.0 | 0.16.4 |
|
| 462 |
+
| bitsandbytes | 0.39.0 | 0.43.1 |
|
| 463 |
+
| vllm | 0.4.3 | 0.8.2 |
|
| 464 |
+
| flash-attn | 2.5.6 | 2.7.2 |
|
| 465 |
+
|
| 466 |
+
### Hardware Requirement
|
| 467 |
+
|
| 468 |
+
\* *estimated*
|
| 469 |
+
|
| 470 |
+
| Method | Bits | 7B | 14B | 30B | 70B | `x`B |
|
| 471 |
+
| ------------------------------- | ---- | ----- | ----- | ----- | ------ | ------- |
|
| 472 |
+
| Full (`bf16` or `fp16`) | 32 | 120GB | 240GB | 600GB | 1200GB | `18x`GB |
|
| 473 |
+
| Full (`pure_bf16`) | 16 | 60GB | 120GB | 300GB | 600GB | `8x`GB |
|
| 474 |
+
| Freeze/LoRA/GaLore/APOLLO/BAdam | 16 | 16GB | 32GB | 64GB | 160GB | `2x`GB |
|
| 475 |
+
| QLoRA | 8 | 10GB | 20GB | 40GB | 80GB | `x`GB |
|
| 476 |
+
| QLoRA | 4 | 6GB | 12GB | 24GB | 48GB | `x/2`GB |
|
| 477 |
+
| QLoRA | 2 | 4GB | 8GB | 16GB | 24GB | `x/4`GB |
|
| 478 |
+
|
| 479 |
+
## Getting Started
|
| 480 |
+
|
| 481 |
+
### Installation
|
| 482 |
+
|
| 483 |
+
> [!IMPORTANT]
|
| 484 |
+
> Installation is mandatory.
|
| 485 |
+
|
| 486 |
+
#### Install from Source
|
| 487 |
+
|
| 488 |
+
```bash
|
| 489 |
+
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
|
| 490 |
+
cd LLaMA-Factory
|
| 491 |
+
pip install -e ".[torch,metrics]" --no-build-isolation
|
| 492 |
+
```
|
| 493 |
+
|
| 494 |
+
Extra dependencies available: torch, torch-npu, metrics, deepspeed, liger-kernel, bitsandbytes, hqq, eetq, gptq, aqlm, vllm, sglang, galore, apollo, badam, adam-mini, qwen, minicpm_v, openmind, swanlab, dev
|
| 495 |
+
|
| 496 |
+
#### Install from Docker Image
|
| 497 |
+
|
| 498 |
+
```bash
|
| 499 |
+
docker run -it --rm --gpus=all --ipc=host hiyouga/llamafactory:latest
|
| 500 |
+
```
|
| 501 |
+
|
| 502 |
+
This image is built on Ubuntu 22.04 (x86\_64), CUDA 12.4, Python 3.11, PyTorch 2.6.0, and Flash-attn 2.7.4.
|
| 503 |
+
|
| 504 |
+
Find the pre-built images: https://hub.docker.com/r/hiyouga/llamafactory/tags
|
| 505 |
+
|
| 506 |
+
Please refer to [build docker](#build-docker) to build the image yourself.
|
| 507 |
+
|
| 508 |
+
<details><summary>Setting up a virtual environment with <b>uv</b></summary>
|
| 509 |
+
|
| 510 |
+
Create an isolated Python environment with [uv](https://github.com/astral-sh/uv):
|
| 511 |
+
|
| 512 |
+
```bash
|
| 513 |
+
uv sync --extra torch --extra metrics --prerelease=allow
|
| 514 |
+
```
|
| 515 |
+
|
| 516 |
+
Run LLaMA-Factory in the isolated environment:
|
| 517 |
+
|
| 518 |
+
```bash
|
| 519 |
+
uv run --prerelease=allow llamafactory-cli train examples/train_lora/llama3_lora_pretrain.yaml
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
</details>
|
| 523 |
+
|
| 524 |
+
<details><summary>For Windows users</summary>
|
| 525 |
+
|
| 526 |
+
#### Install PyTorch
|
| 527 |
+
|
| 528 |
+
You need to manually install the GPU version of PyTorch on the Windows platform. Please refer to the [official website](https://pytorch.org/get-started/locally/) and the following command to install PyTorch with CUDA support:
|
| 529 |
+
|
| 530 |
+
```bash
|
| 531 |
+
pip uninstall torch torchvision torchaudio
|
| 532 |
+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
|
| 533 |
+
python -c "import torch; print(torch.cuda.is_available())"
|
| 534 |
+
```
|
| 535 |
+
|
| 536 |
+
If you see `True` then you have successfully installed PyTorch with CUDA support.
|
| 537 |
+
|
| 538 |
+
Try `dataloader_num_workers: 0` if you encounter `Can't pickle local object` error.
|
| 539 |
+
|
| 540 |
+
#### Install BitsAndBytes
|
| 541 |
+
|
| 542 |
+
If you want to enable the quantized LoRA (QLoRA) on the Windows platform, you need to install a pre-built version of `bitsandbytes` library, which supports CUDA 11.1 to 12.2, please select the appropriate [release version](https://github.com/jllllll/bitsandbytes-windows-webui/releases/tag/wheels) based on your CUDA version.
|
| 543 |
+
|
| 544 |
+
```bash
|
| 545 |
+
pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.2.post2-py3-none-win_amd64.whl
|
| 546 |
+
```
|
| 547 |
+
|
| 548 |
+
#### Install Flash Attention-2
|
| 549 |
+
|
| 550 |
+
To enable FlashAttention-2 on the Windows platform, please use the script from [flash-attention-windows-wheel](https://huggingface.co/lldacing/flash-attention-windows-wheel) to compile and install it by yourself.
|
| 551 |
+
|
| 552 |
+
</details>
|
| 553 |
+
|
| 554 |
+
<details><summary>For Ascend NPU users</summary>
|
| 555 |
+
|
| 556 |
+
To install LLaMA Factory on Ascend NPU devices, please upgrade Python to version 3.10 or higher and specify extra dependencies: `pip install -e ".[torch-npu,metrics]"`. Additionally, you need to install the **[Ascend CANN Toolkit and Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**. Please follow the [installation tutorial](https://www.hiascend.com/document/detail/en/CANNCommunityEdition/600alphaX/softwareinstall/instg/atlasdeploy_03_0031.html) or use the following commands:
|
| 557 |
+
|
| 558 |
+
```bash
|
| 559 |
+
# replace the url according to your CANN version and devices
|
| 560 |
+
# install CANN Toolkit
|
| 561 |
+
wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C20SPC702/Ascend-cann-toolkit_8.0.0.alpha002_linux-"$(uname -i)".run
|
| 562 |
+
bash Ascend-cann-toolkit_8.0.0.alpha002_linux-"$(uname -i)".run --install
|
| 563 |
+
|
| 564 |
+
# install CANN Kernels
|
| 565 |
+
wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C20SPC702/Ascend-cann-kernels-910b_8.0.0.alpha002_linux-"$(uname -i)".run
|
| 566 |
+
bash Ascend-cann-kernels-910b_8.0.0.alpha002_linux-"$(uname -i)".run --install
|
| 567 |
+
|
| 568 |
+
# set env variables
|
| 569 |
+
source /usr/local/Ascend/ascend-toolkit/set_env.sh
|
| 570 |
+
```
|
| 571 |
+
|
| 572 |
+
| Requirement | Minimum | Recommend |
|
| 573 |
+
| ------------ | ------- | -------------- |
|
| 574 |
+
| CANN | 8.0.RC1 | 8.0.0.alpha002 |
|
| 575 |
+
| torch | 2.1.0 | 2.4.0 |
|
| 576 |
+
| torch-npu | 2.1.0 | 2.4.0.post2 |
|
| 577 |
+
| deepspeed | 0.13.2 | 0.13.2 |
|
| 578 |
+
| vllm-ascend | - | 0.7.3 |
|
| 579 |
+
|
| 580 |
+
Remember to use `ASCEND_RT_VISIBLE_DEVICES` instead of `CUDA_VISIBLE_DEVICES` to specify the device to use.
|
| 581 |
+
|
| 582 |
+
If you cannot infer model on NPU devices, try setting `do_sample: false` in the configurations.
|
| 583 |
+
|
| 584 |
+
Download the pre-built Docker images: [32GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/130.html) | [64GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/131.html)
|
| 585 |
+
|
| 586 |
+
#### Install BitsAndBytes
|
| 587 |
+
|
| 588 |
+
To use QLoRA based on bitsandbytes on Ascend NPU, please follow these 3 steps:
|
| 589 |
+
|
| 590 |
+
1. Manually compile bitsandbytes: Refer to [the installation documentation](https://huggingface.co/docs/bitsandbytes/installation?backend=Ascend+NPU&platform=Ascend+NPU) for the NPU version of bitsandbytes to complete the compilation and installation. The compilation requires a cmake version of at least 3.22.1 and a g++ version of at least 12.x.
|
| 591 |
+
|
| 592 |
+
```bash
|
| 593 |
+
# Install bitsandbytes from source
|
| 594 |
+
# Clone bitsandbytes repo, Ascend NPU backend is currently enabled on multi-backend-refactor branch
|
| 595 |
+
git clone -b multi-backend-refactor https://github.com/bitsandbytes-foundation/bitsandbytes.git
|
| 596 |
+
cd bitsandbytes/
|
| 597 |
+
|
| 598 |
+
# Install dependencies
|
| 599 |
+
pip install -r requirements-dev.txt
|
| 600 |
+
|
| 601 |
+
# Install the dependencies for the compilation tools. Note that the commands for this step may vary depending on the operating system. The following are provided for reference
|
| 602 |
+
apt-get install -y build-essential cmake
|
| 603 |
+
|
| 604 |
+
# Compile & install
|
| 605 |
+
cmake -DCOMPUTE_BACKEND=npu -S .
|
| 606 |
+
make
|
| 607 |
+
pip install .
|
| 608 |
+
```
|
| 609 |
+
|
| 610 |
+
2. Install transformers from the main branch.
|
| 611 |
+
|
| 612 |
+
```bash
|
| 613 |
+
git clone -b main https://github.com/huggingface/transformers.git
|
| 614 |
+
cd transformers
|
| 615 |
+
pip install .
|
| 616 |
+
```
|
| 617 |
+
|
| 618 |
+
3. Set `double_quantization: false` in the configuration. You can refer to the [example](examples/train_qlora/llama3_lora_sft_bnb_npu.yaml).
|
| 619 |
+
|
| 620 |
+
</details>
|
| 621 |
+
|
| 622 |
+
### Data Preparation
|
| 623 |
+
|
| 624 |
+
Please refer to [data/README.md](data/README.md) for checking the details about the format of dataset files. You can use datasets on HuggingFace / ModelScope / Modelers hub, load the dataset in local disk, or specify a path to s3/gcs cloud storage.
|
| 625 |
+
|
| 626 |
+
> [!NOTE]
|
| 627 |
+
> Please update `data/dataset_info.json` to use your custom dataset.
|
| 628 |
+
|
| 629 |
+
You can also use **[Easy Dataset](https://github.com/ConardLi/easy-dataset)** or **[GraphGen](https://github.com/open-sciencelab/GraphGen)** to create synthetic data for fine-tuning.
|
| 630 |
+
|
| 631 |
+
### Quickstart
|
| 632 |
+
|
| 633 |
+
Use the following 3 commands to run LoRA **fine-tuning**, **inference** and **merging** of the Llama3-8B-Instruct model, respectively.
|
| 634 |
+
|
| 635 |
+
```bash
|
| 636 |
+
llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
|
| 637 |
+
llamafactory-cli chat examples/inference/llama3_lora_sft.yaml
|
| 638 |
+
llamafactory-cli export examples/merge_lora/llama3_lora_sft.yaml
|
| 639 |
+
```
|
| 640 |
+
|
| 641 |
+
See [examples/README.md](examples/README.md) for advanced usage (including distributed training).
|
| 642 |
+
|
| 643 |
+
> [!TIP]
|
| 644 |
+
> Use `llamafactory-cli help` to show help information.
|
| 645 |
+
>
|
| 646 |
+
> Read [FAQs](https://github.com/hiyouga/LLaMA-Factory/issues/4614) first if you encounter any problems.
|
| 647 |
+
|
| 648 |
+
### Fine-Tuning with LLaMA Board GUI (powered by [Gradio](https://github.com/gradio-app/gradio))
|
| 649 |
+
|
| 650 |
+
```bash
|
| 651 |
+
llamafactory-cli webui
|
| 652 |
+
```
|
| 653 |
+
|
| 654 |
+
### Build Docker
|
| 655 |
+
|
| 656 |
+
For CUDA users:
|
| 657 |
+
|
| 658 |
+
```bash
|
| 659 |
+
cd docker/docker-cuda/
|
| 660 |
+
docker compose up -d
|
| 661 |
+
docker compose exec llamafactory bash
|
| 662 |
+
```
|
| 663 |
+
|
| 664 |
+
For Ascend NPU users:
|
| 665 |
+
|
| 666 |
+
```bash
|
| 667 |
+
cd docker/docker-npu/
|
| 668 |
+
docker compose up -d
|
| 669 |
+
docker compose exec llamafactory bash
|
| 670 |
+
```
|
| 671 |
+
|
| 672 |
+
For AMD ROCm users:
|
| 673 |
+
|
| 674 |
+
```bash
|
| 675 |
+
cd docker/docker-rocm/
|
| 676 |
+
docker compose up -d
|
| 677 |
+
docker compose exec llamafactory bash
|
| 678 |
+
```
|
| 679 |
+
|
| 680 |
+
<details><summary>Build without Docker Compose</summary>
|
| 681 |
+
|
| 682 |
+
For CUDA users:
|
| 683 |
+
|
| 684 |
+
```bash
|
| 685 |
+
docker build -f ./docker/docker-cuda/Dockerfile \
|
| 686 |
+
--build-arg PIP_INDEX=https://pypi.org/simple \
|
| 687 |
+
--build-arg EXTRAS=metrics \
|
| 688 |
+
-t llamafactory:latest .
|
| 689 |
+
|
| 690 |
+
docker run -dit --ipc=host --gpus=all \
|
| 691 |
+
-p 7860:7860 \
|
| 692 |
+
-p 8000:8000 \
|
| 693 |
+
--name llamafactory \
|
| 694 |
+
llamafactory:latest
|
| 695 |
+
|
| 696 |
+
docker exec -it llamafactory bash
|
| 697 |
+
```
|
| 698 |
+
|
| 699 |
+
For Ascend NPU users:
|
| 700 |
+
|
| 701 |
+
```bash
|
| 702 |
+
docker build -f ./docker/docker-npu/Dockerfile \
|
| 703 |
+
--build-arg PIP_INDEX=https://pypi.org/simple \
|
| 704 |
+
--build-arg EXTRAS=torch-npu,metrics \
|
| 705 |
+
-t llamafactory:latest .
|
| 706 |
+
|
| 707 |
+
docker run -dit --ipc=host \
|
| 708 |
+
-v /usr/local/dcmi:/usr/local/dcmi \
|
| 709 |
+
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
|
| 710 |
+
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
|
| 711 |
+
-v /etc/ascend_install.info:/etc/ascend_install.info \
|
| 712 |
+
-p 7860:7860 \
|
| 713 |
+
-p 8000:8000 \
|
| 714 |
+
--device /dev/davinci0 \
|
| 715 |
+
--device /dev/davinci_manager \
|
| 716 |
+
--device /dev/devmm_svm \
|
| 717 |
+
--device /dev/hisi_hdc \
|
| 718 |
+
--name llamafactory \
|
| 719 |
+
llamafactory:latest
|
| 720 |
+
|
| 721 |
+
docker exec -it llamafactory bash
|
| 722 |
+
```
|
| 723 |
+
|
| 724 |
+
For AMD ROCm users:
|
| 725 |
+
|
| 726 |
+
```bash
|
| 727 |
+
docker build -f ./docker/docker-rocm/Dockerfile \
|
| 728 |
+
--build-arg PIP_INDEX=https://pypi.org/simple \
|
| 729 |
+
--build-arg EXTRAS=metrics \
|
| 730 |
+
-t llamafactory:latest .
|
| 731 |
+
|
| 732 |
+
docker run -dit --ipc=host \
|
| 733 |
+
-p 7860:7860 \
|
| 734 |
+
-p 8000:8000 \
|
| 735 |
+
--device /dev/kfd \
|
| 736 |
+
--device /dev/dri \
|
| 737 |
+
--name llamafactory \
|
| 738 |
+
llamafactory:latest
|
| 739 |
+
|
| 740 |
+
docker exec -it llamafactory bash
|
| 741 |
+
```
|
| 742 |
+
|
| 743 |
+
</details>
|
| 744 |
+
|
| 745 |
+
<details><summary>Use Docker volumes</summary>
|
| 746 |
+
|
| 747 |
+
You can uncomment `VOLUME [ "/root/.cache/huggingface", "/app/shared_data", "/app/output" ]` in the Dockerfile to use data volumes.
|
| 748 |
+
|
| 749 |
+
When building the Docker image, use `-v ./hf_cache:/root/.cache/huggingface` argument to mount the local directory to the container. The following data volumes are available.
|
| 750 |
+
|
| 751 |
+
- `hf_cache`: Utilize Hugging Face cache on the host machine.
|
| 752 |
+
- `shared_data`: The directionary to store datasets on the host machine.
|
| 753 |
+
- `output`: Set export dir to this location so that the merged result can be accessed directly on the host machine.
|
| 754 |
+
|
| 755 |
+
</details>
|
| 756 |
+
|
| 757 |
+
### Deploy with OpenAI-style API and vLLM
|
| 758 |
+
|
| 759 |
+
```bash
|
| 760 |
+
API_PORT=8000 llamafactory-cli api examples/inference/llama3.yaml infer_backend=vllm vllm_enforce_eager=true
|
| 761 |
+
```
|
| 762 |
+
|
| 763 |
+
> [!TIP]
|
| 764 |
+
> Visit [this page](https://platform.openai.com/docs/api-reference/chat/create) for API document.
|
| 765 |
+
>
|
| 766 |
+
> Examples: [Image understanding](scripts/api_example/test_image.py) | [Function calling](scripts/api_example/test_toolcall.py)
|
| 767 |
+
|
| 768 |
+
### Download from ModelScope Hub
|
| 769 |
+
|
| 770 |
+
If you have trouble with downloading models and datasets from Hugging Face, you can use ModelScope.
|
| 771 |
+
|
| 772 |
+
```bash
|
| 773 |
+
export USE_MODELSCOPE_HUB=1 # `set USE_MODELSCOPE_HUB=1` for Windows
|
| 774 |
+
```
|
| 775 |
+
|
| 776 |
+
Train the model by specifying a model ID of the ModelScope Hub as the `model_name_or_path`. You can find a full list of model IDs at [ModelScope Hub](https://modelscope.cn/models), e.g., `LLM-Research/Meta-Llama-3-8B-Instruct`.
|
| 777 |
+
|
| 778 |
+
### Download from Modelers Hub
|
| 779 |
+
|
| 780 |
+
You can also use Modelers Hub to download models and datasets.
|
| 781 |
+
|
| 782 |
+
```bash
|
| 783 |
+
export USE_OPENMIND_HUB=1 # `set USE_OPENMIND_HUB=1` for Windows
|
| 784 |
+
```
|
| 785 |
+
|
| 786 |
+
Train the model by specifying a model ID of the Modelers Hub as the `model_name_or_path`. You can find a full list of model IDs at [Modelers Hub](https://modelers.cn/models), e.g., `TeleAI/TeleChat-7B-pt`.
|
| 787 |
+
|
| 788 |
+
### Use W&B Logger
|
| 789 |
+
|
| 790 |
+
To use [Weights & Biases](https://wandb.ai) for logging experimental results, you need to add the following arguments to yaml files.
|
| 791 |
+
|
| 792 |
+
```yaml
|
| 793 |
+
report_to: wandb
|
| 794 |
+
run_name: test_run # optional
|
| 795 |
+
```
|
| 796 |
+
|
| 797 |
+
Set `WANDB_API_KEY` to [your key](https://wandb.ai/authorize) when launching training tasks to log in with your W&B account.
|
| 798 |
+
|
| 799 |
+
### Use SwanLab Logger
|
| 800 |
+
|
| 801 |
+
To use [SwanLab](https://github.com/SwanHubX/SwanLab) for logging experimental results, you need to add the following arguments to yaml files.
|
| 802 |
+
|
| 803 |
+
```yaml
|
| 804 |
+
use_swanlab: true
|
| 805 |
+
swanlab_run_name: test_run # optional
|
| 806 |
+
```
|
| 807 |
+
|
| 808 |
+
When launching training tasks, you can log in to SwanLab in three ways:
|
| 809 |
+
|
| 810 |
+
1. Add `swanlab_api_key=<your_api_key>` to the yaml file, and set it to your [API key](https://swanlab.cn/settings).
|
| 811 |
+
2. Set the environment variable `SWANLAB_API_KEY` to your [API key](https://swanlab.cn/settings).
|
| 812 |
+
3. Use the `swanlab login` command to complete the login.
|
| 813 |
+
|
| 814 |
+
## Projects using LLaMA Factory
|
| 815 |
+
|
| 816 |
+
If you have a project that should be incorporated, please contact via email or create a pull request.
|
| 817 |
+
|
| 818 |
+
<details><summary>Click to show</summary>
|
| 819 |
+
|
| 820 |
+
1. Wang et al. ESRL: Efficient Sampling-based Reinforcement Learning for Sequence Generation. 2023. [[arxiv]](https://arxiv.org/abs/2308.02223)
|
| 821 |
+
1. Yu et al. Open, Closed, or Small Language Models for Text Classification? 2023. [[arxiv]](https://arxiv.org/abs/2308.10092)
|
| 822 |
+
1. Wang et al. UbiPhysio: Support Daily Functioning, Fitness, and Rehabilitation with Action Understanding and Feedback in Natural Language. 2023. [[arxiv]](https://arxiv.org/abs/2308.10526)
|
| 823 |
+
1. Luceri et al. Leveraging Large Language Models to Detect Influence Campaigns in Social Media. 2023. [[arxiv]](https://arxiv.org/abs/2311.07816)
|
| 824 |
+
1. Zhang et al. Alleviating Hallucinations of Large Language Models through Induced Hallucinations. 2023. [[arxiv]](https://arxiv.org/abs/2312.15710)
|
| 825 |
+
1. Wang et al. Know Your Needs Better: Towards Structured Understanding of Marketer Demands with Analogical Reasoning Augmented LLMs. KDD 2024. [[arxiv]](https://arxiv.org/abs/2401.04319)
|
| 826 |
+
1. Wang et al. CANDLE: Iterative Conceptualization and Instantiation Distillation from Large Language Models for Commonsense Reasoning. ACL 2024. [[arxiv]](https://arxiv.org/abs/2401.07286)
|
| 827 |
+
1. Choi et al. FACT-GPT: Fact-Checking Augmentation via Claim Matching with LLMs. 2024. [[arxiv]](https://arxiv.org/abs/2402.05904)
|
| 828 |
+
1. Zhang et al. AutoMathText: Autonomous Data Selection with Language Models for Mathematical Texts. 2024. [[arxiv]](https://arxiv.org/abs/2402.07625)
|
| 829 |
+
1. Lyu et al. KnowTuning: Knowledge-aware Fine-tuning for Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.11176)
|
| 830 |
+
1. Yang et al. LaCo: Large Language Model Pruning via Layer Collaps. 2024. [[arxiv]](https://arxiv.org/abs/2402.11187)
|
| 831 |
+
1. Bhardwaj et al. Language Models are Homer Simpson! Safety Re-Alignment of Fine-tuned Language Models through Task Arithmetic. 2024. [[arxiv]](https://arxiv.org/abs/2402.11746)
|
| 832 |
+
1. Yang et al. Enhancing Empathetic Response Generation by Augmenting LLMs with Small-scale Empathetic Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.11801)
|
| 833 |
+
1. Yi et al. Generation Meets Verification: Accelerating Large Language Model Inference with Smart Parallel Auto-Correct Decoding. ACL 2024 Findings. [[arxiv]](https://arxiv.org/abs/2402.11809)
|
| 834 |
+
1. Cao et al. Head-wise Shareable Attention for Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.11819)
|
| 835 |
+
1. Zhang et al. Enhancing Multilingual Capabilities of Large Language Models through Self-Distillation from Resource-Rich Languages. 2024. [[arxiv]](https://arxiv.org/abs/2402.12204)
|
| 836 |
+
1. Kim et al. Efficient and Effective Vocabulary Expansion Towards Multilingual Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.14714)
|
| 837 |
+
1. Yu et al. KIEval: A Knowledge-grounded Interactive Evaluation Framework for Large Language Models. ACL 2024. [[arxiv]](https://arxiv.org/abs/2402.15043)
|
| 838 |
+
1. Huang et al. Key-Point-Driven Data Synthesis with its Enhancement on Mathematical Reasoning. 2024. [[arxiv]](https://arxiv.org/abs/2403.02333)
|
| 839 |
+
1. Duan et al. Negating Negatives: Alignment without Human Positive Samples via Distributional Dispreference Optimization. 2024. [[arxiv]](https://arxiv.org/abs/2403.03419)
|
| 840 |
+
1. Xie and Schwertfeger. Empowering Robotics with Large Language Models: osmAG Map Comprehension with LLMs. 2024. [[arxiv]](https://arxiv.org/abs/2403.08228)
|
| 841 |
+
1. Wu et al. Large Language Models are Parallel Multilingual Learners. 2024. [[arxiv]](https://arxiv.org/abs/2403.09073)
|
| 842 |
+
1. Zhang et al. EDT: Improving Large Language Models' Generation by Entropy-based Dynamic Temperature Sampling. 2024. [[arxiv]](https://arxiv.org/abs/2403.14541)
|
| 843 |
+
1. Weller et al. FollowIR: Evaluating and Teaching Information Retrieval Models to Follow Instructions. 2024. [[arxiv]](https://arxiv.org/abs/2403.15246)
|
| 844 |
+
1. Hongbin Na. CBT-LLM: A Chinese Large Language Model for Cognitive Behavioral Therapy-based Mental Health Question Answering. COLING 2024. [[arxiv]](https://arxiv.org/abs/2403.16008)
|
| 845 |
+
1. Zan et al. CodeS: Natural Language to Code Repository via Multi-Layer Sketch. 2024. [[arxiv]](https://arxiv.org/abs/2403.16443)
|
| 846 |
+
1. Liu et al. Extensive Self-Contrast Enables Feedback-Free Language Model Alignment. 2024. [[arxiv]](https://arxiv.org/abs/2404.00604)
|
| 847 |
+
1. Luo et al. BAdam: A Memory Efficient Full Parameter Training Method for Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.02827)
|
| 848 |
+
1. Du et al. Chinese Tiny LLM: Pretraining a Chinese-Centric Large Language Model. 2024. [[arxiv]](https://arxiv.org/abs/2404.04167)
|
| 849 |
+
1. Ma et al. Parameter Efficient Quasi-Orthogonal Fine-Tuning via Givens Rotation. ICML 2024. [[arxiv]](https://arxiv.org/abs/2404.04316)
|
| 850 |
+
1. Liu et al. Dynamic Generation of Personalities with Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.07084)
|
| 851 |
+
1. Shang et al. How Far Have We Gone in Stripped Binary Code Understanding Using Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.09836)
|
| 852 |
+
1. Huang et al. LLMTune: Accelerate Database Knob Tuning with Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.11581)
|
| 853 |
+
1. Deng et al. Text-Tuple-Table: Towards Information Integration in Text-to-Table Generation via Global Tuple Extraction. 2024. [[arxiv]](https://arxiv.org/abs/2404.14215)
|
| 854 |
+
1. Acikgoz et al. Hippocrates: An Open-Source Framework for Advancing Large Language Models in Healthcare. 2024. [[arxiv]](https://arxiv.org/abs/2404.16621)
|
| 855 |
+
1. Zhang et al. Small Language Models Need Strong Verifiers to Self-Correct Reasoning. ACL 2024 Findings. [[arxiv]](https://arxiv.org/abs/2404.17140)
|
| 856 |
+
1. Zhou et al. FREB-TQA: A Fine-Grained Robustness Evaluation Benchmark for Table Question Answering. NAACL 2024. [[arxiv]](https://arxiv.org/abs/2404.18585)
|
| 857 |
+
1. Xu et al. Large Language Models for Cyber Security: A Systematic Literature Review. 2024. [[arxiv]](https://arxiv.org/abs/2405.04760)
|
| 858 |
+
1. Dammu et al. "They are uncultured": Unveiling Covert Harms and Social Threats in LLM Generated Conversations. 2024. [[arxiv]](https://arxiv.org/abs/2405.05378)
|
| 859 |
+
1. Yi et al. A safety realignment framework via subspace-oriented model fusion for large language models. 2024. [[arxiv]](https://arxiv.org/abs/2405.09055)
|
| 860 |
+
1. Lou et al. SPO: Multi-Dimensional Preference Sequential Alignment With Implicit Reward Modeling. 2024. [[arxiv]](https://arxiv.org/abs/2405.12739)
|
| 861 |
+
1. Zhang et al. Getting More from Less: Large Language Models are Good Spontaneous Multilingual Learners. 2024. [[arxiv]](https://arxiv.org/abs/2405.13816)
|
| 862 |
+
1. Zhang et al. TS-Align: A Teacher-Student Collaborative Framework for Scalable Iterative Finetuning of Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2405.20215)
|
| 863 |
+
1. Zihong Chen. Sentence Segmentation and Sentence Punctuation Based on XunziALLM. 2024. [[paper]](https://aclanthology.org/2024.lt4hala-1.30)
|
| 864 |
+
1. Gao et al. The Best of Both Worlds: Toward an Honest and Helpful Large Language Model. 2024. [[arxiv]](https://arxiv.org/abs/2406.00380)
|
| 865 |
+
1. Wang and Song. MARS: Benchmarking the Metaphysical Reasoning Abilities of Language Models with a Multi-task Evaluation Dataset. 2024. [[arxiv]](https://arxiv.org/abs/2406.02106)
|
| 866 |
+
1. Hu et al. Computational Limits of Low-Rank Adaptation (LoRA) for Transformer-Based Models. 2024. [[arxiv]](https://arxiv.org/abs/2406.03136)
|
| 867 |
+
1. Ge et al. Time Sensitive Knowledge Editing through Efficient Finetuning. ACL 2024. [[arxiv]](https://arxiv.org/abs/2406.04496)
|
| 868 |
+
1. Tan et al. Peer Review as A Multi-Turn and Long-Context Dialogue with Role-Based Interactions. 2024. [[arxiv]](https://arxiv.org/abs/2406.05688)
|
| 869 |
+
1. Song et al. Turbo Sparse: Achieving LLM SOTA Performance with Minimal Activated Parameters. 2024. [[arxiv]](https://arxiv.org/abs/2406.05955)
|
| 870 |
+
1. Gu et al. RWKV-CLIP: A Robust Vision-Language Representation Learner. 2024. [[arxiv]](https://arxiv.org/abs/2406.06973)
|
| 871 |
+
1. Chen et al. Advancing Tool-Augmented Large Language Models: Integrating Insights from Errors in Inference Trees. 2024. [[arxiv]](https://arxiv.org/abs/2406.07115)
|
| 872 |
+
1. Zhu et al. Are Large Language Models Good Statisticians?. 2024. [[arxiv]](https://arxiv.org/abs/2406.07815)
|
| 873 |
+
1. Li et al. Know the Unknown: An Uncertainty-Sensitive Method for LLM Instruction Tuning. 2024. [[arxiv]](https://arxiv.org/abs/2406.10099)
|
| 874 |
+
1. Ding et al. IntentionQA: A Benchmark for Evaluating Purchase Intention Comprehension Abilities of Language Models in E-commerce. 2024. [[arxiv]](https://arxiv.org/abs/2406.10173)
|
| 875 |
+
1. He et al. COMMUNITY-CROSS-INSTRUCT: Unsupervised Instruction Generation for Aligning Large Language Models to Online Communities. 2024. [[arxiv]](https://arxiv.org/abs/2406.12074)
|
| 876 |
+
1. Lin et al. FVEL: Interactive Formal Verification Environment with Large Language Models via Theorem Proving. 2024. [[arxiv]](https://arxiv.org/abs/2406.14408)
|
| 877 |
+
1. Treutlein et al. Connecting the Dots: LLMs can Infer and Verbalize Latent Structure from Disparate Training Data. 2024. [[arxiv]](https://arxiv.org/abs/2406.14546)
|
| 878 |
+
1. Feng et al. SS-Bench: A Benchmark for Social Story Generation and Evaluation. 2024. [[arxiv]](https://arxiv.org/abs/2406.15695)
|
| 879 |
+
1. Feng et al. Self-Constructed Context Decompilation with Fined-grained Alignment Enhancement. 2024. [[arxiv]](https://arxiv.org/abs/2406.17233)
|
| 880 |
+
1. Liu et al. Large Language Models for Cuffless Blood Pressure Measurement From Wearable Biosignals. 2024. [[arxiv]](https://arxiv.org/abs/2406.18069)
|
| 881 |
+
1. Iyer et al. Exploring Very Low-Resource Translation with LLMs: The University of Edinburgh's Submission to AmericasNLP 2024 Translation Task. AmericasNLP 2024. [[paper]](https://aclanthology.org/2024.americasnlp-1.25)
|
| 882 |
+
1. Li et al. Calibrating LLMs with Preference Optimization on Thought Trees for Generating Rationale in Science Question Scoring. 2024. [[arxiv]](https://arxiv.org/abs/2406.19949)
|
| 883 |
+
1. Yang et al. Financial Knowledge Large Language Model. 2024. [[arxiv]](https://arxiv.org/abs/2407.00365)
|
| 884 |
+
1. Lin et al. DogeRM: Equipping Reward Models with Domain Knowledge through Model Merging. 2024. [[arxiv]](https://arxiv.org/abs/2407.01470)
|
| 885 |
+
1. Bako et al. Evaluating the Semantic Profiling Abilities of LLMs for Natural Language Utterances in Data Visualization. 2024. [[arxiv]](https://arxiv.org/abs/2407.06129)
|
| 886 |
+
1. Huang et al. RoLoRA: Fine-tuning Rotated Outlier-free LLMs for Effective Weight-Activation Quantization. 2024. [[arxiv]](https://arxiv.org/abs/2407.08044)
|
| 887 |
+
1. Jiang et al. LLM-Collaboration on Automatic Science Journalism for the General Audience. 2024. [[arxiv]](https://arxiv.org/abs/2407.09756)
|
| 888 |
+
1. Inouye et al. Applied Auto-tuning on LoRA Hyperparameters. 2024. [[paper]](https://scholarcommons.scu.edu/cseng_senior/272/)
|
| 889 |
+
1. Qi et al. Research on Tibetan Tourism Viewpoints information generation system based on LLM. 2024. [[arxiv]](https://arxiv.org/abs/2407.13561)
|
| 890 |
+
1. Xu et al. Course-Correction: Safety Alignment Using Synthetic Preferences. 2024. [[arxiv]](https://arxiv.org/abs/2407.16637)
|
| 891 |
+
1. Sun et al. LAMBDA: A Large Model Based Data Agent. 2024. [[arxiv]](https://arxiv.org/abs/2407.17535)
|
| 892 |
+
1. Zhu et al. CollectiveSFT: Scaling Large Language Models for Chinese Medical Benchmark with Collective Instructions in Healthcare. 2024. [[arxiv]](https://arxiv.org/abs/2407.19705)
|
| 893 |
+
1. Yu et al. Correcting Negative Bias in Large Language Models through Negative Attention Score Alignment. 2024. [[arxiv]](https://arxiv.org/abs/2408.00137)
|
| 894 |
+
1. Xie et al. The Power of Personalized Datasets: Advancing Chinese Composition Writing for Elementary School through Targeted Model Fine-Tuning. IALP 2024. [[paper]](https://www.asianlp.sg/conferences/ialp2024/proceedings/papers/IALP2024_P055.pdf)
|
| 895 |
+
1. Liu et al. Instruct-Code-Llama: Improving Capabilities of Language Model in Competition Level Code Generation by Online Judge Feedback. ICIC 2024. [[paper]](https://link.springer.com/chapter/10.1007/978-981-97-5669-8_11)
|
| 896 |
+
1. Wang et al. Cybernetic Sentinels: Unveiling the Impact of Safety Data Selection on Model Security in Supervised Fine-Tuning. ICIC 2024. [[paper]](https://link.springer.com/chapter/10.1007/978-981-97-5669-8_23)
|
| 897 |
+
1. Xia et al. Understanding the Performance and Estimating the Cost of LLM Fine-Tuning. 2024. [[arxiv]](https://arxiv.org/abs/2408.04693)
|
| 898 |
+
1. Zeng et al. Perceive, Reflect, and Plan: Designing LLM Agent for Goal-Directed City Navigation without Instructions. 2024. [[arxiv]](https://arxiv.org/abs/2408.04168)
|
| 899 |
+
1. Xia et al. Using Pre-trained Language Model for Accurate ESG Prediction. FinNLP 2024. [[paper]](https://aclanthology.org/2024.finnlp-2.1/)
|
| 900 |
+
1. Liang et al. I-SHEEP: Self-Alignment of LLM from Scratch through an Iterative Self-Enhancement Paradigm. 2024. [[arxiv]](https://arxiv.org/abs/2408.08072)
|
| 901 |
+
1. Bai et al. Aligning Large Language Model with Direct Multi-Preference Optimization for Recommendation. CIKM 2024. [[paper]](https://dl.acm.org/doi/10.1145/3627673.3679611)
|
| 902 |
+
1. Zhang et al. CPsyCoun: A Report-based Multi-turn Dialogue Reconstruction and Evaluation Framework for Chinese Psychological Counseling. ACL 2024. [[paper]](https://aclanthology.org/2024.findings-acl.830.pdf)
|
| 903 |
+
1. **[StarWhisper](https://github.com/Yu-Yang-Li/StarWhisper)**: A large language model for Astronomy, based on ChatGLM2-6B and Qwen-14B.
|
| 904 |
+
1. **[DISC-LawLLM](https://github.com/FudanDISC/DISC-LawLLM)**: A large language model specialized in Chinese legal domain, based on Baichuan-13B, is capable of retrieving and reasoning on legal knowledge.
|
| 905 |
+
1. **[Sunsimiao](https://github.com/X-D-Lab/Sunsimiao)**: A large language model specialized in Chinese medical domain, based on Baichuan-7B and ChatGLM-6B.
|
| 906 |
+
1. **[CareGPT](https://github.com/WangRongsheng/CareGPT)**: A series of large language models for Chinese medical domain, based on LLaMA2-7B and Baichuan-13B.
|
| 907 |
+
1. **[MachineMindset](https://github.com/PKU-YuanGroup/Machine-Mindset/)**: A series of MBTI Personality large language models, capable of giving any LLM 16 different personality types based on different datasets and training methods.
|
| 908 |
+
1. **[Luminia-13B-v3](https://huggingface.co/Nekochu/Luminia-13B-v3)**: A large language model specialized in generate metadata for stable diffusion. [[demo]](https://huggingface.co/spaces/Nekochu/Luminia-13B_SD_Prompt)
|
| 909 |
+
1. **[Chinese-LLaVA-Med](https://github.com/BUAADreamer/Chinese-LLaVA-Med)**: A multimodal large language model specialized in Chinese medical domain, based on LLaVA-1.5-7B.
|
| 910 |
+
1. **[AutoRE](https://github.com/THUDM/AutoRE)**: A document-level relation extraction system based on large language models.
|
| 911 |
+
1. **[NVIDIA RTX AI Toolkit](https://github.com/NVIDIA/RTX-AI-Toolkit)**: SDKs for fine-tuning LLMs on Windows PC for NVIDIA RTX.
|
| 912 |
+
1. **[LazyLLM](https://github.com/LazyAGI/LazyLLM)**: An easy and lazy way for building multi-agent LLMs applications and supports model fine-tuning via LLaMA Factory.
|
| 913 |
+
1. **[RAG-Retrieval](https://github.com/NLPJCL/RAG-Retrieval)**: A full pipeline for RAG retrieval model fine-tuning, inference, and distillation. [[blog]](https://zhuanlan.zhihu.com/p/987727357)
|
| 914 |
+
1. **[360-LLaMA-Factory](https://github.com/Qihoo360/360-LLaMA-Factory)**: A modified library that supports long sequence SFT & DPO using ring attention.
|
| 915 |
+
1. **[Sky-T1](https://novasky-ai.github.io/posts/sky-t1/)**: An o1-like model fine-tuned by NovaSky AI with very small cost.
|
| 916 |
+
1. **[WeClone](https://github.com/xming521/WeClone)**: One-stop solution for creating your digital avatar from chat logs.
|
| 917 |
+
1. **[EmoLLM](https://github.com/SmartFlowAI/EmoLLM)**: A project about large language models (LLMs) and mental health.
|
| 918 |
+
</details>
|
| 919 |
+
|
| 920 |
+
## License
|
| 921 |
+
|
| 922 |
+
This repository is licensed under the [Apache-2.0 License](LICENSE).
|
| 923 |
+
|
| 924 |
+
Please follow the model licenses to use the corresponding model weights: [Baichuan 2](https://huggingface.co/baichuan-inc/Baichuan2-7B-Base/blob/main/Community%20License%20for%20Baichuan%202%20Model.pdf) / [BLOOM](https://huggingface.co/spaces/bigscience/license) / [ChatGLM3](https://github.com/THUDM/ChatGLM3/blob/main/MODEL_LICENSE) / [Command R](https://cohere.com/c4ai-cc-by-nc-license) / [DeepSeek](https://github.com/deepseek-ai/DeepSeek-LLM/blob/main/LICENSE-MODEL) / [Falcon](https://huggingface.co/tiiuae/falcon-180B/blob/main/LICENSE.txt) / [Gemma](https://ai.google.dev/gemma/terms) / [GLM-4](https://huggingface.co/THUDM/glm-4-9b/blob/main/LICENSE) / [GPT-2](https://github.com/openai/gpt-2/blob/master/LICENSE) / [Granite](LICENSE) / [Index](https://huggingface.co/IndexTeam/Index-1.9B/blob/main/LICENSE) / [InternLM](https://github.com/InternLM/InternLM#license) / [Llama](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md) / [Llama 2](https://ai.meta.com/llama/license/) / [Llama 3](https://llama.meta.com/llama3/license/) / [Llama 4](https://github.com/meta-llama/llama-models/blob/main/models/llama4/LICENSE) / [MiniCPM](https://github.com/OpenBMB/MiniCPM/blob/main/MiniCPM%20Model%20License.md) / [Mistral/Mixtral/Pixtral](LICENSE) / [OLMo](LICENSE) / [Phi-1.5/Phi-2](https://huggingface.co/microsoft/phi-1_5/resolve/main/Research%20License.docx) / [Phi-3/Phi-4](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct/blob/main/LICENSE) / [Qwen](https://github.com/QwenLM/Qwen/blob/main/Tongyi%20Qianwen%20LICENSE%20AGREEMENT) / [Skywork](https://huggingface.co/Skywork/Skywork-13B-base/blob/main/Skywork%20Community%20License.pdf) / [StarCoder 2](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement) / [TeleChat2](https://huggingface.co/Tele-AI/telechat-7B/blob/main/TeleChat%E6%A8%A1%E5%9E%8B%E7%A4%BE%E5%8C%BA%E8%AE%B8%E5%8F%AF%E5%8D%8F%E8%AE%AE.pdf) / [XVERSE](https://github.com/xverse-ai/XVERSE-13B/blob/main/MODEL_LICENSE.pdf) / [Yi](https://huggingface.co/01-ai/Yi-6B/blob/main/LICENSE) / [Yi-1.5](LICENSE) / [Yuan 2](https://github.com/IEIT-Yuan/Yuan-2.0/blob/main/LICENSE-Yuan)
|
| 925 |
+
|
| 926 |
+
## Citation
|
| 927 |
+
|
| 928 |
+
If this work is helpful, please kindly cite as:
|
| 929 |
+
|
| 930 |
+
```bibtex
|
| 931 |
+
@inproceedings{zheng2024llamafactory,
|
| 932 |
+
title={LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models},
|
| 933 |
+
author={Yaowei Zheng and Richong Zhang and Junhao Zhang and Yanhan Ye and Zheyan Luo and Zhangchi Feng and Yongqiang Ma},
|
| 934 |
+
booktitle={Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)},
|
| 935 |
+
address={Bangkok, Thailand},
|
| 936 |
+
publisher={Association for Computational Linguistics},
|
| 937 |
+
year={2024},
|
| 938 |
+
url={http://arxiv.org/abs/2403.13372}
|
| 939 |
+
}
|
| 940 |
+
```
|
| 941 |
+
|
| 942 |
+
## Acknowledgement
|
| 943 |
+
|
| 944 |
+
This repo benefits from [PEFT](https://github.com/huggingface/peft), [TRL](https://github.com/huggingface/trl), [QLoRA](https://github.com/artidoro/qlora) and [FastChat](https://github.com/lm-sys/FastChat). Thanks for their wonderful works.
|
| 945 |
+
|
| 946 |
+
## Star History
|
| 947 |
+
|
| 948 |
+

|
README_zh.md
ADDED
|
@@ -0,0 +1,949 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 2 |
+
|
| 3 |
+
[](https://github.com/hiyouga/LLaMA-Factory/stargazers)
|
| 4 |
+
[](https://github.com/hiyouga/LLaMA-Factory/commits/main)
|
| 5 |
+
[](https://github.com/hiyouga/LLaMA-Factory/graphs/contributors)
|
| 6 |
+
[](https://github.com/hiyouga/LLaMA-Factory/actions/workflows/tests.yml)
|
| 7 |
+
[](https://pypi.org/project/llamafactory/)
|
| 8 |
+
[](https://scholar.google.com/scholar?cites=12620864006390196564)
|
| 9 |
+
[](https://hub.docker.com/r/hiyouga/llamafactory/tags)
|
| 10 |
+
|
| 11 |
+
[](https://twitter.com/llamafactory_ai)
|
| 12 |
+
[](https://discord.gg/rKfvV9r9FK)
|
| 13 |
+
[](https://gitcode.com/zhengyaowei/LLaMA-Factory)
|
| 14 |
+
|
| 15 |
+
[](https://colab.research.google.com/drive/1d5KQtbemerlSDSxZIfAaWXhKr30QypiK?usp=sharing)
|
| 16 |
+
[](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory)
|
| 17 |
+
[](https://docs.alayanew.com/docs/documents/newActivities/llamafactory/?utm_source=LLaMA-Factory)
|
| 18 |
+
[](https://huggingface.co/spaces/hiyouga/LLaMA-Board)
|
| 19 |
+
[](https://modelscope.cn/studios/hiyouga/LLaMA-Board)
|
| 20 |
+
[](https://novita.ai/templates-library/105981?sharer=88115474-394e-4bda-968e-b88e123d0c47)
|
| 21 |
+
|
| 22 |
+
### 获得[亚马逊](https://aws.amazon.com/cn/blogs/china/a-one-stop-code-free-model-fine-tuning-deployment-platform-based-on-sagemaker-and-llama-factory/)、[英伟达](https://developer.nvidia.cn/rtx/ai-toolkit)、[阿里云](https://help.aliyun.com/zh/pai/use-cases/fine-tune-a-llama-3-model-with-llama-factory)等的应用。
|
| 23 |
+
|
| 24 |
+
<div align="center" markdown="1">
|
| 25 |
+
|
| 26 |
+
### 赞助商 ❤️
|
| 27 |
+
|
| 28 |
+
<a href="https://warp.dev/llama-factory">
|
| 29 |
+
<img alt="Warp sponsorship" width="400" src="https://github.com/user-attachments/assets/ab8dd143-b0fd-4904-bdc5-dd7ecac94eae">
|
| 30 |
+
</a>
|
| 31 |
+
|
| 32 |
+
#### [Warp,面向开发者的智能终端](https://warp.dev/llama-factory)
|
| 33 |
+
|
| 34 |
+
[适用于 MacOS、Linux 和 Windows](https://warp.dev/llama-factory)
|
| 35 |
+
|
| 36 |
+
----
|
| 37 |
+
|
| 38 |
+
### 使用零代码[命令行](#快速开始)与 [Web UI](#llama-board-可视化微调由-gradio-驱动) 轻松微调百余种大模型
|
| 39 |
+
|
| 40 |
+

|
| 41 |
+
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
👋 加入我们的[微信群](assets/wechat.jpg)、[NPU 用户群](assets/wechat_npu.jpg)或 [九章智算云算力优惠群](assets/wechat_alaya.png)。
|
| 45 |
+
|
| 46 |
+
\[ [English](README.md) | 中文 \]
|
| 47 |
+
|
| 48 |
+
**微调大模型可以像这样轻松…**
|
| 49 |
+
|
| 50 |
+
https://github.com/user-attachments/assets/43b700c6-a178-41db-b1f8-8190a5d3fcfc
|
| 51 |
+
|
| 52 |
+
选择你的打开方式:
|
| 53 |
+
|
| 54 |
+
- **入门教程**:https://zhuanlan.zhihu.com/p/695287607
|
| 55 |
+
- **微调视频教程**:https://www.bilibili.com/video/BV1djgRzxEts/
|
| 56 |
+
- **框架文档**:https://llamafactory.readthedocs.io/zh-cn/latest/
|
| 57 |
+
- **框架文档(昇腾 NPU)**:https://ascend.github.io/docs/sources/llamafactory/
|
| 58 |
+
- **Colab(免费)**:https://colab.research.google.com/drive/1d5KQtbemerlSDSxZIfAaWXhKr30QypiK?usp=sharing
|
| 59 |
+
- **本地机器**:请见[如何使用](#如何使用)
|
| 60 |
+
- **PAI-DSW(免费试用)**:https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory
|
| 61 |
+
- **九章智算云(算力优惠活动)**:https://docs.alayanew.com/docs/documents/useGuide/LLaMAFactory/mutiple/?utm_source=LLaMA-Factory
|
| 62 |
+
|
| 63 |
+
> [!NOTE]
|
| 64 |
+
> 除上述链接以外的其他网站均为未经许可的第三方网站,请小心甄别。
|
| 65 |
+
|
| 66 |
+
## 目录
|
| 67 |
+
|
| 68 |
+
- [项目特色](#项目特色)
|
| 69 |
+
- [官方博客](#官方博客)
|
| 70 |
+
- [更新日志](#更新日志)
|
| 71 |
+
- [模型](#模型)
|
| 72 |
+
- [训练方法](#训练方法)
|
| 73 |
+
- [数据集](#数据集)
|
| 74 |
+
- [软硬件依赖](#软硬件依赖)
|
| 75 |
+
- [如何使用](#如何使用)
|
| 76 |
+
- [安装 LLaMA Factory](#安装-llama-factory)
|
| 77 |
+
- [数据准备](#数据准备)
|
| 78 |
+
- [快速开始](#快速开始)
|
| 79 |
+
- [LLaMA Board 可视化微调](#llama-board-可视化微调由-gradio-驱动)
|
| 80 |
+
- [构建 Docker](#构建-docker)
|
| 81 |
+
- [利用 vLLM 部署 OpenAI API](#利用-vllm-部署-openai-api)
|
| 82 |
+
- [从魔搭社区下载](#从魔搭社区下载)
|
| 83 |
+
- [从魔乐社区下载](#从魔乐社区下载)
|
| 84 |
+
- [使用 W&B 面板](#使用-wb-面板)
|
| 85 |
+
- [使用 SwanLab 面板](#使用-swanlab-面板)
|
| 86 |
+
- [使用了 LLaMA Factory 的项目](#使用了-llama-factory-的项目)
|
| 87 |
+
- [协议](#协议)
|
| 88 |
+
- [引用](#引用)
|
| 89 |
+
- [致谢](#致谢)
|
| 90 |
+
|
| 91 |
+
## 项目特色
|
| 92 |
+
|
| 93 |
+
- **多种模型**:LLaMA、LLaVA、Mistral、Mixtral-MoE、Qwen、Qwen2-VL、DeepSeek、Yi、Gemma、ChatGLM、Phi 等等。
|
| 94 |
+
- **集成方法**:(增量)预训练、(多模态)指令监督微调、奖励模型训练、PPO 训练、DPO 训练、KTO 训练、ORPO 训练等等。
|
| 95 |
+
- **多种精度**:16 比特全参数微调、冻结微调、LoRA 微调和基于 AQLM/AWQ/GPTQ/LLM.int8/HQQ/EETQ 的 2/3/4/5/6/8 比特 QLoRA 微调。
|
| 96 |
+
- **先进算法**:[GaLore](https://github.com/jiaweizzhao/GaLore)、[BAdam](https://github.com/Ledzy/BAdam)、[APOLLO](https://github.com/zhuhanqing/APOLLO)、[Adam-mini](https://github.com/zyushun/Adam-mini)、[Muon](https://github.com/KellerJordan/Muon)、DoRA、LongLoRA、LLaMA Pro、Mixture-of-Depths、LoRA+、LoftQ 和 PiSSA。
|
| 97 |
+
- **实用技巧**:[FlashAttention-2](https://github.com/Dao-AILab/flash-attention)、[Unsloth](https://github.com/unslothai/unsloth)、[Liger Kernel](https://github.com/linkedin/Liger-Kernel)、RoPE scaling、NEFTune 和 rsLoRA。
|
| 98 |
+
- **广泛任务**:多轮对话、工具调用、图像理解、视觉定位、视频识别和语音理解等等。
|
| 99 |
+
- **实验监控**:LlamaBoard、TensorBoard、Wandb、MLflow、[SwanLab](https://github.com/SwanHubX/SwanLab) 等等。
|
| 100 |
+
- **极速推理**:基于 [vLLM](https://github.com/vllm-project/vllm) 或 [SGLang](https://github.com/sgl-project/sglang) 的 OpenAI 风格 API、浏览器界面和命令行接口。
|
| 101 |
+
|
| 102 |
+
### 最新模型的 Day-N 微调适配
|
| 103 |
+
|
| 104 |
+
| 适配时间 | 模型名称 |
|
| 105 |
+
| ------------ | -------------------------------------------------------------------- |
|
| 106 |
+
| Day 0 | Qwen3 / Qwen2.5-VL / Gemma 3 / GLM-4.1V / InternLM 3 / MiniCPM-o-2.6 |
|
| 107 |
+
| Day 1 | Llama 3 / GLM-4 / Mistral Small / PaliGemma2 / Llama 4 |
|
| 108 |
+
|
| 109 |
+
## 官方博客
|
| 110 |
+
|
| 111 |
+
- [基于 LLaMA-Factory 和 EasyR1 打造一站式无代码大模型强化学习和部署平台 LLM Model Hub](https://aws.amazon.com/cn/blogs/china/building-llm-model-hub-based-on-llamafactory-and-easyr1/)(中文)
|
| 112 |
+
- [使用 LLaMA-Factory 微调 Qwen2.5-VL 实现自动驾驶场景微调](https://docs.alayanew.com/docs/documents/useGuide/LLaMAFactory/mutiple/?utm_source=LLaMA-Factory)(中文)
|
| 113 |
+
- [通过亚马逊 SageMaker HyperPod 上的 LLaMA-Factory 增强多模态模型银行文档的视觉信息提取](https://aws.amazon.com/cn/blogs/machine-learning/how-apoidea-group-enhances-visual-information-extraction-from-banking-documents-with-multimodal-models-using-llama-factory-on-amazon-sagemaker-hyperpod/)(英文)
|
| 114 |
+
- [Easy Dataset × LLaMA Factory: 让大模型高效学习领域知识](https://buaa-act.feishu.cn/wiki/KY9xwTGs1iqHrRkjXBwcZP9WnL9)(中文)
|
| 115 |
+
|
| 116 |
+
<details><summary>全部博客</summary>
|
| 117 |
+
|
| 118 |
+
- [LLaMA Factory:微调 DeepSeek-R1-Distill-Qwen-7B 模型实现新闻标题分类器](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory_deepseek_r1_distill_7b)(中文)
|
| 119 |
+
- [基于 Amazon SageMaker 和 LLaMA-Factory 打造一站式无代码模型微调部署平台 Model Hub](https://aws.amazon.com/cn/blogs/china/a-one-stop-code-free-model-fine-tuning-deployment-platform-based-on-sagemaker-and-llama-factory/)(中文)
|
| 120 |
+
- [LLaMA Factory 多模态微调实践:微调 Qwen2-VL 构建文旅大模型](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory_qwen2vl)(中文)
|
| 121 |
+
- [LLaMA Factory:微调LLaMA3模型实现角色扮演](https://gallery.pai-ml.com/#/preview/deepLearning/nlp/llama_factory)(中文)
|
| 122 |
+
|
| 123 |
+
</details>
|
| 124 |
+
|
| 125 |
+
## 更新日志
|
| 126 |
+
|
| 127 |
+
[25/07/02] 我们支持了 **[GLM-4.1V-9B-Thinking](https://github.com/THUDM/GLM-4.1V-Thinking)** 模型的微调。请安装 transformers 的 main 分支版本以使用。
|
| 128 |
+
|
| 129 |
+
[25/04/28] 我们支持了 **[Qwen3](https://qwenlm.github.io/blog/qwen3/)** 系列模型的微调。
|
| 130 |
+
|
| 131 |
+
[25/04/21] 我们支持了 **[Muon](https://github.com/KellerJordan/Muon)** 优化器。详细用法请参照 [examples](examples/README_zh.md)。感谢 [@tianshijing](https://github.com/tianshijing) 的 PR。
|
| 132 |
+
|
| 133 |
+
[25/04/16] 我们支持了 **[InternVL3](https://huggingface.co/OpenGVLab/InternVL3-8B)** 模型的微调。查看 [PR #7258](https://github.com/hiyouga/LLaMA-Factory/pull/7258) 以使用。
|
| 134 |
+
|
| 135 |
+
[25/04/14] 我们支持了 **[GLM-Z1](https://huggingface.co/THUDM/GLM-Z1-9B-0414)** 和 **[Kimi-VL](https://huggingface.co/moonshotai/Kimi-VL-A3B-Instruct)** 模型的微调。
|
| 136 |
+
|
| 137 |
+
[25/04/06] 我们支持了 **[Llama 4](https://ai.meta.com/blog/llama-4-multimodal-intelligence/)** 模型的微调。查看 [PR #7611](https://github.com/hiyouga/LLaMA-Factory/pull/7611) 以使用。
|
| 138 |
+
|
| 139 |
+
<details><summary>展开日志</summary>
|
| 140 |
+
|
| 141 |
+
[25/03/31] 我们支持了 **[Qwen2.5 Omni](https://qwenlm.github.io/blog/qwen2.5-omni/)** 模型的微调。查看 [PR #7537](https://github.com/hiyouga/LLaMA-Factory/pull/7537) 以使用。
|
| 142 |
+
|
| 143 |
+
[25/03/15] 我们支持了 **[SGLang](https://github.com/sgl-project/sglang)** 推理后端,请使用 `infer_backend: sglang` 启用。
|
| 144 |
+
|
| 145 |
+
[25/03/12] 我们支持了 **[Gemma 3](https://huggingface.co/blog/gemma3)** 模型的微调。
|
| 146 |
+
|
| 147 |
+
[25/02/24] 我们宣布开源 **[EasyR1](https://github.com/hiyouga/EasyR1)**,一个高效可扩展的多模态强化学习框架,支持高效的 GRPO 训练。
|
| 148 |
+
|
| 149 |
+
[25/02/11] 我们支持了在导出模型时保存 **[Ollama](https://github.com/ollama/ollama)** 配置文件。详细用法请参照 [examples](examples/README_zh.md)。
|
| 150 |
+
|
| 151 |
+
[25/02/05] 我们支持了在语音理解任务上微调 **[Qwen2-Audio](Qwen/Qwen2-Audio-7B-Instruct)** 和 **[MiniCPM-o-2.6](https://huggingface.co/openbmb/MiniCPM-o-2_6)** 模型。
|
| 152 |
+
|
| 153 |
+
[25/01/31] 我们支持了 **[DeepSeek-R1](https://huggingface.co/deepseek-ai/DeepSeek-R1)** 和 **[Qwen2.5-VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)** 模型的微调。
|
| 154 |
+
|
| 155 |
+
[25/01/15] 我们支持了 **[APOLLO](https://arxiv.org/abs/2412.05270)** 优化器。详细用法请参照 [examples](examples/README_zh.md)。
|
| 156 |
+
|
| 157 |
+
[25/01/14] 我们支持了 **[MiniCPM-o-2.6](https://huggingface.co/openbmb/MiniCPM-o-2_6)** 和 **[MiniCPM-V-2.6](https://huggingface.co/openbmb/MiniCPM-V-2_6)** 模型的微调。 感谢 [@BUAADreamer](https://github.com/BUAADreamer) 的 PR.
|
| 158 |
+
|
| 159 |
+
[25/01/14] 我们支持了 **[InternLM 3](https://huggingface.co/collections/internlm/)** 模型的微调。感谢 [@hhaAndroid](https://github.com/hhaAndroid) 的 PR。
|
| 160 |
+
|
| 161 |
+
[25/01/10] 我们支持了 **[Phi-4](https://huggingface.co/microsoft/phi-4)** 模型的微调。
|
| 162 |
+
|
| 163 |
+
[24/12/21] 我们支持了使用 **[SwanLab](https://github.com/SwanHubX/SwanLab)** 跟踪与可视化实验。详细用法请参考 [此部分](#使用-swanlab-面板)。
|
| 164 |
+
|
| 165 |
+
[24/11/27] 我们支持了 **[Skywork-o1](https://huggingface.co/Skywork/Skywork-o1-Open-Llama-3.1-8B)** 模型的微调和 **[OpenO1](https://huggingface.co/datasets/O1-OPEN/OpenO1-SFT)** 数据集。
|
| 166 |
+
|
| 167 |
+
[24/10/09] 我们支持了从 **[魔乐社区](https://modelers.cn/models)** 下载预训练模型和数据集。详细用法请参照 [此教程](#从魔乐社区下载)。
|
| 168 |
+
|
| 169 |
+
[24/09/19] 我们支持了 **[Qwen2.5](https://qwenlm.github.io/blog/qwen2.5/)** 模型的微调。
|
| 170 |
+
|
| 171 |
+
[24/08/30] 我们支持了 **[Qwen2-VL](https://qwenlm.github.io/blog/qwen2-vl/)** 模型的微调。感谢 [@simonJJJ](https://github.com/simonJJJ) 的 PR。
|
| 172 |
+
|
| 173 |
+
[24/08/27] 我们支持了 **[Liger Kernel](https://github.com/linkedin/Liger-Kernel)**。请使用 `enable_liger_kernel: true` 来加速训练。
|
| 174 |
+
|
| 175 |
+
[24/08/09] 我们支持了 **[Adam-mini](https://github.com/zyushun/Adam-mini)** 优化器。详细用法请参照 [examples](examples/README_zh.md)。感谢 [@relic-yuexi](https://github.com/relic-yuexi) 的 PR。
|
| 176 |
+
|
| 177 |
+
[24/07/04] 我们支持了[无污染打包训练](https://github.com/MeetKai/functionary/tree/main/functionary/train/packing)。请使用 `neat_packing: true` 参数。感谢 [@chuan298](https://github.com/chuan298) 的 PR。
|
| 178 |
+
|
| 179 |
+
[24/06/16] 我们支持了 **[PiSSA](https://arxiv.org/abs/2404.02948)** 算法。详细用法请参照 [examples](examples/README_zh.md)。
|
| 180 |
+
|
| 181 |
+
[24/06/07] 我们支持了 **[Qwen2](https://qwenlm.github.io/blog/qwen2/)** 和 **[GLM-4](https://github.com/THUDM/GLM-4)** 模型的微调。
|
| 182 |
+
|
| 183 |
+
[24/05/26] 我们支持了 **[SimPO](https://arxiv.org/abs/2405.14734)** 偏好对齐算法。详细用法请参照 [examples](examples/README_zh.md)。
|
| 184 |
+
|
| 185 |
+
[24/05/20] 我们支持了 **PaliGemma** 系列模型的微调。注意 PaliGemma 是预训练模型,你需要使用 `paligemma` 模板进行微调使其获得对话能力。
|
| 186 |
+
|
| 187 |
+
[24/05/18] 我们支持了 **[KTO](https://arxiv.org/abs/2402.01306)** 偏好对齐算法。详细用法请参照 [examples](examples/README_zh.md)。
|
| 188 |
+
|
| 189 |
+
[24/05/14] 我们支持了昇腾 NPU 设备的训练和推理。详情请查阅[安装](#安装-llama-factory)部分。
|
| 190 |
+
|
| 191 |
+
[24/04/26] 我们支持了多模态模型 **LLaVA-1.5** 的微调。详细用法请参照 [examples](examples/README_zh.md)。
|
| 192 |
+
|
| 193 |
+
[24/04/22] 我们提供了在免费 T4 GPU 上微调 Llama-3 模型的 **[Colab 笔记本](https://colab.research.google.com/drive/1d5KQtbemerlSDSxZIfAaWXhKr30QypiK?usp=sharing)**。Hugging Face 社区公开了两个利用 LLaMA Factory 微调的 Llama-3 模型,详情请见 [Llama3-8B-Chinese-Chat](https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat) 和 [Llama3-Chinese](https://huggingface.co/zhichen/Llama3-Chinese)。
|
| 194 |
+
|
| 195 |
+
[24/04/21] 我们基于 [AstraMindAI 的仓库](https://github.com/astramind-ai/Mixture-of-depths)支持了 **[混合深度训练](https://arxiv.org/abs/2404.02258)**。详细用法请参照 [examples](examples/README_zh.md)。
|
| 196 |
+
|
| 197 |
+
[24/04/16] 我们支持了 **[BAdam](https://arxiv.org/abs/2404.02827)** 优化器。详细用法请参照 [examples](examples/README_zh.md)。
|
| 198 |
+
|
| 199 |
+
[24/04/16] 我们支持了 **[unsloth](https://github.com/unslothai/unsloth)** 的长序列训练(24GB 可训练 Llama-2-7B-56k)。该方法相比 FlashAttention-2 提供了 **117%** 的训��速度和 **50%** 的显存节约。更多数据请见[此页面](https://github.com/hiyouga/LLaMA-Factory/wiki/Performance-comparison)。
|
| 200 |
+
|
| 201 |
+
[24/03/31] 我们支持了 **[ORPO](https://arxiv.org/abs/2403.07691)**。详细用法请参照 [examples](examples/README_zh.md)。
|
| 202 |
+
|
| 203 |
+
[24/03/21] 我们的论文 "[LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models](https://arxiv.org/abs/2403.13372)" 可在 arXiv 上查看!
|
| 204 |
+
|
| 205 |
+
[24/03/20] 我们支持了能在 2x24GB GPU 上微调 70B 模型的 **FSDP+QLoRA**。详细用法请参照 [examples](examples/README_zh.md)。
|
| 206 |
+
|
| 207 |
+
[24/03/13] 我们支持了 **[LoRA+](https://arxiv.org/abs/2402.12354)**。详细用法请参照 [examples](examples/README_zh.md)。
|
| 208 |
+
|
| 209 |
+
[24/03/07] 我们支持了 **[GaLore](https://arxiv.org/abs/2403.03507)** 优化器。详细用法请参照 [examples](examples/README_zh.md)。
|
| 210 |
+
|
| 211 |
+
[24/03/07] 我们集成了 **[vLLM](https://github.com/vllm-project/vllm)** 以实现极速并发推理。请使用 `infer_backend: vllm` 来获得 **270%** 的推理速度。
|
| 212 |
+
|
| 213 |
+
[24/02/28] 我们支持了 **[DoRA](https://arxiv.org/abs/2402.09353)** 微调。请使用 `use_dora: true` 参数进行 DoRA 微调。
|
| 214 |
+
|
| 215 |
+
[24/02/15] 我们支持了 [LLaMA Pro](https://github.com/TencentARC/LLaMA-Pro) 提出的**块扩展**方法。详细用法请参照 [examples](examples/README_zh.md)。
|
| 216 |
+
|
| 217 |
+
[24/02/05] Qwen1.5(Qwen2 测试版)系列模型已在 LLaMA-Factory 中实现微调支持。详情请查阅该[博客页面](https://qwenlm.github.io/zh/blog/qwen1.5/)。
|
| 218 |
+
|
| 219 |
+
[24/01/18] 我们针对绝大多数模型实现了 **Agent 微调**,微调时指定 `dataset: glaive_toolcall_zh` 即可使模型获得工具调用能力。
|
| 220 |
+
|
| 221 |
+
[23/12/23] 我们针对 LLaMA, Mistral 和 Yi 模型支持了 **[unsloth](https://github.com/unslothai/unsloth)** 的 LoRA 训练加速。请使用 `use_unsloth: true` 参数启用 unsloth 优化。该方法可提供 **170%** 的训练速度,详情请查阅[此页面](https://github.com/hiyouga/LLaMA-Factory/wiki/Performance-comparison)。
|
| 222 |
+
|
| 223 |
+
[23/12/12] 我们支持了微调最新的混合专家模型 **[Mixtral 8x7B](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1)**。硬件需求请查阅[此处](#硬件依赖)。
|
| 224 |
+
|
| 225 |
+
[23/12/01] 我们支持了从 **[魔搭社区](https://modelscope.cn/models)** 下载预训练模型和数据集。详细用法请参照 [此教程](#从魔搭社区下载)。
|
| 226 |
+
|
| 227 |
+
[23/10/21] 我们支持了 **[NEFTune](https://arxiv.org/abs/2310.05914)** 训练技巧。请使用 `neftune_noise_alpha: 5` 参数启用 NEFTune。
|
| 228 |
+
|
| 229 |
+
[23/09/27] 我们针对 LLaMA 模型支持了 [LongLoRA](https://github.com/dvlab-research/LongLoRA) 提出的 **$S^2$-Attn**。请使用 `shift_attn: true` 参数以启用该功能。
|
| 230 |
+
|
| 231 |
+
[23/09/23] 我们在项目中集成了 MMLU、C-Eval 和 CMMLU 评估集。详细用法请参照 [examples](examples/README_zh.md)。
|
| 232 |
+
|
| 233 |
+
[23/09/10] 我们支持了 **[FlashAttention-2](https://github.com/Dao-AILab/flash-attention)**。如果您使用的是 RTX4090、A100 或 H100 GPU,请使用 `flash_attn: fa2` 参数以启用 FlashAttention-2。
|
| 234 |
+
|
| 235 |
+
[23/08/12] 我们支持了 **RoPE 插值**来扩展 LLaMA 模型的上下文长度。请使用 `rope_scaling: linear` 参数训练模型或使用 `rope_scaling: dynamic` 参数评估模型。
|
| 236 |
+
|
| 237 |
+
[23/08/11] 我们支持了指令模型的 **[DPO 训练](https://arxiv.org/abs/2305.18290)**。详细用法请参照 [examples](examples/README_zh.md)。
|
| 238 |
+
|
| 239 |
+
[23/07/31] 我们支持了**数据流式加载**。请使用 `streaming: true` 和 `max_steps: 10000` 参数来流式加载数据集。
|
| 240 |
+
|
| 241 |
+
[23/07/29] 我们在 Hugging Face 发布了两个 13B 指令微调模型。详细内容请查阅我们的 Hugging Face 项目([LLaMA-2](https://huggingface.co/hiyouga/Llama-2-Chinese-13b-chat) / [Baichuan](https://huggingface.co/hiyouga/Baichuan-13B-sft))。
|
| 242 |
+
|
| 243 |
+
[23/07/18] 我们开发了支持训练和测试的**浏览器一体化界面**。请使用 `train_web.py` 在您的浏览器中微调模型。感谢 [@KanadeSiina](https://github.com/KanadeSiina) 和 [@codemayq](https://github.com/codemayq) 在该功能开发中付出的努力。
|
| 244 |
+
|
| 245 |
+
[23/07/09] 我们开源了 **[FastEdit](https://github.com/hiyouga/FastEdit)** ⚡🩹,一个简单易用的、能迅速编辑大模型事实记忆的工具包。如果您感兴趣请关注我们的 [FastEdit](https://github.com/hiyouga/FastEdit) 项目。
|
| 246 |
+
|
| 247 |
+
[23/06/29] 我们提供了一个**可复现的**指令模型微调示例,详细内容请查阅 [Baichuan-7B-sft](https://huggingface.co/hiyouga/Baichuan-7B-sft)。
|
| 248 |
+
|
| 249 |
+
[23/06/22] 我们对齐了[示例 API](src/api_demo.py) 与 [OpenAI API](https://platform.openai.com/docs/api-reference/chat) 的格式,您可以将微调模型接入**任意基于 ChatGPT 的应用**中。
|
| 250 |
+
|
| 251 |
+
[23/06/03] 我们实现了 4 比特的 LoRA 训练(也称 **[QLoRA](https://github.com/artidoro/qlora)**)。详细用法请参照 [examples](examples/README_zh.md)。
|
| 252 |
+
|
| 253 |
+
</details>
|
| 254 |
+
|
| 255 |
+
> [!TIP]
|
| 256 |
+
> 如果您无法使用最新的功能,请尝试重新拉取代码并再次安装 LLaMA-Factory。
|
| 257 |
+
|
| 258 |
+
## 模型
|
| 259 |
+
|
| 260 |
+
| 模型名 | 参数量 | Template |
|
| 261 |
+
| ----------------------------------------------------------------- | -------------------------------- | ------------------- |
|
| 262 |
+
| [Baichuan 2](https://huggingface.co/baichuan-inc) | 7B/13B | baichuan2 |
|
| 263 |
+
| [BLOOM/BLOOMZ](https://huggingface.co/bigscience) | 560M/1.1B/1.7B/3B/7.1B/176B | - |
|
| 264 |
+
| [ChatGLM3](https://huggingface.co/THUDM) | 6B | chatglm3 |
|
| 265 |
+
| [Command R](https://huggingface.co/CohereForAI) | 35B/104B | cohere |
|
| 266 |
+
| [DeepSeek (Code/MoE)](https://huggingface.co/deepseek-ai) | 7B/16B/67B/236B | deepseek |
|
| 267 |
+
| [DeepSeek 2.5/3](https://huggingface.co/deepseek-ai) | 236B/671B | deepseek3 |
|
| 268 |
+
| [DeepSeek R1 (Distill)](https://huggingface.co/deepseek-ai) | 1.5B/7B/8B/14B/32B/70B/671B | deepseekr1 |
|
| 269 |
+
| [Falcon](https://huggingface.co/tiiuae) | 7B/11B/40B/180B | falcon |
|
| 270 |
+
| [Falcon-H1](https://huggingface.co/tiiuae) | 0.5B/1.5B/3B/7B/34B | falcon_h1 |
|
| 271 |
+
| [Gemma/Gemma 2/CodeGemma](https://huggingface.co/google) | 2B/7B/9B/27B | gemma/gemma2 |
|
| 272 |
+
| [Gemma 3/Gemma 3n](https://huggingface.co/google) | 1B/4B/6B/8B/12B/27B | gemma3/gemma3n |
|
| 273 |
+
| [GLM-4/GLM-4-0414/GLM-Z1](https://huggingface.co/THUDM) | 9B/32B | glm4/glmz1 |
|
| 274 |
+
| [GLM-4.1V](https://huggingface.co/THUDM)* | 9B | glm4v |
|
| 275 |
+
| [GPT-2](https://huggingface.co/openai-community) | 0.1B/0.4B/0.8B/1.5B | - |
|
| 276 |
+
| [Granite 3.0-3.3](https://huggingface.co/ibm-granite) | 1B/2B/3B/8B | granite3 |
|
| 277 |
+
| [Hunyuan](https://huggingface.co/tencent/) | 7B | hunyuan |
|
| 278 |
+
| [Index](https://huggingface.co/IndexTeam) | 1.9B | index |
|
| 279 |
+
| [InternLM 2-3](https://huggingface.co/internlm) | 7B/8B/20B | intern2 |
|
| 280 |
+
| [InternVL 2.5-3](https://huggingface.co/OpenGVLab) | 1B/2B/8B/14B/38B/78B | intern_vl |
|
| 281 |
+
| [Kimi-VL](https://huggingface.co/moonshotai) | 16B | kimi_vl |
|
| 282 |
+
| [Llama](https://github.com/facebookresearch/llama) | 7B/13B/33B/65B | - |
|
| 283 |
+
| [Llama 2](https://huggingface.co/meta-llama) | 7B/13B/70B | llama2 |
|
| 284 |
+
| [Llama 3-3.3](https://huggingface.co/meta-llama) | 1B/3B/8B/70B | llama3 |
|
| 285 |
+
| [Llama 4](https://huggingface.co/meta-llama) | 109B/402B | llama4 |
|
| 286 |
+
| [Llama 3.2 Vision](https://huggingface.co/meta-llama) | 11B/90B | mllama |
|
| 287 |
+
| [LLaVA-1.5](https://huggingface.co/llava-hf) | 7B/13B | llava |
|
| 288 |
+
| [LLaVA-NeXT](https://huggingface.co/llava-hf) | 7B/8B/13B/34B/72B/110B | llava_next |
|
| 289 |
+
| [LLaVA-NeXT-Video](https://huggingface.co/llava-hf) | 7B/34B | llava_next_video |
|
| 290 |
+
| [MiMo](https://huggingface.co/XiaomiMiMo) | 7B | mimo |
|
| 291 |
+
| [MiniCPM](https://huggingface.co/openbmb) | 0.5B/1B/2B/4B/8B | cpm/cpm3/cpm4 |
|
| 292 |
+
| [MiniCPM-o-2.6/MiniCPM-V-2.6](https://huggingface.co/openbmb) | 8B | minicpm_o/minicpm_v |
|
| 293 |
+
| [Ministral/Mistral-Nemo](https://huggingface.co/mistralai) | 8B/12B | ministral |
|
| 294 |
+
| [Mistral/Mixtral](https://huggingface.co/mistralai) | 7B/8x7B/8x22B | mistral |
|
| 295 |
+
| [Mistral Small](https://huggingface.co/mistralai) | 24B | mistral_small |
|
| 296 |
+
| [OLMo](https://huggingface.co/allenai) | 1B/7B | - |
|
| 297 |
+
| [PaliGemma/PaliGemma2](https://huggingface.co/google) | 3B/10B/28B | paligemma |
|
| 298 |
+
| [Phi-1.5/Phi-2](https://huggingface.co/microsoft) | 1.3B/2.7B | - |
|
| 299 |
+
| [Phi-3/Phi-3.5](https://huggingface.co/microsoft) | 4B/14B | phi |
|
| 300 |
+
| [Phi-3-small](https://huggingface.co/microsoft) | 7B | phi_small |
|
| 301 |
+
| [Phi-4](https://huggingface.co/microsoft) | 14B | phi4 |
|
| 302 |
+
| [Pixtral](https://huggingface.co/mistralai) | 12B | pixtral |
|
| 303 |
+
| [Qwen (1-2.5) (Code/Math/MoE/QwQ)](https://huggingface.co/Qwen) | 0.5B/1.5B/3B/7B/14B/32B/72B/110B | qwen |
|
| 304 |
+
| [Qwen3 (MoE)](https://huggingface.co/Qwen) | 0.6B/1.7B/4B/8B/14B/32B/235B | qwen3 |
|
| 305 |
+
| [Qwen2-Audio](https://huggingface.co/Qwen) | 7B | qwen2_audio |
|
| 306 |
+
| [Qwen2.5-Omni](https://huggingface.co/Qwen) | 3B/7B | qwen2_omni |
|
| 307 |
+
| [Qwen2-VL/Qwen2.5-VL/QVQ](https://huggingface.co/Qwen) | 2B/3B/7B/32B/72B | qwen2_vl |
|
| 308 |
+
| [Seed Coder](https://huggingface.co/ByteDance-Seed) | 8B | seed_coder |
|
| 309 |
+
| [Skywork o1](https://huggingface.co/Skywork) | 8B | skywork_o1 |
|
| 310 |
+
| [StarCoder 2](https://huggingface.co/bigcode) | 3B/7B/15B | - |
|
| 311 |
+
| [TeleChat2](https://huggingface.co/Tele-AI) | 3B/7B/35B/115B | telechat2 |
|
| 312 |
+
| [XVERSE](https://huggingface.co/xverse) | 7B/13B/65B | xverse |
|
| 313 |
+
| [Yi/Yi-1.5 (Code)](https://huggingface.co/01-ai) | 1.5B/6B/9B/34B | yi |
|
| 314 |
+
| [Yi-VL](https://huggingface.co/01-ai) | 6B/34B | yi_vl |
|
| 315 |
+
| [Yuan 2](https://huggingface.co/IEITYuan) | 2B/51B/102B | yuan |
|
| 316 |
+
|
| 317 |
+
> [!NOTE]
|
| 318 |
+
> 对于所有“基座”(Base)模型,`template` 参数可以是 `default`, `alpaca`, `vicuna` 等任意值。但“对话”(Instruct/Chat)模型请务必使用**对应的模板**。
|
| 319 |
+
>
|
| 320 |
+
> 请务必在训练和推理时采用**完全一致**的模板。
|
| 321 |
+
>
|
| 322 |
+
> \*:您需要从 main 分支安装 `transformers` 并使用 `DISABLE_VERSION_CHECK=1` 来跳过版本检查。
|
| 323 |
+
>
|
| 324 |
+
> \*\*:您需要安装特定版本的 `transformers` 以使用该模型。
|
| 325 |
+
|
| 326 |
+
项目所支持模型的完整列表请参阅 [constants.py](src/llamafactory/extras/constants.py)。
|
| 327 |
+
|
| 328 |
+
您也可以在 [template.py](src/llamafactory/data/template.py) 中添加自己的对话模板。
|
| 329 |
+
|
| 330 |
+
## 训练方法
|
| 331 |
+
|
| 332 |
+
| 方法 | 全参数训练 | 部分参数训练 | LoRA | QLoRA |
|
| 333 |
+
| --------------------- | ------------------ | ------------------ | ------------------ | ------------------ |
|
| 334 |
+
| 预训练 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 335 |
+
| 指令监督微调 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 336 |
+
| 奖励模型训练 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 337 |
+
| PPO 训练 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 338 |
+
| DPO 训练 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 339 |
+
| KTO 训练 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 340 |
+
| ORPO 训练 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 341 |
+
| SimPO 训练 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
| 342 |
+
|
| 343 |
+
> [!TIP]
|
| 344 |
+
> 有关 PPO 的实现细节,请参考[此博客](https://newfacade.github.io/notes-on-reinforcement-learning/17-ppo-trl.html)。
|
| 345 |
+
|
| 346 |
+
## 数据集
|
| 347 |
+
|
| 348 |
+
<details><summary>预训练数据集</summary>
|
| 349 |
+
|
| 350 |
+
- [Wiki Demo (en)](data/wiki_demo.txt)
|
| 351 |
+
- [RefinedWeb (en)](https://huggingface.co/datasets/tiiuae/falcon-refinedweb)
|
| 352 |
+
- [RedPajama V2 (en)](https://huggingface.co/datasets/togethercomputer/RedPajama-Data-V2)
|
| 353 |
+
- [Wikipedia (en)](https://huggingface.co/datasets/olm/olm-wikipedia-20221220)
|
| 354 |
+
- [Wikipedia (zh)](https://huggingface.co/datasets/pleisto/wikipedia-cn-20230720-filtered)
|
| 355 |
+
- [Pile (en)](https://huggingface.co/datasets/EleutherAI/pile)
|
| 356 |
+
- [SkyPile (zh)](https://huggingface.co/datasets/Skywork/SkyPile-150B)
|
| 357 |
+
- [FineWeb (en)](https://huggingface.co/datasets/HuggingFaceFW/fineweb)
|
| 358 |
+
- [FineWeb-Edu (en)](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu)
|
| 359 |
+
- [The Stack (en)](https://huggingface.co/datasets/bigcode/the-stack)
|
| 360 |
+
- [StarCoder (en)](https://huggingface.co/datasets/bigcode/starcoderdata)
|
| 361 |
+
|
| 362 |
+
</details>
|
| 363 |
+
|
| 364 |
+
<details><summary>指令微调数据集</summary>
|
| 365 |
+
|
| 366 |
+
- [Identity (en&zh)](data/identity.json)
|
| 367 |
+
- [Stanford Alpaca (en)](https://github.com/tatsu-lab/stanford_alpaca)
|
| 368 |
+
- [Stanford Alpaca (zh)](https://github.com/ymcui/Chinese-LLaMA-Alpaca-3)
|
| 369 |
+
- [Alpaca GPT4 (en&zh)](https://github.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM)
|
| 370 |
+
- [Glaive Function Calling V2 (en&zh)](https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2)
|
| 371 |
+
- [LIMA (en)](https://huggingface.co/datasets/GAIR/lima)
|
| 372 |
+
- [Guanaco Dataset (multilingual)](https://huggingface.co/datasets/JosephusCheung/GuanacoDataset)
|
| 373 |
+
- [BELLE 2M (zh)](https://huggingface.co/datasets/BelleGroup/train_2M_CN)
|
| 374 |
+
- [BELLE 1M (zh)](https://huggingface.co/datasets/BelleGroup/train_1M_CN)
|
| 375 |
+
- [BELLE 0.5M (zh)](https://huggingface.co/datasets/BelleGroup/train_0.5M_CN)
|
| 376 |
+
- [BELLE Dialogue 0.4M (zh)](https://huggingface.co/datasets/BelleGroup/generated_chat_0.4M)
|
| 377 |
+
- [BELLE School Math 0.25M (zh)](https://huggingface.co/datasets/BelleGroup/school_math_0.25M)
|
| 378 |
+
- [BELLE Multiturn Chat 0.8M (zh)](https://huggingface.co/datasets/BelleGroup/multiturn_chat_0.8M)
|
| 379 |
+
- [UltraChat (en)](https://github.com/thunlp/UltraChat)
|
| 380 |
+
- [OpenPlatypus (en)](https://huggingface.co/datasets/garage-bAInd/Open-Platypus)
|
| 381 |
+
- [CodeAlpaca 20k (en)](https://huggingface.co/datasets/sahil2801/CodeAlpaca-20k)
|
| 382 |
+
- [Alpaca CoT (multilingual)](https://huggingface.co/datasets/QingyiSi/Alpaca-CoT)
|
| 383 |
+
- [OpenOrca (en)](https://huggingface.co/datasets/Open-Orca/OpenOrca)
|
| 384 |
+
- [SlimOrca (en)](https://huggingface.co/datasets/Open-Orca/SlimOrca)
|
| 385 |
+
- [MathInstruct (en)](https://huggingface.co/datasets/TIGER-Lab/MathInstruct)
|
| 386 |
+
- [Firefly 1.1M (zh)](https://huggingface.co/datasets/YeungNLP/firefly-train-1.1M)
|
| 387 |
+
- [Wiki QA (en)](https://huggingface.co/datasets/wiki_qa)
|
| 388 |
+
- [Web QA (zh)](https://huggingface.co/datasets/suolyer/webqa)
|
| 389 |
+
- [WebNovel (zh)](https://huggingface.co/datasets/zxbsmk/webnovel_cn)
|
| 390 |
+
- [Nectar (en)](https://huggingface.co/datasets/berkeley-nest/Nectar)
|
| 391 |
+
- [deepctrl (en&zh)](https://www.modelscope.cn/datasets/deepctrl/deepctrl-sft-data)
|
| 392 |
+
- [Advertise Generating (zh)](https://huggingface.co/datasets/HasturOfficial/adgen)
|
| 393 |
+
- [ShareGPT Hyperfiltered (en)](https://huggingface.co/datasets/totally-not-an-llm/sharegpt-hyperfiltered-3k)
|
| 394 |
+
- [ShareGPT4 (en&zh)](https://huggingface.co/datasets/shibing624/sharegpt_gpt4)
|
| 395 |
+
- [UltraChat 200k (en)](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k)
|
| 396 |
+
- [AgentInstruct (en)](https://huggingface.co/datasets/THUDM/AgentInstruct)
|
| 397 |
+
- [LMSYS Chat 1M (en)](https://huggingface.co/datasets/lmsys/lmsys-chat-1m)
|
| 398 |
+
- [Evol Instruct V2 (en)](https://huggingface.co/datasets/WizardLM/WizardLM_evol_instruct_V2_196k)
|
| 399 |
+
- [Cosmopedia (en)](https://huggingface.co/datasets/HuggingFaceTB/cosmopedia)
|
| 400 |
+
- [STEM (zh)](https://huggingface.co/datasets/hfl/stem_zh_instruction)
|
| 401 |
+
- [Ruozhiba (zh)](https://huggingface.co/datasets/hfl/ruozhiba_gpt4_turbo)
|
| 402 |
+
- [Neo-sft (zh)](https://huggingface.co/datasets/m-a-p/neo_sft_phase2)
|
| 403 |
+
- [Magpie-Pro-300K-Filtered (en)](https://huggingface.co/datasets/Magpie-Align/Magpie-Pro-300K-Filtered)
|
| 404 |
+
- [Magpie-ultra-v0.1 (en)](https://huggingface.co/datasets/argilla/magpie-ultra-v0.1)
|
| 405 |
+
- [WebInstructSub (en)](https://huggingface.co/datasets/TIGER-Lab/WebInstructSub)
|
| 406 |
+
- [OpenO1-SFT (en&zh)](https://huggingface.co/datasets/O1-OPEN/OpenO1-SFT)
|
| 407 |
+
- [Open-Thoughts (en)](https://huggingface.co/datasets/open-thoughts/OpenThoughts-114k)
|
| 408 |
+
- [Open-R1-Math (en)](https://huggingface.co/datasets/open-r1/OpenR1-Math-220k)
|
| 409 |
+
- [Chinese-DeepSeek-R1-Distill (zh)](https://huggingface.co/datasets/Congliu/Chinese-DeepSeek-R1-Distill-data-110k-SFT)
|
| 410 |
+
- [LLaVA mixed (en&zh)](https://huggingface.co/datasets/BUAADreamer/llava-en-zh-300k)
|
| 411 |
+
- [Pokemon-gpt4o-captions (en&zh)](https://huggingface.co/datasets/jugg1024/pokemon-gpt4o-captions)
|
| 412 |
+
- [Open Assistant (de)](https://huggingface.co/datasets/mayflowergmbh/oasst_de)
|
| 413 |
+
- [Dolly 15k (de)](https://huggingface.co/datasets/mayflowergmbh/dolly-15k_de)
|
| 414 |
+
- [Alpaca GPT4 (de)](https://huggingface.co/datasets/mayflowergmbh/alpaca-gpt4_de)
|
| 415 |
+
- [OpenSchnabeltier (de)](https://huggingface.co/datasets/mayflowergmbh/openschnabeltier_de)
|
| 416 |
+
- [Evol Instruct (de)](https://huggingface.co/datasets/mayflowergmbh/evol-instruct_de)
|
| 417 |
+
- [Dolphin (de)](https://huggingface.co/datasets/mayflowergmbh/dolphin_de)
|
| 418 |
+
- [Booksum (de)](https://huggingface.co/datasets/mayflowergmbh/booksum_de)
|
| 419 |
+
- [Airoboros (de)](https://huggingface.co/datasets/mayflowergmbh/airoboros-3.0_de)
|
| 420 |
+
- [Ultrachat (de)](https://huggingface.co/datasets/mayflowergmbh/ultra-chat_de)
|
| 421 |
+
|
| 422 |
+
</details>
|
| 423 |
+
|
| 424 |
+
<details><summary>偏好数据集</summary>
|
| 425 |
+
|
| 426 |
+
- [DPO mixed (en&zh)](https://huggingface.co/datasets/hiyouga/DPO-En-Zh-20k)
|
| 427 |
+
- [UltraFeedback (en)](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized)
|
| 428 |
+
- [COIG-P (zh)](https://huggingface.co/datasets/m-a-p/COIG-P)
|
| 429 |
+
- [RLHF-V (en)](https://huggingface.co/datasets/openbmb/RLHF-V-Dataset)
|
| 430 |
+
- [VLFeedback (en)](https://huggingface.co/datasets/Zhihui/VLFeedback)
|
| 431 |
+
- [RLAIF-V (en)](https://huggingface.co/datasets/openbmb/RLAIF-V-Dataset)
|
| 432 |
+
- [Orca DPO Pairs (en)](https://huggingface.co/datasets/Intel/orca_dpo_pairs)
|
| 433 |
+
- [HH-RLHF (en)](https://huggingface.co/datasets/Anthropic/hh-rlhf)
|
| 434 |
+
- [Nectar (en)](https://huggingface.co/datasets/berkeley-nest/Nectar)
|
| 435 |
+
- [Orca DPO (de)](https://huggingface.co/datasets/mayflowergmbh/intel_orca_dpo_pairs_de)
|
| 436 |
+
- [KTO mixed (en)](https://huggingface.co/datasets/argilla/kto-mix-15k)
|
| 437 |
+
|
| 438 |
+
</details>
|
| 439 |
+
|
| 440 |
+
部分数据集的使用需要确认,我们推荐使用下述命令登录您的 Hugging Face 账户。
|
| 441 |
+
|
| 442 |
+
```bash
|
| 443 |
+
pip install --upgrade huggingface_hub
|
| 444 |
+
huggingface-cli login
|
| 445 |
+
```
|
| 446 |
+
|
| 447 |
+
## 软硬件依赖
|
| 448 |
+
|
| 449 |
+
| 必需项 | 至少 | 推荐 |
|
| 450 |
+
| ------------ | ------- | --------- |
|
| 451 |
+
| python | 3.9 | 3.10 |
|
| 452 |
+
| torch | 2.0.0 | 2.6.0 |
|
| 453 |
+
| torchvision | 0.15.0 | 0.21.0 |
|
| 454 |
+
| transformers | 4.49.0 | 4.50.0 |
|
| 455 |
+
| datasets | 2.16.0 | 3.2.0 |
|
| 456 |
+
| accelerate | 0.34.0 | 1.2.1 |
|
| 457 |
+
| peft | 0.14.0 | 0.15.1 |
|
| 458 |
+
| trl | 0.8.6 | 0.9.6 |
|
| 459 |
+
|
| 460 |
+
| 可选项 | 至少 | 推荐 |
|
| 461 |
+
| ------------ | ------- | --------- |
|
| 462 |
+
| CUDA | 11.6 | 12.2 |
|
| 463 |
+
| deepspeed | 0.10.0 | 0.16.4 |
|
| 464 |
+
| bitsandbytes | 0.39.0 | 0.43.1 |
|
| 465 |
+
| vllm | 0.4.3 | 0.8.2 |
|
| 466 |
+
| flash-attn | 2.5.6 | 2.7.2 |
|
| 467 |
+
|
| 468 |
+
### 硬件依赖
|
| 469 |
+
|
| 470 |
+
\* *估算值*
|
| 471 |
+
|
| 472 |
+
| 方法 | 精度 | 7B | 14B | 30B | 70B | `x`B |
|
| 473 |
+
| ------------------------------- | ---- | ----- | ----- | ----- | ------ | ------- |
|
| 474 |
+
| Full (`bf16` or `fp16`) | 32 | 120GB | 240GB | 600GB | 1200GB | `18x`GB |
|
| 475 |
+
| Full (`pure_bf16`) | 16 | 60GB | 120GB | 300GB | 600GB | `8x`GB |
|
| 476 |
+
| Freeze/LoRA/GaLore/APOLLO/BAdam | 16 | 16GB | 32GB | 64GB | 160GB | `2x`GB |
|
| 477 |
+
| QLoRA | 8 | 10GB | 20GB | 40GB | 80GB | `x`GB |
|
| 478 |
+
| QLoRA | 4 | 6GB | 12GB | 24GB | 48GB | `x/2`GB |
|
| 479 |
+
| QLoRA | 2 | 4GB | 8GB | 16GB | 24GB | `x/4`GB |
|
| 480 |
+
|
| 481 |
+
## 如何使用
|
| 482 |
+
|
| 483 |
+
### 安装 LLaMA Factory
|
| 484 |
+
|
| 485 |
+
> [!IMPORTANT]
|
| 486 |
+
> 此步骤为必需。
|
| 487 |
+
|
| 488 |
+
#### 从源码安装
|
| 489 |
+
|
| 490 |
+
```bash
|
| 491 |
+
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
|
| 492 |
+
cd LLaMA-Factory
|
| 493 |
+
pip install -e ".[torch,metrics]" --no-build-isolation
|
| 494 |
+
```
|
| 495 |
+
|
| 496 |
+
可选的额外依赖项:torch、torch-npu、metrics、deepspeed、liger-kernel、bitsandbytes、hqq、eetq、gptq、aqlm、vllm、sglang、galore、apollo、badam、adam-mini、qwen、minicpm_v、openmind、swanlab、dev
|
| 497 |
+
|
| 498 |
+
#### 从镜像安装
|
| 499 |
+
|
| 500 |
+
```bash
|
| 501 |
+
docker run -it --rm --gpus=all --ipc=host hiyouga/llamafactory:latest
|
| 502 |
+
```
|
| 503 |
+
|
| 504 |
+
该镜像基于 Ubuntu 22.04(x86\_64)、CUDA 12.4、Python 3.11、PyTorch 2.6.0 和 Flash-attn 2.7.4 构建。
|
| 505 |
+
|
| 506 |
+
查看全部镜像:https://hub.docker.com/r/hiyouga/llamafactory/tags
|
| 507 |
+
|
| 508 |
+
请参阅[构建 Docker](#构建-docker) 来重新构建镜像。
|
| 509 |
+
|
| 510 |
+
<details><summary>使用 <b>uv</b> 构建虚拟环境</summary>
|
| 511 |
+
|
| 512 |
+
使用 [uv](https://github.com/astral-sh/uv) 创建隔离的 Python 环境:
|
| 513 |
+
|
| 514 |
+
```bash
|
| 515 |
+
uv sync --extra torch --extra metrics --prerelease=allow
|
| 516 |
+
```
|
| 517 |
+
|
| 518 |
+
在环境中运行 LLaMA-Factory:
|
| 519 |
+
|
| 520 |
+
```bash
|
| 521 |
+
uv run --prerelease=allow llamafactory-cli train examples/train_lora/llama3_lora_pretrain.yaml
|
| 522 |
+
```
|
| 523 |
+
|
| 524 |
+
</details>
|
| 525 |
+
|
| 526 |
+
<details><summary>Windows 用户指南</summary>
|
| 527 |
+
|
| 528 |
+
#### 安装 PyTorch
|
| 529 |
+
|
| 530 |
+
Windows 平台需要额外手动安装 GPU 版本的 PyTorch 依赖包,您可以参考[官方网站](https://pytorch.org/get-started/locally/)和以下命令安装并测试 PyTorch 是否正确安装。
|
| 531 |
+
|
| 532 |
+
```bash
|
| 533 |
+
pip uninstall torch torchvision torchaudio
|
| 534 |
+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
|
| 535 |
+
python -c "import torch; print(torch.cuda.is_available())"
|
| 536 |
+
```
|
| 537 |
+
|
| 538 |
+
如果看到 `True` 则说明安装成功。
|
| 539 |
+
|
| 540 |
+
若遇到类似 `Can't pickle local object` 的报错,请设置 `dataloader_num_workers: 0`。
|
| 541 |
+
|
| 542 |
+
#### 安装 BitsAndBytes
|
| 543 |
+
|
| 544 |
+
如果要在 Windows 平台上开启量化 LoRA(QLoRA),需要安装预编译的 `bitsandbytes` 库, 支持 CUDA 11.1 到 12.2, 请根据您的 CUDA 版本情况选择适合的[发布版本](https://github.com/jllllll/bitsandbytes-windows-webui/releases/tag/wheels)。
|
| 545 |
+
|
| 546 |
+
```bash
|
| 547 |
+
pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.2.post2-py3-none-win_amd64.whl
|
| 548 |
+
```
|
| 549 |
+
|
| 550 |
+
#### 安装 Flash Attention-2
|
| 551 |
+
|
| 552 |
+
如果要在 Windows 平台上开启 FlashAttention-2,请使用 [flash-attention-windows-wheel](https://huggingface.co/lldacing/flash-attention-windows-wheel) 中的脚本自行编译与安装。
|
| 553 |
+
|
| 554 |
+
</details>
|
| 555 |
+
|
| 556 |
+
<details><summary>昇腾 NPU 用户指南</summary>
|
| 557 |
+
|
| 558 |
+
在昇腾 NPU 设备上安装 LLaMA Factory 时,请升级 Python 到 3.10 及以上,并需要指定额外依赖项,使用 `pip install -e ".[torch-npu,metrics]"` 命令安装。此外,还需要安装 **[Ascend CANN Toolkit 与 Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**,安装方法请参考[安装教程](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC2alpha002/quickstart/quickstart/quickstart_18_0004.html)或使用以下命令:
|
| 559 |
+
|
| 560 |
+
```bash
|
| 561 |
+
# 请替换 URL 为 CANN 版本和设备型号对应的 URL
|
| 562 |
+
# 安装 CANN Toolkit
|
| 563 |
+
wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C17SPC701/Ascend-cann-toolkit_8.0.RC1.alpha001_linux-"$(uname -i)".run
|
| 564 |
+
bash Ascend-cann-toolkit_8.0.RC1.alpha001_linux-"$(uname -i)".run --install
|
| 565 |
+
|
| 566 |
+
# 安装 CANN Kernels
|
| 567 |
+
wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C17SPC701/Ascend-cann-kernels-910b_8.0.RC1.alpha001_linux.run
|
| 568 |
+
bash Ascend-cann-kernels-910b_8.0.RC1.alpha001_linux.run --install
|
| 569 |
+
|
| 570 |
+
# 设置环境变量
|
| 571 |
+
source /usr/local/Ascend/ascend-toolkit/set_env.sh
|
| 572 |
+
```
|
| 573 |
+
|
| 574 |
+
| 依赖项 | 至少 | 推荐 |
|
| 575 |
+
| ------------ | ------- | -------------- |
|
| 576 |
+
| CANN | 8.0.RC1 | 8.0.0.alpha002 |
|
| 577 |
+
| torch | 2.1.0 | 2.4.0 |
|
| 578 |
+
| torch-npu | 2.1.0 | 2.4.0.post2 |
|
| 579 |
+
| deepspeed | 0.13.2 | 0.13.2 |
|
| 580 |
+
| vllm-ascend | - | 0.7.3 |
|
| 581 |
+
|
| 582 |
+
请使用 `ASCEND_RT_VISIBLE_DEVICES` 而非 `CUDA_VISIBLE_DEVICES` 来指定运算设备。
|
| 583 |
+
|
| 584 |
+
如果遇到无法正常推理的情况,请尝试设置 `do_sample: false`。
|
| 585 |
+
|
| 586 |
+
下载预构建 Docker 镜像:[32GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/130.html) | [64GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/131.html)
|
| 587 |
+
|
| 588 |
+
#### 安装 BitsAndBytes
|
| 589 |
+
|
| 590 |
+
如果要在 Ascend NPU 上进行基于 bitsandbytes 的 QLoRA 量化微调,请执行如下步骤:
|
| 591 |
+
|
| 592 |
+
1. 手动编译 bitsandbytes:请参考[安装文档](https://huggingface.co/docs/bitsandbytes/installation?backend=Ascend+NPU&platform=Ascend+NPU)完成 NPU 版的 bitsandbytes 安装,编译要求环境 cmake 版本不低于 3.22.1,g++ 版本不低于 12.x。
|
| 593 |
+
|
| 594 |
+
```bash
|
| 595 |
+
# 从源码安装 bitsandbytes
|
| 596 |
+
# 克隆 bitsandbytes 仓库, Ascend NPU 目前在 multi-backend-refactor 中支持
|
| 597 |
+
git clone -b multi-backend-refactor https://github.com/bitsandbytes-foundation/bitsandbytes.git
|
| 598 |
+
cd bitsandbytes/
|
| 599 |
+
|
| 600 |
+
# 安装依赖
|
| 601 |
+
pip install -r requirements-dev.txt
|
| 602 |
+
|
| 603 |
+
# 安装编译工具依赖,该步骤在不同系统上命令有所不同,供参考
|
| 604 |
+
apt-get install -y build-essential cmake
|
| 605 |
+
|
| 606 |
+
# 编译 & 安装
|
| 607 |
+
cmake -DCOMPUTE_BACKEND=npu -S .
|
| 608 |
+
make
|
| 609 |
+
pip install .
|
| 610 |
+
```
|
| 611 |
+
|
| 612 |
+
2. 安装 transformers 的 main 分支版本。
|
| 613 |
+
|
| 614 |
+
```bash
|
| 615 |
+
git clone -b main https://github.com/huggingface/transformers.git
|
| 616 |
+
cd transformers
|
| 617 |
+
pip install .
|
| 618 |
+
```
|
| 619 |
+
|
| 620 |
+
3. 在训练参数中设置 `double_quantization: false`,可参考[示例](examples/train_qlora/llama3_lora_sft_bnb_npu.yaml)。
|
| 621 |
+
|
| 622 |
+
</details>
|
| 623 |
+
|
| 624 |
+
### 数据准备
|
| 625 |
+
|
| 626 |
+
关于数据集文件的格式,请参考 [data/README_zh.md](data/README_zh.md) 的内容。你可以使用 HuggingFace / ModelScope / Modelers 上的数据集或加载本地数据集。
|
| 627 |
+
|
| 628 |
+
> [!NOTE]
|
| 629 |
+
> 使用自定义数据集时,请更新 `data/dataset_info.json` 文件。
|
| 630 |
+
|
| 631 |
+
您也可以使用 **[Easy Dataset](https://github.com/ConardLi/easy-dataset)** 或 **[GraphGen](https://github.com/open-sciencelab/GraphGen)** 构建用于微调的合成数据。
|
| 632 |
+
|
| 633 |
+
### 快速开始
|
| 634 |
+
|
| 635 |
+
下面三行命令分别对 Llama3-8B-Instruct 模型进行 LoRA **微调**、**推理**和**合并**。
|
| 636 |
+
|
| 637 |
+
```bash
|
| 638 |
+
llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
|
| 639 |
+
llamafactory-cli chat examples/inference/llama3_lora_sft.yaml
|
| 640 |
+
llamafactory-cli export examples/merge_lora/llama3_lora_sft.yaml
|
| 641 |
+
```
|
| 642 |
+
|
| 643 |
+
高级用法请参考 [examples/README_zh.md](examples/README_zh.md)(包括多 GPU 微调)。
|
| 644 |
+
|
| 645 |
+
> [!TIP]
|
| 646 |
+
> 使用 `llamafactory-cli help` 显示帮助信息。
|
| 647 |
+
>
|
| 648 |
+
> 遇到报错请先看[常见问题](https://github.com/hiyouga/LLaMA-Factory/issues/4614)。
|
| 649 |
+
|
| 650 |
+
### LLaMA Board 可视化微调(由 [Gradio](https://github.com/gradio-app/gradio) 驱动)
|
| 651 |
+
|
| 652 |
+
```bash
|
| 653 |
+
llamafactory-cli webui
|
| 654 |
+
```
|
| 655 |
+
|
| 656 |
+
### 构建 Docker
|
| 657 |
+
|
| 658 |
+
CUDA 用户:
|
| 659 |
+
|
| 660 |
+
```bash
|
| 661 |
+
cd docker/docker-cuda/
|
| 662 |
+
docker compose up -d
|
| 663 |
+
docker compose exec llamafactory bash
|
| 664 |
+
```
|
| 665 |
+
|
| 666 |
+
昇腾 NPU 用户:
|
| 667 |
+
|
| 668 |
+
```bash
|
| 669 |
+
cd docker/docker-npu/
|
| 670 |
+
docker compose up -d
|
| 671 |
+
docker compose exec llamafactory bash
|
| 672 |
+
```
|
| 673 |
+
|
| 674 |
+
AMD ROCm 用户:
|
| 675 |
+
|
| 676 |
+
```bash
|
| 677 |
+
cd docker/docker-rocm/
|
| 678 |
+
docker compose up -d
|
| 679 |
+
docker compose exec llamafactory bash
|
| 680 |
+
```
|
| 681 |
+
|
| 682 |
+
<details><summary>不使用 Docker Compose 构建</summary>
|
| 683 |
+
|
| 684 |
+
CUDA 用户:
|
| 685 |
+
|
| 686 |
+
```bash
|
| 687 |
+
docker build -f ./docker/docker-cuda/Dockerfile \
|
| 688 |
+
--build-arg PIP_INDEX=https://pypi.org/simple \
|
| 689 |
+
--build-arg EXTRAS=metrics \
|
| 690 |
+
-t llamafactory:latest .
|
| 691 |
+
|
| 692 |
+
docker run -dit --ipc=host --gpus=all \
|
| 693 |
+
-p 7860:7860 \
|
| 694 |
+
-p 8000:8000 \
|
| 695 |
+
--name llamafactory \
|
| 696 |
+
llamafactory:latest
|
| 697 |
+
|
| 698 |
+
docker exec -it llamafactory bash
|
| 699 |
+
```
|
| 700 |
+
|
| 701 |
+
昇腾 NPU 用户:
|
| 702 |
+
|
| 703 |
+
```bash
|
| 704 |
+
docker build -f ./docker/docker-npu/Dockerfile \
|
| 705 |
+
--build-arg PIP_INDEX=https://pypi.org/simple \
|
| 706 |
+
--build-arg EXTRAS=torch-npu,metrics \
|
| 707 |
+
-t llamafactory:latest .
|
| 708 |
+
|
| 709 |
+
docker run -dit --ipc=host \
|
| 710 |
+
-v /usr/local/dcmi:/usr/local/dcmi \
|
| 711 |
+
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
|
| 712 |
+
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
|
| 713 |
+
-v /etc/ascend_install.info:/etc/ascend_install.info \
|
| 714 |
+
-p 7860:7860 \
|
| 715 |
+
-p 8000:8000 \
|
| 716 |
+
--device /dev/davinci0 \
|
| 717 |
+
--device /dev/davinci_manager \
|
| 718 |
+
--device /dev/devmm_svm \
|
| 719 |
+
--device /dev/hisi_hdc \
|
| 720 |
+
--name llamafactory \
|
| 721 |
+
llamafactory:latest
|
| 722 |
+
|
| 723 |
+
docker exec -it llamafactory bash
|
| 724 |
+
```
|
| 725 |
+
|
| 726 |
+
AMD ROCm 用户:
|
| 727 |
+
|
| 728 |
+
```bash
|
| 729 |
+
docker build -f ./docker/docker-rocm/Dockerfile \
|
| 730 |
+
--build-arg PIP_INDEX=https://pypi.org/simple \
|
| 731 |
+
--build-arg EXTRAS=metrics \
|
| 732 |
+
-t llamafactory:latest .
|
| 733 |
+
|
| 734 |
+
docker run -dit --ipc=host \
|
| 735 |
+
-p 7860:7860 \
|
| 736 |
+
-p 8000:8000 \
|
| 737 |
+
--device /dev/kfd \
|
| 738 |
+
--device /dev/dri \
|
| 739 |
+
--name llamafactory \
|
| 740 |
+
llamafactory:latest
|
| 741 |
+
|
| 742 |
+
docker exec -it llamafactory bash
|
| 743 |
+
```
|
| 744 |
+
|
| 745 |
+
</details>
|
| 746 |
+
|
| 747 |
+
<details><summary>使用数据卷</summary>
|
| 748 |
+
|
| 749 |
+
您可以通过移除 Dockerfile 中 `VOLUME [ "/root/.cache/huggingface", "/app/shared_data", "/app/output" ]` 的注释来使用数据卷。
|
| 750 |
+
|
| 751 |
+
在构建 Docker 时使用参数 `-v ./hf_cache:/root/.cache/huggingface` 来挂载数据卷。各个数据卷的含义表示如下。
|
| 752 |
+
|
| 753 |
+
- `hf_cache`:使用宿主机的 Hugging Face 缓存文件夹。
|
| 754 |
+
- `shared_data`:宿主机中存放数据集的文件夹路径。
|
| 755 |
+
- `output`:将导出目录设置为该路径后,即可在宿主机中访问导出后的模型。
|
| 756 |
+
|
| 757 |
+
</details>
|
| 758 |
+
|
| 759 |
+
### 利用 vLLM 部署 OpenAI API
|
| 760 |
+
|
| 761 |
+
```bash
|
| 762 |
+
API_PORT=8000 llamafactory-cli api examples/inference/llama3.yaml infer_backend=vllm vllm_enforce_eager=true
|
| 763 |
+
```
|
| 764 |
+
|
| 765 |
+
> [!TIP]
|
| 766 |
+
> API 文档请查阅[这里](https://platform.openai.com/docs/api-reference/chat/create)。
|
| 767 |
+
>
|
| 768 |
+
> 示例:[图像理解](scripts/api_example/test_image.py) | [工具调用](scripts/api_example/test_toolcall.py)
|
| 769 |
+
|
| 770 |
+
### 从魔搭社区下载
|
| 771 |
+
|
| 772 |
+
如果您在 Hugging Face 模型和数据集的下载中遇到了问题,可以通过下述方法使用魔搭社区。
|
| 773 |
+
|
| 774 |
+
```bash
|
| 775 |
+
export USE_MODELSCOPE_HUB=1 # Windows 使用 `set USE_MODELSCOPE_HUB=1`
|
| 776 |
+
```
|
| 777 |
+
|
| 778 |
+
将 `model_name_or_path` 设置为模型 ID 来加载对应的模型。在[魔搭社区](https://modelscope.cn/models)查看所有可用的模型,例如 `LLM-Research/Meta-Llama-3-8B-Instruct`。
|
| 779 |
+
|
| 780 |
+
### 从魔乐社区下载
|
| 781 |
+
|
| 782 |
+
您也可以通过下述方法,使用魔乐社区下载数据集和模型。
|
| 783 |
+
|
| 784 |
+
```bash
|
| 785 |
+
export USE_OPENMIND_HUB=1 # Windows 使用 `set USE_OPENMIND_HUB=1`
|
| 786 |
+
```
|
| 787 |
+
|
| 788 |
+
将 `model_name_or_path` 设置为模型 ID 来加载对应的模型。在[魔乐社区](https://modelers.cn/models)查看所有可用的模型,例如 `TeleAI/TeleChat-7B-pt`。
|
| 789 |
+
|
| 790 |
+
### 使用 W&B 面板
|
| 791 |
+
|
| 792 |
+
若要使用 [Weights & Biases](https://wandb.ai) 记录实验数据,请在 yaml 文件中添加下面的参数。
|
| 793 |
+
|
| 794 |
+
```yaml
|
| 795 |
+
report_to: wandb
|
| 796 |
+
run_name: test_run # 可选
|
| 797 |
+
```
|
| 798 |
+
|
| 799 |
+
在启动训练任务时,将 `WANDB_API_KEY` 设置为[密钥](https://wandb.ai/authorize)来登录 W&B 账户。
|
| 800 |
+
|
| 801 |
+
### 使用 SwanLab 面板
|
| 802 |
+
|
| 803 |
+
若要使用 [SwanLab](https://github.com/SwanHubX/SwanLab) 记录实验数据,请在 yaml 文件中添加下面的参数。
|
| 804 |
+
|
| 805 |
+
```yaml
|
| 806 |
+
use_swanlab: true
|
| 807 |
+
swanlab_run_name: test_run # 可选
|
| 808 |
+
```
|
| 809 |
+
|
| 810 |
+
在启动训练任务时,登录SwanLab账户有以下三种方式:
|
| 811 |
+
|
| 812 |
+
方式一:在 yaml 文件中添加 `swanlab_api_key=<your_api_key>` ,并设置为你的 [API 密钥](https://swanlab.cn/settings)。
|
| 813 |
+
方式二:将环境变量 `SWANLAB_API_KEY` 设置为你的 [API 密钥](https://swanlab.cn/settings)。
|
| 814 |
+
方式三:启动前使用 `swanlab login` 命令完成登录。
|
| 815 |
+
|
| 816 |
+
## 使用了 LLaMA Factory 的项目
|
| 817 |
+
|
| 818 |
+
如果您有项目希望添加至下述列表,请通过邮件联系或者创建一个 PR。
|
| 819 |
+
|
| 820 |
+
<details><summary>点击显示</summary>
|
| 821 |
+
|
| 822 |
+
1. Wang et al. ESRL: Efficient Sampling-based Reinforcement Learning for Sequence Generation. 2023. [[arxiv]](https://arxiv.org/abs/2308.02223)
|
| 823 |
+
1. Yu et al. Open, Closed, or Small Language Models for Text Classification? 2023. [[arxiv]](https://arxiv.org/abs/2308.10092)
|
| 824 |
+
1. Wang et al. UbiPhysio: Support Daily Functioning, Fitness, and Rehabilitation with Action Understanding and Feedback in Natural Language. 2023. [[arxiv]](https://arxiv.org/abs/2308.10526)
|
| 825 |
+
1. Luceri et al. Leveraging Large Language Models to Detect Influence Campaigns in Social Media. 2023. [[arxiv]](https://arxiv.org/abs/2311.07816)
|
| 826 |
+
1. Zhang et al. Alleviating Hallucinations of Large Language Models through Induced Hallucinations. 2023. [[arxiv]](https://arxiv.org/abs/2312.15710)
|
| 827 |
+
1. Wang et al. Know Your Needs Better: Towards Structured Understanding of Marketer Demands with Analogical Reasoning Augmented LLMs. KDD 2024. [[arxiv]](https://arxiv.org/abs/2401.04319)
|
| 828 |
+
1. Wang et al. CANDLE: Iterative Conceptualization and Instantiation Distillation from Large Language Models for Commonsense Reasoning. ACL 2024. [[arxiv]](https://arxiv.org/abs/2401.07286)
|
| 829 |
+
1. Choi et al. FACT-GPT: Fact-Checking Augmentation via Claim Matching with LLMs. 2024. [[arxiv]](https://arxiv.org/abs/2402.05904)
|
| 830 |
+
1. Zhang et al. AutoMathText: Autonomous Data Selection with Language Models for Mathematical Texts. 2024. [[arxiv]](https://arxiv.org/abs/2402.07625)
|
| 831 |
+
1. Lyu et al. KnowTuning: Knowledge-aware Fine-tuning for Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.11176)
|
| 832 |
+
1. Yang et al. LaCo: Large Language Model Pruning via Layer Collaps. 2024. [[arxiv]](https://arxiv.org/abs/2402.11187)
|
| 833 |
+
1. Bhardwaj et al. Language Models are Homer Simpson! Safety Re-Alignment of Fine-tuned Language Models through Task Arithmetic. 2024. [[arxiv]](https://arxiv.org/abs/2402.11746)
|
| 834 |
+
1. Yang et al. Enhancing Empathetic Response Generation by Augmenting LLMs with Small-scale Empathetic Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.11801)
|
| 835 |
+
1. Yi et al. Generation Meets Verification: Accelerating Large Language Model Inference with Smart Parallel Auto-Correct Decoding. ACL 2024 Findings. [[arxiv]](https://arxiv.org/abs/2402.11809)
|
| 836 |
+
1. Cao et al. Head-wise Shareable Attention for Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.11819)
|
| 837 |
+
1. Zhang et al. Enhancing Multilingual Capabilities of Large Language Models through Self-Distillation from Resource-Rich Languages. 2024. [[arxiv]](https://arxiv.org/abs/2402.12204)
|
| 838 |
+
1. Kim et al. Efficient and Effective Vocabulary Expansion Towards Multilingual Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2402.14714)
|
| 839 |
+
1. Yu et al. KIEval: A Knowledge-grounded Interactive Evaluation Framework for Large Language Models. ACL 2024. [[arxiv]](https://arxiv.org/abs/2402.15043)
|
| 840 |
+
1. Huang et al. Key-Point-Driven Data Synthesis with its Enhancement on Mathematical Reasoning. 2024. [[arxiv]](https://arxiv.org/abs/2403.02333)
|
| 841 |
+
1. Duan et al. Negating Negatives: Alignment without Human Positive Samples via Distributional Dispreference Optimization. 2024. [[arxiv]](https://arxiv.org/abs/2403.03419)
|
| 842 |
+
1. Xie and Schwertfeger. Empowering Robotics with Large Language Models: osmAG Map Comprehension with LLMs. 2024. [[arxiv]](https://arxiv.org/abs/2403.08228)
|
| 843 |
+
1. Wu et al. Large Language Models are Parallel Multilingual Learners. 2024. [[arxiv]](https://arxiv.org/abs/2403.09073)
|
| 844 |
+
1. Zhang et al. EDT: Improving Large Language Models' Generation by Entropy-based Dynamic Temperature Sampling. 2024. [[arxiv]](https://arxiv.org/abs/2403.14541)
|
| 845 |
+
1. Weller et al. FollowIR: Evaluating and Teaching Information Retrieval Models to Follow Instructions. 2024. [[arxiv]](https://arxiv.org/abs/2403.15246)
|
| 846 |
+
1. Hongbin Na. CBT-LLM: A Chinese Large Language Model for Cognitive Behavioral Therapy-based Mental Health Question Answering. COLING 2024. [[arxiv]](https://arxiv.org/abs/2403.16008)
|
| 847 |
+
1. Zan et al. CodeS: Natural Language to Code Repository via Multi-Layer Sketch. 2024. [[arxiv]](https://arxiv.org/abs/2403.16443)
|
| 848 |
+
1. Liu et al. Extensive Self-Contrast Enables Feedback-Free Language Model Alignment. 2024. [[arxiv]](https://arxiv.org/abs/2404.00604)
|
| 849 |
+
1. Luo et al. BAdam: A Memory Efficient Full Parameter Training Method for Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.02827)
|
| 850 |
+
1. Du et al. Chinese Tiny LLM: Pretraining a Chinese-Centric Large Language Model. 2024. [[arxiv]](https://arxiv.org/abs/2404.04167)
|
| 851 |
+
1. Ma et al. Parameter Efficient Quasi-Orthogonal Fine-Tuning via Givens Rotation. ICML 2024. [[arxiv]](https://arxiv.org/abs/2404.04316)
|
| 852 |
+
1. Liu et al. Dynamic Generation of Personalities with Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.07084)
|
| 853 |
+
1. Shang et al. How Far Have We Gone in Stripped Binary Code Understanding Using Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.09836)
|
| 854 |
+
1. Huang et al. LLMTune: Accelerate Database Knob Tuning with Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2404.11581)
|
| 855 |
+
1. Deng et al. Text-Tuple-Table: Towards Information Integration in Text-to-Table Generation via Global Tuple Extraction. 2024. [[arxiv]](https://arxiv.org/abs/2404.14215)
|
| 856 |
+
1. Acikgoz et al. Hippocrates: An Open-Source Framework for Advancing Large Language Models in Healthcare. 2024. [[arxiv]](https://arxiv.org/abs/2404.16621)
|
| 857 |
+
1. Zhang et al. Small Language Models Need Strong Verifiers to Self-Correct Reasoning. ACL 2024 Findings. [[arxiv]](https://arxiv.org/abs/2404.17140)
|
| 858 |
+
1. Zhou et al. FREB-TQA: A Fine-Grained Robustness Evaluation Benchmark for Table Question Answering. NAACL 2024. [[arxiv]](https://arxiv.org/abs/2404.18585)
|
| 859 |
+
1. Xu et al. Large Language Models for Cyber Security: A Systematic Literature Review. 2024. [[arxiv]](https://arxiv.org/abs/2405.04760)
|
| 860 |
+
1. Dammu et al. "They are uncultured": Unveiling Covert Harms and Social Threats in LLM Generated Conversations. 2024. [[arxiv]](https://arxiv.org/abs/2405.05378)
|
| 861 |
+
1. Yi et al. A safety realignment framework via subspace-oriented model fusion for large language models. 2024. [[arxiv]](https://arxiv.org/abs/2405.09055)
|
| 862 |
+
1. Lou et al. SPO: Multi-Dimensional Preference Sequential Alignment With Implicit Reward Modeling. 2024. [[arxiv]](https://arxiv.org/abs/2405.12739)
|
| 863 |
+
1. Zhang et al. Getting More from Less: Large Language Models are Good Spontaneous Multilingual Learners. 2024. [[arxiv]](https://arxiv.org/abs/2405.13816)
|
| 864 |
+
1. Zhang et al. TS-Align: A Teacher-Student Collaborative Framework for Scalable Iterative Finetuning of Large Language Models. 2024. [[arxiv]](https://arxiv.org/abs/2405.20215)
|
| 865 |
+
1. Zihong Chen. Sentence Segmentation and Sentence Punctuation Based on XunziALLM. 2024. [[paper]](https://aclanthology.org/2024.lt4hala-1.30)
|
| 866 |
+
1. Gao et al. The Best of Both Worlds: Toward an Honest and Helpful Large Language Model. 2024. [[arxiv]](https://arxiv.org/abs/2406.00380)
|
| 867 |
+
1. Wang and Song. MARS: Benchmarking the Metaphysical Reasoning Abilities of Language Models with a Multi-task Evaluation Dataset. 2024. [[arxiv]](https://arxiv.org/abs/2406.02106)
|
| 868 |
+
1. Hu et al. Computational Limits of Low-Rank Adaptation (LoRA) for Transformer-Based Models. 2024. [[arxiv]](https://arxiv.org/abs/2406.03136)
|
| 869 |
+
1. Ge et al. Time Sensitive Knowledge Editing through Efficient Finetuning. ACL 2024. [[arxiv]](https://arxiv.org/abs/2406.04496)
|
| 870 |
+
1. Tan et al. Peer Review as A Multi-Turn and Long-Context Dialogue with Role-Based Interactions. 2024. [[arxiv]](https://arxiv.org/abs/2406.05688)
|
| 871 |
+
1. Song et al. Turbo Sparse: Achieving LLM SOTA Performance with Minimal Activated Parameters. 2024. [[arxiv]](https://arxiv.org/abs/2406.05955)
|
| 872 |
+
1. Gu et al. RWKV-CLIP: A Robust Vision-Language Representation Learner. 2024. [[arxiv]](https://arxiv.org/abs/2406.06973)
|
| 873 |
+
1. Chen et al. Advancing Tool-Augmented Large Language Models: Integrating Insights from Errors in Inference Trees. 2024. [[arxiv]](https://arxiv.org/abs/2406.07115)
|
| 874 |
+
1. Zhu et al. Are Large Language Models Good Statisticians?. 2024. [[arxiv]](https://arxiv.org/abs/2406.07815)
|
| 875 |
+
1. Li et al. Know the Unknown: An Uncertainty-Sensitive Method for LLM Instruction Tuning. 2024. [[arxiv]](https://arxiv.org/abs/2406.10099)
|
| 876 |
+
1. Ding et al. IntentionQA: A Benchmark for Evaluating Purchase Intention Comprehension Abilities of Language Models in E-commerce. 2024. [[arxiv]](https://arxiv.org/abs/2406.10173)
|
| 877 |
+
1. He et al. COMMUNITY-CROSS-INSTRUCT: Unsupervised Instruction Generation for Aligning Large Language Models to Online Communities. 2024. [[arxiv]](https://arxiv.org/abs/2406.12074)
|
| 878 |
+
1. Lin et al. FVEL: Interactive Formal Verification Environment with Large Language Models via Theorem Proving. 2024. [[arxiv]](https://arxiv.org/abs/2406.14408)
|
| 879 |
+
1. Treutlein et al. Connecting the Dots: LLMs can Infer and Verbalize Latent Structure from Disparate Training Data. 2024. [[arxiv]](https://arxiv.org/abs/2406.14546)
|
| 880 |
+
1. Feng et al. SS-Bench: A Benchmark for Social Story Generation and Evaluation. 2024. [[arxiv]](https://arxiv.org/abs/2406.15695)
|
| 881 |
+
1. Feng et al. Self-Constructed Context Decompilation with Fined-grained Alignment Enhancement. 2024. [[arxiv]](https://arxiv.org/abs/2406.17233)
|
| 882 |
+
1. Liu et al. Large Language Models for Cuffless Blood Pressure Measurement From Wearable Biosignals. 2024. [[arxiv]](https://arxiv.org/abs/2406.18069)
|
| 883 |
+
1. Iyer et al. Exploring Very Low-Resource Translation with LLMs: The University of Edinburgh's Submission to AmericasNLP 2024 Translation Task. AmericasNLP 2024. [[paper]](https://aclanthology.org/2024.americasnlp-1.25)
|
| 884 |
+
1. Li et al. Calibrating LLMs with Preference Optimization on Thought Trees for Generating Rationale in Science Question Scoring. 2024. [[arxiv]](https://arxiv.org/abs/2406.19949)
|
| 885 |
+
1. Yang et al. Financial Knowledge Large Language Model. 2024. [[arxiv]](https://arxiv.org/abs/2407.00365)
|
| 886 |
+
1. Lin et al. DogeRM: Equipping Reward Models with Domain Knowledge through Model Merging. 2024. [[arxiv]](https://arxiv.org/abs/2407.01470)
|
| 887 |
+
1. Bako et al. Evaluating the Semantic Profiling Abilities of LLMs for Natural Language Utterances in Data Visualization. 2024. [[arxiv]](https://arxiv.org/abs/2407.06129)
|
| 888 |
+
1. Huang et al. RoLoRA: Fine-tuning Rotated Outlier-free LLMs for Effective Weight-Activation Quantization. 2024. [[arxiv]](https://arxiv.org/abs/2407.08044)
|
| 889 |
+
1. Jiang et al. LLM-Collaboration on Automatic Science Journalism for the General Audience. 2024. [[arxiv]](https://arxiv.org/abs/2407.09756)
|
| 890 |
+
1. Inouye et al. Applied Auto-tuning on LoRA Hyperparameters. 2024. [[paper]](https://scholarcommons.scu.edu/cseng_senior/272/)
|
| 891 |
+
1. Qi et al. Research on Tibetan Tourism Viewpoints information generation system based on LLM. 2024. [[arxiv]](https://arxiv.org/abs/2407.13561)
|
| 892 |
+
1. Xu et al. Course-Correction: Safety Alignment Using Synthetic Preferences. 2024. [[arxiv]](https://arxiv.org/abs/2407.16637)
|
| 893 |
+
1. Sun et al. LAMBDA: A Large Model Based Data Agent. 2024. [[arxiv]](https://arxiv.org/abs/2407.17535)
|
| 894 |
+
1. Zhu et al. CollectiveSFT: Scaling Large Language Models for Chinese Medical Benchmark with Collective Instructions in Healthcare. 2024. [[arxiv]](https://arxiv.org/abs/2407.19705)
|
| 895 |
+
1. Yu et al. Correcting Negative Bias in Large Language Models through Negative Attention Score Alignment. 2024. [[arxiv]](https://arxiv.org/abs/2408.00137)
|
| 896 |
+
1. Xie et al. The Power of Personalized Datasets: Advancing Chinese Composition Writing for Elementary School through Targeted Model Fine-Tuning. IALP 2024. [[paper]](https://www.asianlp.sg/conferences/ialp2024/proceedings/papers/IALP2024_P055.pdf)
|
| 897 |
+
1. Liu et al. Instruct-Code-Llama: Improving Capabilities of Language Model in Competition Level Code Generation by Online Judge Feedback. ICIC 2024. [[paper]](https://link.springer.com/chapter/10.1007/978-981-97-5669-8_11)
|
| 898 |
+
1. Wang et al. Cybernetic Sentinels: Unveiling the Impact of Safety Data Selection on Model Security in Supervised Fine-Tuning. ICIC 2024. [[paper]](https://link.springer.com/chapter/10.1007/978-981-97-5669-8_23)
|
| 899 |
+
1. Xia et al. Understanding the Performance and Estimating the Cost of LLM Fine-Tuning. 2024. [[arxiv]](https://arxiv.org/abs/2408.04693)
|
| 900 |
+
1. Zeng et al. Perceive, Reflect, and Plan: Designing LLM Agent for Goal-Directed City Navigation without Instructions. 2024. [[arxiv]](https://arxiv.org/abs/2408.04168)
|
| 901 |
+
1. Xia et al. Using Pre-trained Language Model for Accurate ESG Prediction. FinNLP 2024. [[paper]](https://aclanthology.org/2024.finnlp-2.1/)
|
| 902 |
+
1. Liang et al. I-SHEEP: Self-Alignment of LLM from Scratch through an Iterative Self-Enhancement Paradigm. 2024. [[arxiv]](https://arxiv.org/abs/2408.08072)
|
| 903 |
+
1. Bai et al. Aligning Large Language Model with Direct Multi-Preference Optimization for Recommendation. CIKM 2024. [[paper]](https://dl.acm.org/doi/10.1145/3627673.3679611)
|
| 904 |
+
1. **[StarWhisper](https://github.com/Yu-Yang-Li/StarWhisper)**: 天文大模型 StarWhisper,基于 ChatGLM2-6B 和 Qwen-14B 在天文数据上微调而得。
|
| 905 |
+
1. **[DISC-LawLLM](https://github.com/FudanDISC/DISC-LawLLM)**: 中文法律领域大模型 DISC-LawLLM,基于 Baichuan-13B 微调而得,具有法律推理和知识检索能力。
|
| 906 |
+
1. **[Sunsimiao](https://github.com/X-D-Lab/Sunsimiao)**: 孙思邈中文医疗大模型 Sumsimiao,基于 Baichuan-7B 和 ChatGLM-6B 在中文医疗数据上微调而得。
|
| 907 |
+
1. **[CareGPT](https://github.com/WangRongsheng/CareGPT)**: 医疗大模型项目 CareGPT,基于 LLaMA2-7B 和 Baichuan-13B 在中文医疗数据上微调而得。
|
| 908 |
+
1. **[MachineMindset](https://github.com/PKU-YuanGroup/Machine-Mindset/)**:MBTI性格大模型项目,根据数据集与训练方式让任意 LLM 拥有 16 个不同的性格类型。
|
| 909 |
+
1. **[Luminia-13B-v3](https://huggingface.co/Nekochu/Luminia-13B-v3)**:一个用于生成 Stable Diffusion 提示词的大型语言模型。[[demo]](https://huggingface.co/spaces/Nekochu/Luminia-13B_SD_Prompt)
|
| 910 |
+
1. **[Chinese-LLaVA-Med](https://github.com/BUAADreamer/Chinese-LLaVA-Med)**:中文多模态医学大模型,基于 LLaVA-1.5-7B 在中文多模态医疗数据上微调而得。
|
| 911 |
+
1. **[AutoRE](https://github.com/THUDM/AutoRE)**:基于大语言模型的文档级关系抽取系统。
|
| 912 |
+
1. **[NVIDIA RTX AI Toolkit](https://github.com/NVIDIA/RTX-AI-Toolkit)**:在 Windows 主机上利用英伟达 RTX 设备进行大型语言模型微调的开发包。
|
| 913 |
+
1. **[LazyLLM](https://github.com/LazyAGI/LazyLLM)**:一个低代码构建多 Agent 大模型应用的开发工具,支持基于 LLaMA Factory 的模型微调.
|
| 914 |
+
1. **[RAG-Retrieval](https://github.com/NLPJCL/RAG-Retrieval)**:一个全链路 RAG 检索模型微调、推理和蒸馏代码库。[[blog]](https://zhuanlan.zhihu.com/p/987727357)
|
| 915 |
+
1. **[360-LLaMA-Factory](https://github.com/Qihoo360/360-LLaMA-Factory)**:一个魔改后的代码库,通过 Ring Attention 支持长序列的 SFT 和 DPO 训练。
|
| 916 |
+
1. **[Sky-T1](https://novasky-ai.github.io/posts/sky-t1/)**:由 NovaSky AI 微调的低成本类 o1 长推理模型。
|
| 917 |
+
1. **[WeClone](https://github.com/xming521/WeClone)**:从聊天记录创造数字分身的一站式解决方案。
|
| 918 |
+
|
| 919 |
+
</details>
|
| 920 |
+
|
| 921 |
+
## 协议
|
| 922 |
+
|
| 923 |
+
本仓库的代码依照 [Apache-2.0](LICENSE) 协议开源。
|
| 924 |
+
|
| 925 |
+
使用模型权重时,请遵循对应的模型协议:[Baichuan 2](https://huggingface.co/baichuan-inc/Baichuan2-7B-Base/blob/main/Community%20License%20for%20Baichuan%202%20Model.pdf) / [BLOOM](https://huggingface.co/spaces/bigscience/license) / [ChatGLM3](https://github.com/THUDM/ChatGLM3/blob/main/MODEL_LICENSE) / [Command R](https://cohere.com/c4ai-cc-by-nc-license) / [DeepSeek](https://github.com/deepseek-ai/DeepSeek-LLM/blob/main/LICENSE-MODEL) / [Falcon](https://huggingface.co/tiiuae/falcon-180B/blob/main/LICENSE.txt) / [Gemma](https://ai.google.dev/gemma/terms) / [GLM-4](https://huggingface.co/THUDM/glm-4-9b/blob/main/LICENSE) / [GPT-2](https://github.com/openai/gpt-2/blob/master/LICENSE) / [Granite](LICENSE) / [Index](https://huggingface.co/IndexTeam/Index-1.9B/blob/main/LICENSE) / [InternLM](https://github.com/InternLM/InternLM#license) / [Llama](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md) / [Llama 2](https://ai.meta.com/llama/license/) / [Llama 3](https://llama.meta.com/llama3/license/) / [Llama 4](https://github.com/meta-llama/llama-models/blob/main/models/llama4/LICENSE) / [MiniCPM](https://github.com/OpenBMB/MiniCPM/blob/main/MiniCPM%20Model%20License.md) / [Mistral/Mixtral/Pixtral](LICENSE) / [OLMo](LICENSE) / [Phi-1.5/Phi-2](https://huggingface.co/microsoft/phi-1_5/resolve/main/Research%20License.docx) / [Phi-3/Phi-4](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct/blob/main/LICENSE) / [Qwen](https://github.com/QwenLM/Qwen/blob/main/Tongyi%20Qianwen%20LICENSE%20AGREEMENT) / [Skywork](https://huggingface.co/Skywork/Skywork-13B-base/blob/main/Skywork%20Community%20License.pdf) / [StarCoder 2](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement) / [TeleChat2](https://huggingface.co/Tele-AI/telechat-7B/blob/main/TeleChat%E6%A8%A1%E5%9E%8B%E7%A4%BE%E5%8C%BA%E8%AE%B8%E5%8F%AF%E5%8D%8F%E8%AE%AE.pdf) / [XVERSE](https://github.com/xverse-ai/XVERSE-13B/blob/main/MODEL_LICENSE.pdf) / [Yi](https://huggingface.co/01-ai/Yi-6B/blob/main/LICENSE) / [Yi-1.5](LICENSE) / [Yuan 2](https://github.com/IEIT-Yuan/Yuan-2.0/blob/main/LICENSE-Yuan)
|
| 926 |
+
|
| 927 |
+
## 引用
|
| 928 |
+
|
| 929 |
+
如果您觉得此项目有帮助,请考虑以下列格式引用
|
| 930 |
+
|
| 931 |
+
```bibtex
|
| 932 |
+
@inproceedings{zheng2024llamafactory,
|
| 933 |
+
title={LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models},
|
| 934 |
+
author={Yaowei Zheng and Richong Zhang and Junhao Zhang and Yanhan Ye and Zheyan Luo and Zhangchi Feng and Yongqiang Ma},
|
| 935 |
+
booktitle={Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)},
|
| 936 |
+
address={Bangkok, Thailand},
|
| 937 |
+
publisher={Association for Computational Linguistics},
|
| 938 |
+
year={2024},
|
| 939 |
+
url={http://arxiv.org/abs/2403.13372}
|
| 940 |
+
}
|
| 941 |
+
```
|
| 942 |
+
|
| 943 |
+
## 致谢
|
| 944 |
+
|
| 945 |
+
本项目受益于 [PEFT](https://github.com/huggingface/peft)、[TRL](https://github.com/huggingface/trl)、[QLoRA](https://github.com/artidoro/qlora) 和 [FastChat](https://github.com/lm-sys/FastChat),感谢以上诸位作者的付出。
|
| 946 |
+
|
| 947 |
+
## Star History
|
| 948 |
+
|
| 949 |
+

|
SUMMARY_完成情况总结.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 任务完成情况总结
|
| 2 |
+
|
| 3 |
+
## 需求1:ShareGPT训练的具体pair分割情况分析 ✅
|
| 4 |
+
|
| 5 |
+
### 完成内容
|
| 6 |
+
1. **详细调试分析**:创建了`debug_pair_splitting.py`脚本,详细分析了ShareGPT格式的对话在训练过程中的具体分割情况
|
| 7 |
+
|
| 8 |
+
2. **核心发现**:
|
| 9 |
+
- **原始对话结构**:6条消息(human → function_call → observation → function_call → observation → gpt)
|
| 10 |
+
- **编码后消息段**:6个独立的token段,每个对应一条消息
|
| 11 |
+
- **最终训练pairs**:3个训练对,按照(prompt, response)方式分割
|
| 12 |
+
|
| 13 |
+
3. **关键理解**:
|
| 14 |
+
```python
|
| 15 |
+
# 实际的pairs结构:
|
| 16 |
+
pairs = [
|
| 17 |
+
# Pair 1: 系统提示+用户问题 → 第一次工具调用
|
| 18 |
+
([<system_tokens> + <user_tokens>], [<function_call_1_tokens>]),
|
| 19 |
+
# Pair 2: 第一次工具结果 → 第二次工具调用
|
| 20 |
+
([<observation_1_tokens>], [<function_call_2_tokens>]),
|
| 21 |
+
# Pair 3: 第二次工具结果 → 助手回复
|
| 22 |
+
([<observation_2_tokens>], [<assistant_tokens>])
|
| 23 |
+
]
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
4. **重要发现**:
|
| 27 |
+
- ✅ **只有第一个pair包含system tokens**,后续pairs不包含
|
| 28 |
+
- ✅ **每个target自动添加思维链标记**(`<think>\n\n</think>`)
|
| 29 |
+
- ✅ **多轮function call被分成多个独立训练对**
|
| 30 |
+
- ✅ **按照cutoff_len进行智能截断**
|
| 31 |
+
|
| 32 |
+
### 生成文件
|
| 33 |
+
- `debug_pair_splitting.py` - 主要调试脚本
|
| 34 |
+
- `pair_debug.log` - 详细调试日志
|
| 35 |
+
- 在`supervised.py`和`template.py`中添加了调试代码
|
| 36 |
+
|
| 37 |
+
## 需求2:基于真实训练流程的测试集评测脚本 ✅
|
| 38 |
+
|
| 39 |
+
### 完成内容
|
| 40 |
+
1. **核心评估器**:`eval_by_training_flow.py`
|
| 41 |
+
- 完全按照训练时的pair分割方式进行评估
|
| 42 |
+
- 支持function call准确性评估
|
| 43 |
+
- 支持LLM judge多维度评估
|
| 44 |
+
|
| 45 |
+
2. **Function Call评估**:
|
| 46 |
+
- ✅ **工具名称匹配检测**
|
| 47 |
+
- ✅ **参数完整性和准确性检测**
|
| 48 |
+
- ✅ **详细错误分析**(缺失参数、错误参数)
|
| 49 |
+
- ✅ **自动处理转义字符和JSON格式**
|
| 50 |
+
|
| 51 |
+
3. **Assistant Response评估**:
|
| 52 |
+
- ✅ **LLM judge多维度评分**(准确性、完整性、相关性、清晰度)
|
| 53 |
+
- ✅ **自动化评分解析**
|
| 54 |
+
- ✅ **上下文感知评估**
|
| 55 |
+
|
| 56 |
+
4. **完整的评估流程**:
|
| 57 |
+
- ✅ **数据加载和格式转换**
|
| 58 |
+
- ✅ **按训练方式分割pairs**
|
| 59 |
+
- ✅ **逐pair评估和统计**
|
| 60 |
+
- ✅ **详细结果保存和分析**
|
| 61 |
+
|
| 62 |
+
### 评估指标
|
| 63 |
+
```python
|
| 64 |
+
{
|
| 65 |
+
"function_call": {
|
| 66 |
+
"name_accuracy": 0.90, # 工具名称准确率
|
| 67 |
+
"args_accuracy": 0.75, # 参数准确率
|
| 68 |
+
"overall_accuracy": 0.60 # 整体准确率
|
| 69 |
+
},
|
| 70 |
+
"assistant_response": {
|
| 71 |
+
"average_score": 4.2, # 平均分数(1-5分)
|
| 72 |
+
"score_distribution": {...} # 分数分布
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### 生成文件
|
| 78 |
+
- `eval_by_training_flow.py` - 主要评估器
|
| 79 |
+
- `test_evaluator.py` - 功能测试脚本
|
| 80 |
+
- `run_evaluation_example.py` - 完整使用示例
|
| 81 |
+
- `sample_test_data.json` - 示例测试数据
|
| 82 |
+
- `mock_eval_results.json` - 示例评估结果
|
| 83 |
+
- `README_evaluation.md` - 详细使用文档
|
| 84 |
+
|
| 85 |
+
## 技术亮点
|
| 86 |
+
|
| 87 |
+
### 1. 完全基于真实训练流程
|
| 88 |
+
- 使用相同的tokenizer和template
|
| 89 |
+
- 按照实际的pair分割逻辑
|
| 90 |
+
- 考虑思维链和特殊token处理
|
| 91 |
+
|
| 92 |
+
### 2. 智能Function Call解析
|
| 93 |
+
- 支持多种格式的function call
|
| 94 |
+
- 自动处理转义字符
|
| 95 |
+
- 详细的错误诊断
|
| 96 |
+
|
| 97 |
+
### 3. 多维度评估体系
|
| 98 |
+
- Function call的结构化评估
|
| 99 |
+
- LLM judge的主观评估
|
| 100 |
+
- 统计分析和可视化
|
| 101 |
+
|
| 102 |
+
### 4. 完善的工具链
|
| 103 |
+
- 调试工具:理解训练过程
|
| 104 |
+
- 测试工具:验证功能正确性
|
| 105 |
+
- 评估工具:实际评测效果
|
| 106 |
+
- 文档工具:使用说明和示例
|
| 107 |
+
|
| 108 |
+
## 使用方式
|
| 109 |
+
|
| 110 |
+
### 1. 理解训练过程
|
| 111 |
+
```bash
|
| 112 |
+
python debug_pair_splitting.py
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
### 2. 测试评估功能
|
| 116 |
+
```bash
|
| 117 |
+
python test_evaluator.py
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### 3. 运行完整评估
|
| 121 |
+
```bash
|
| 122 |
+
python run_evaluation_example.py # 模拟API
|
| 123 |
+
python eval_by_training_flow.py # 真实API
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
## 核心价值
|
| 127 |
+
|
| 128 |
+
1. **训练-评估一致性**:确保评估方式与训练方式完全一致
|
| 129 |
+
2. **全面的评估体系**:覆盖function call和response质量的多个维度
|
| 130 |
+
3. **实用的工具链**:从调试到评估的完整解决方案
|
| 131 |
+
4. **可扩展的架构**:易于添加新的评估指标和功能
|
| 132 |
+
|
| 133 |
+
## 项目文件总览
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
/home/ziqiang/LLaMA-Factory/
|
| 137 |
+
├── debug_pair_splitting.py # pair分割调试脚本
|
| 138 |
+
├── eval_by_training_flow.py # 主评估器
|
| 139 |
+
├── test_evaluator.py # 功能测试
|
| 140 |
+
├── run_evaluation_example.py # 使用示例
|
| 141 |
+
├── README_evaluation.md # 详细文档
|
| 142 |
+
├── SUMMARY_完成情况总结.md # 本文档
|
| 143 |
+
├── pair_debug.log # 调试日志
|
| 144 |
+
├── eval_results.log # 评估日志
|
| 145 |
+
├── sample_test_data.json # 示例数据
|
| 146 |
+
└── mock_eval_results.json # 示例结果
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
## 总结
|
| 150 |
+
|
| 151 |
+
我们成功完成了两个主要需求:
|
| 152 |
+
|
| 153 |
+
1. ✅ **深入理解了ShareGPT训练的pair分割机制**,并提供了详细的调试工具
|
| 154 |
+
2. ✅ **构建了完整的基于训练流程的评测体系**,包括function call和LLM judge评估
|
| 155 |
+
|
| 156 |
+
这套工具可以帮助你:
|
| 157 |
+
- 准确理解训练过程中的数据处理方式
|
| 158 |
+
- 按照真实训练流程评估模型效果
|
| 159 |
+
- 获得详细的评估指标和错误分析
|
| 160 |
+
- 持续优化模型的function calling能力
|
| 161 |
+
|
| 162 |
+
所有代码都经过测试验证,可以直接使用。
|
| 163 |
+
|
| 164 |
+
|
analyze_token_logs.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
分析Token调试日志的脚本
|
| 4 |
+
用于分析训练日志中的token处理情况
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import re
|
| 8 |
+
import sys
|
| 9 |
+
from collections import defaultdict
|
| 10 |
+
|
| 11 |
+
def analyze_token_logs(log_file):
|
| 12 |
+
"""分析token调试日志"""
|
| 13 |
+
print(f"=== 分析日志文件: {log_file} ===\n")
|
| 14 |
+
|
| 15 |
+
# 统计信息
|
| 16 |
+
stats = {
|
| 17 |
+
'total_samples': 0,
|
| 18 |
+
'truncated_pairs': 0,
|
| 19 |
+
'dropped_pairs': 0,
|
| 20 |
+
'cutoff_usage': [],
|
| 21 |
+
'truncation_events': []
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
current_sample = None
|
| 25 |
+
|
| 26 |
+
with open(log_file, 'r', encoding='utf-8') as f:
|
| 27 |
+
for line in f:
|
| 28 |
+
line = line.strip()
|
| 29 |
+
|
| 30 |
+
# 检测新样本开始
|
| 31 |
+
if '[TOKEN_DEBUG] 开始处理数据样本' in line:
|
| 32 |
+
stats['total_samples'] += 1
|
| 33 |
+
current_sample = {
|
| 34 |
+
'sample_id': stats['total_samples'],
|
| 35 |
+
'pairs': [],
|
| 36 |
+
'final_length': 0,
|
| 37 |
+
'cutoff_len': 0
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# 记录cutoff_len
|
| 41 |
+
elif '[TOKEN_DEBUG] cutoff_len:' in line:
|
| 42 |
+
cutoff_match = re.search(r'cutoff_len: (\d+)', line)
|
| 43 |
+
if cutoff_match:
|
| 44 |
+
current_sample['cutoff_len'] = int(cutoff_match.group(1))
|
| 45 |
+
|
| 46 |
+
# 记录pair信息
|
| 47 |
+
elif '[TOKEN_DEBUG] === Pair' in line:
|
| 48 |
+
pair_match = re.search(r'Pair (\d+)', line)
|
| 49 |
+
if pair_match:
|
| 50 |
+
pair_id = int(pair_match.group(1))
|
| 51 |
+
current_sample['pairs'].append({
|
| 52 |
+
'id': pair_id,
|
| 53 |
+
'original_source': 0,
|
| 54 |
+
'original_target': 0,
|
| 55 |
+
'truncated_source': 0,
|
| 56 |
+
'truncated_target': 0,
|
| 57 |
+
'truncated': False
|
| 58 |
+
})
|
| 59 |
+
|
| 60 |
+
# 记录原始长度
|
| 61 |
+
elif '[TOKEN_DEBUG] 原始长度:' in line:
|
| 62 |
+
length_match = re.search(r'source=(\d+), target=(\d+)', line)
|
| 63 |
+
if length_match and current_sample and current_sample['pairs']:
|
| 64 |
+
source_len = int(length_match.group(1))
|
| 65 |
+
target_len = int(length_match.group(2))
|
| 66 |
+
current_sample['pairs'][-1]['original_source'] = source_len
|
| 67 |
+
current_sample['pairs'][-1]['original_target'] = target_len
|
| 68 |
+
|
| 69 |
+
# 记录截断后长度
|
| 70 |
+
elif '[TOKEN_DEBUG] 截断后长度:' in line:
|
| 71 |
+
truncate_match = re.search(r'source=(\d+)->(\d+), target=(\d+)->(\d+)', line)
|
| 72 |
+
if truncate_match and current_sample and current_sample['pairs']:
|
| 73 |
+
orig_source = int(truncate_match.group(1))
|
| 74 |
+
new_source = int(truncate_match.group(2))
|
| 75 |
+
orig_target = int(truncate_match.group(3))
|
| 76 |
+
new_target = int(truncate_match.group(4))
|
| 77 |
+
|
| 78 |
+
current_sample['pairs'][-1]['truncated_source'] = new_source
|
| 79 |
+
current_sample['pairs'][-1]['truncated_target'] = new_target
|
| 80 |
+
|
| 81 |
+
if new_source < orig_source or new_target < orig_target:
|
| 82 |
+
current_sample['pairs'][-1]['truncated'] = True
|
| 83 |
+
stats['truncated_pairs'] += 1
|
| 84 |
+
stats['truncation_events'].append({
|
| 85 |
+
'sample_id': current_sample['sample_id'],
|
| 86 |
+
'pair_id': current_sample['pairs'][-1]['id'],
|
| 87 |
+
'source_truncated': new_source < orig_source,
|
| 88 |
+
'target_truncated': new_target < orig_target
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
# 记录预算耗尽
|
| 92 |
+
elif '[TOKEN_DEBUG] 预算耗尽,丢弃剩余pairs' in line:
|
| 93 |
+
stats['dropped_pairs'] += 1
|
| 94 |
+
|
| 95 |
+
# 记录最终结果
|
| 96 |
+
elif '[TOKEN_DEBUG] 最终total_length:' in line:
|
| 97 |
+
final_match = re.search(r'最终total_length: (\d+)', line)
|
| 98 |
+
if final_match and current_sample:
|
| 99 |
+
current_sample['final_length'] = int(final_match.group(1))
|
| 100 |
+
stats['cutoff_usage'].append({
|
| 101 |
+
'sample_id': current_sample['sample_id'],
|
| 102 |
+
'used': current_sample['final_length'],
|
| 103 |
+
'cutoff': current_sample['cutoff_len'],
|
| 104 |
+
'usage_rate': current_sample['final_length'] / current_sample['cutoff_len'] if current_sample['cutoff_len'] > 0 else 0
|
| 105 |
+
})
|
| 106 |
+
|
| 107 |
+
# 输出分析结果
|
| 108 |
+
print(f"总样本数: {stats['total_samples']}")
|
| 109 |
+
print(f"发生截断的pairs: {stats['truncated_pairs']}")
|
| 110 |
+
print(f"预算耗尽的样本: {stats['dropped_pairs']}")
|
| 111 |
+
print()
|
| 112 |
+
|
| 113 |
+
if stats['cutoff_usage']:
|
| 114 |
+
usage_rates = [item['usage_rate'] for item in stats['cutoff_usage']]
|
| 115 |
+
avg_usage = sum(usage_rates) / len(usage_rates)
|
| 116 |
+
max_usage = max(usage_rates)
|
| 117 |
+
min_usage = min(usage_rates)
|
| 118 |
+
|
| 119 |
+
print(f"Token使用率统计:")
|
| 120 |
+
print(f" 平均使用率: {avg_usage:.1%}")
|
| 121 |
+
print(f" 最大使用率: {max_usage:.1%}")
|
| 122 |
+
print(f" 最小使用率: {min_usage:.1%}")
|
| 123 |
+
print()
|
| 124 |
+
|
| 125 |
+
# 截断事件分析
|
| 126 |
+
if stats['truncation_events']:
|
| 127 |
+
print("截断事件分析:")
|
| 128 |
+
source_truncated = sum(1 for event in stats['truncation_events'] if event['source_truncated'])
|
| 129 |
+
target_truncated = sum(1 for event in stats['truncation_events'] if event['target_truncated'])
|
| 130 |
+
|
| 131 |
+
print(f" source被截断: {source_truncated} 次")
|
| 132 |
+
print(f" target被截断: {target_truncated} 次")
|
| 133 |
+
print()
|
| 134 |
+
|
| 135 |
+
# 显示前几个截断事件
|
| 136 |
+
print("前5个截断事件:")
|
| 137 |
+
for i, event in enumerate(stats['truncation_events'][:5]):
|
| 138 |
+
print(f" 样本{event['sample_id']} Pair{event['pair_id']}: "
|
| 139 |
+
f"source截断={event['source_truncated']}, target截断={event['target_truncated']}")
|
| 140 |
+
|
| 141 |
+
# 使用率分布
|
| 142 |
+
if stats['cutoff_usage']:
|
| 143 |
+
print("\n使用率分布:")
|
| 144 |
+
ranges = [(0.0, 0.5), (0.5, 0.7), (0.7, 0.9), (0.9, 1.0), (1.0, 1.0)]
|
| 145 |
+
for start, end in ranges:
|
| 146 |
+
count = sum(1 for item in stats['cutoff_usage']
|
| 147 |
+
if start <= item['usage_rate'] < end or (end == 1.0 and item['usage_rate'] == 1.0))
|
| 148 |
+
print(f" {start:.0%}-{end:.0%}: {count} 个样本")
|
| 149 |
+
|
| 150 |
+
def main():
|
| 151 |
+
if len(sys.argv) != 2:
|
| 152 |
+
print("使用方法: python analyze_token_logs.py <log_file>")
|
| 153 |
+
print("示例: python analyze_token_logs.py debug_train.log")
|
| 154 |
+
sys.exit(1)
|
| 155 |
+
|
| 156 |
+
log_file = sys.argv[1]
|
| 157 |
+
try:
|
| 158 |
+
analyze_token_logs(log_file)
|
| 159 |
+
except FileNotFoundError:
|
| 160 |
+
print(f"错误: 找不到日志文件 {log_file}")
|
| 161 |
+
except Exception as e:
|
| 162 |
+
print(f"错误: {e}")
|
| 163 |
+
|
| 164 |
+
if __name__ == "__main__":
|
| 165 |
+
main()
|
assets/alaya_new.svg
ADDED
|
|
assets/logo.png
ADDED
|
assets/wechat.jpg
ADDED
|
Git LFS Details
|
assets/wechat_alaya.png
ADDED
|
Git LFS Details
|
assets/wechat_npu.jpg
ADDED
|
Git LFS Details
|
configs/ds_zero3.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bf16": { "enabled": true },
|
| 3 |
+
|
| 4 |
+
"zero_optimization": {
|
| 5 |
+
"stage": 3,
|
| 6 |
+
"overlap_comm": false,
|
| 7 |
+
"contiguous_gradients": true,
|
| 8 |
+
|
| 9 |
+
/* 下面三项是按 40GB 显存收紧的桶大小与持久化阈值 */
|
| 10 |
+
"reduce_bucket_size": 200000000,
|
| 11 |
+
"stage3_prefetch_bucket_size": 50000000,
|
| 12 |
+
"stage3_param_persistence_threshold": 1000000,
|
| 13 |
+
|
| 14 |
+
"stage3_gather_16bit_weights_on_model_save": true
|
| 15 |
+
},
|
| 16 |
+
|
| 17 |
+
"aio": {
|
| 18 |
+
"block_size": 1048576,
|
| 19 |
+
"queue_depth": 8,
|
| 20 |
+
"single_submit": false,
|
| 21 |
+
"overlap_events": true,
|
| 22 |
+
"thread_count": 1
|
| 23 |
+
},
|
| 24 |
+
|
| 25 |
+
/* 交由命令行的 per_device_train_batch_size / gradient_accumulation_steps 控制 */
|
| 26 |
+
"train_micro_batch_size_per_gpu": "auto",
|
| 27 |
+
"gradient_accumulation_steps": "auto",
|
| 28 |
+
|
| 29 |
+
"zero_force_ds_cpu_optimizer": false,
|
| 30 |
+
"zero_allow_untested_optimizer": true,
|
| 31 |
+
"wall_clock_breakdown": false
|
| 32 |
+
}
|
| 33 |
+
|
data/belle_multiturn/belle_multiturn.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 the LlamaFactory team.
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
import json
|
| 17 |
+
import os
|
| 18 |
+
|
| 19 |
+
import datasets
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
_HF_ENDPOINT = os.getenv("HF_ENDPOINT", "https://huggingface.co")
|
| 23 |
+
|
| 24 |
+
_DESCRIPTION = "BELLE multiturn chat dataset."
|
| 25 |
+
|
| 26 |
+
_CITATION = """\
|
| 27 |
+
@article{belle2023exploring,
|
| 28 |
+
title={Exploring the Impact of Instruction Data Scaling on Large Language Models},
|
| 29 |
+
author={Yunjie Ji, Yong Deng, Yan Gong, Yiping Peng, Qiang Niu, Lei Zhang, Baochang Ma, Xiangang Li},
|
| 30 |
+
journal={arXiv preprint arXiv:2303.14742},
|
| 31 |
+
year={2023}
|
| 32 |
+
}
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
_HOMEPAGE = f"{_HF_ENDPOINT}/datasets/BelleGroup/multiturn_chat_0.8M"
|
| 36 |
+
_LICENSE = "gpl-3.0"
|
| 37 |
+
_URL = f"{_HF_ENDPOINT}/datasets/BelleGroup/multiturn_chat_0.8M/resolve/main/multiturn_chat_0.8M.json"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class BelleMultiturn(datasets.GeneratorBasedBuilder):
|
| 41 |
+
VERSION = datasets.Version("0.0.0")
|
| 42 |
+
|
| 43 |
+
def _info(self):
|
| 44 |
+
features = datasets.Features(
|
| 45 |
+
{"conversations": [{"from": datasets.Value("string"), "value": datasets.Value("string")}]}
|
| 46 |
+
)
|
| 47 |
+
return datasets.DatasetInfo(
|
| 48 |
+
description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
| 52 |
+
file_path = dl_manager.download(_URL)
|
| 53 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": file_path})]
|
| 54 |
+
|
| 55 |
+
def _generate_examples(self, filepath: str):
|
| 56 |
+
with open(filepath, encoding="utf-8") as f:
|
| 57 |
+
for key, row in enumerate(f):
|
| 58 |
+
data = json.loads(row)
|
| 59 |
+
conversations = []
|
| 60 |
+
prompt = data["instruction"].strip()
|
| 61 |
+
response = data["output"].strip()
|
| 62 |
+
|
| 63 |
+
assist_idx = prompt.rfind("Assistant:")
|
| 64 |
+
human_idx = prompt.rfind("Human:")
|
| 65 |
+
query = prompt[human_idx + 6 : assist_idx].strip()
|
| 66 |
+
prompt = prompt[:human_idx].strip()
|
| 67 |
+
conversations.insert(0, {"from": "gpt", "value": response})
|
| 68 |
+
conversations.insert(0, {"from": "human", "value": query})
|
| 69 |
+
|
| 70 |
+
while prompt.rfind("Assistant:") != -1:
|
| 71 |
+
assist_idx = prompt.rfind("Assistant:")
|
| 72 |
+
human_idx = prompt.rfind("Human:")
|
| 73 |
+
if human_idx != -1:
|
| 74 |
+
old_query = prompt[human_idx + 6 : assist_idx].strip()
|
| 75 |
+
old_resp = prompt[assist_idx + 10 :].strip()
|
| 76 |
+
conversations.insert(0, {"from": "gpt", "value": old_resp})
|
| 77 |
+
conversations.insert(0, {"from": "human", "value": old_query})
|
| 78 |
+
else:
|
| 79 |
+
break
|
| 80 |
+
prompt = prompt[:human_idx].strip()
|
| 81 |
+
|
| 82 |
+
yield key, {"conversations": conversations}
|
data/dataset/01_26/CUDA内存不足解决方案.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CUDA 内存不足错误解决方案
|
| 2 |
+
|
| 3 |
+
## 错误现象
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 4.64 GiB.
|
| 7 |
+
GPU 0 has a total capacity of 39.49 GiB of which 1.86 GiB is free.
|
| 8 |
+
Including non-PyTorch memory, this process has 26.21 GiB memory in use.
|
| 9 |
+
Process 881161 has 11.40 GiB memory in use.
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
## 错误原因分析
|
| 13 |
+
|
| 14 |
+
1. **序列长度过长**:`cutoff_len 8192` 需要大量显存
|
| 15 |
+
2. **多进程占用显存**:另一个进程(881161)占用了 11.40 GiB
|
| 16 |
+
3. **DeepSpeed ZeRO-2 配置不够激进**:虽然启用了优化器 offload,但参数仍在 GPU 上
|
| 17 |
+
4. **PyTorch 内存碎片**:24.70 GiB 已分配但可能碎片化
|
| 18 |
+
|
| 19 |
+
## 解决方案
|
| 20 |
+
|
| 21 |
+
### 方案 1:启用 ZeRO-3 + 参数 Offload(最推荐)
|
| 22 |
+
|
| 23 |
+
使用 ZeRO-3 并将参数也 offload 到 CPU,可以大幅减少 GPU 显存占用。
|
| 24 |
+
|
| 25 |
+
**修改 DeepSpeed 配置**:使用 `zero3.json` 或创建更激进的配置
|
| 26 |
+
|
| 27 |
+
**训练命令**:
|
| 28 |
+
```bash
|
| 29 |
+
CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train \
|
| 30 |
+
--stage sft \
|
| 31 |
+
--template qwen \
|
| 32 |
+
--do_train True \
|
| 33 |
+
--flash_attn auto \
|
| 34 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 35 |
+
--preprocessing_num_workers 8 \
|
| 36 |
+
--finetuning_type lora \
|
| 37 |
+
--dataset_dir data \
|
| 38 |
+
--dataset 01_26_toollist1 \
|
| 39 |
+
--num_train_epochs 1 \
|
| 40 |
+
--warmup_ratio 0.03 \
|
| 41 |
+
--max_samples 200000 \
|
| 42 |
+
--cutoff_len 8192 \
|
| 43 |
+
--learning_rate 1e-5 \
|
| 44 |
+
--per_device_train_batch_size 1 \
|
| 45 |
+
--gradient_accumulation_steps 2 \
|
| 46 |
+
--lr_scheduler_type cosine \
|
| 47 |
+
--max_grad_norm 1.0 \
|
| 48 |
+
--logging_steps 5 \
|
| 49 |
+
--save_steps 200 \
|
| 50 |
+
--warmup_steps 0 \
|
| 51 |
+
--ddp_timeout 180000000 \
|
| 52 |
+
--packing False \
|
| 53 |
+
--enable_thinking False \
|
| 54 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 55 |
+
--bf16 True \
|
| 56 |
+
--plot_loss True \
|
| 57 |
+
--trust_remote_code True \
|
| 58 |
+
--deepspeed data/deepspeed/zero3_offload.json \
|
| 59 |
+
--include_num_input_tokens_seen True \
|
| 60 |
+
--optim adamw_torch \
|
| 61 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 62 |
+
--lora_rank 8 \
|
| 63 |
+
--lora_alpha 16 \
|
| 64 |
+
--lora_dropout 0 \
|
| 65 |
+
--lora_target all
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### 方案 2:增强 ZeRO-2 配置(参数 Offload)
|
| 69 |
+
|
| 70 |
+
在现有 ZeRO-2 基础上添加参数 offload。
|
| 71 |
+
|
| 72 |
+
**修改 DeepSpeed 配置**:创建 `zero2_offload_param.json`
|
| 73 |
+
|
| 74 |
+
**训练命令**:使用新的 DeepSpeed 配置文件
|
| 75 |
+
|
| 76 |
+
### 方案 3:减少序列长度(快速解决)
|
| 77 |
+
|
| 78 |
+
将 `cutoff_len` 从 8192 降到 6144 或更小:
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
--cutoff_len 6144
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
### 方案 4:清理其他 GPU 进程
|
| 85 |
+
|
| 86 |
+
在训练前检查并清理占用 GPU 的进程:
|
| 87 |
+
|
| 88 |
+
```bash
|
| 89 |
+
# 查看 GPU 使用情况
|
| 90 |
+
nvidia-smi
|
| 91 |
+
|
| 92 |
+
# 如果进程 881161 不需要,可以终止它
|
| 93 |
+
kill -9 881161
|
| 94 |
+
|
| 95 |
+
# 或者使用 fuser 查找占用 GPU 的进程
|
| 96 |
+
fuser -v /dev/nvidia*
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### 方案 5:减少批次大小并增加梯度累积
|
| 100 |
+
|
| 101 |
+
```bash
|
| 102 |
+
--per_device_train_batch_size 1 \
|
| 103 |
+
--gradient_accumulation_steps 4
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### 方案 6:启用 PyTorch 内存优化
|
| 107 |
+
|
| 108 |
+
在训练命令前添加环境变量:
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train ...
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
这可以减少内存碎片化问题。
|
| 115 |
+
|
| 116 |
+
### 方案 7:使用梯度检查点(Gradient Checkpointing)
|
| 117 |
+
|
| 118 |
+
如果 LLaMA-Factory 支持,可以启用梯度检查点来以计算时间换取显存:
|
| 119 |
+
|
| 120 |
+
```bash
|
| 121 |
+
--gradient_checkpointing True
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
## 推荐的组合方案
|
| 125 |
+
|
| 126 |
+
**最佳实践组合**:
|
| 127 |
+
1. 使用 ZeRO-3 + 参数和优化器 offload
|
| 128 |
+
2. 启用 PyTorch 内存优化
|
| 129 |
+
3. 清理不必要的 GPU 进程
|
| 130 |
+
4. 如果仍然不足,适当降低 `cutoff_len`
|
| 131 |
+
|
| 132 |
+
## 内存使用估算
|
| 133 |
+
|
| 134 |
+
- **Qwen3-8B 模型**:约 16 GiB(FP16/BF16)
|
| 135 |
+
- **LoRA 参数**:约 100-200 MiB(rank=8)
|
| 136 |
+
- **激活值(cutoff_len=8192)**:约 8-12 GiB per GPU
|
| 137 |
+
- **优化器状态(ZeRO-2)**:约 4-6 GiB per GPU(已 offload 到 CPU)
|
| 138 |
+
- **梯度**:约 2-4 GiB per GPU
|
| 139 |
+
|
| 140 |
+
**总计(ZeRO-2)**:约 26-34 GiB per GPU
|
| 141 |
+
**总计(ZeRO-3 + offload)**:约 10-15 GiB per GPU
|
| 142 |
+
|
| 143 |
+
## 已创建的配置文件
|
| 144 |
+
|
| 145 |
+
- `zero3_offload.json`:ZeRO-3 + 参数和优化器 offload 配置
|
| 146 |
+
- `zero2_offload_param.json`:ZeRO-2 + 参数 offload 配置
|
data/dataset/01_26/NCCL错误解决方案.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NCCL 通信超时错误解决方案
|
| 2 |
+
|
| 3 |
+
## 错误现象
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
Exception raised from ncclCommWatchdog at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:1902
|
| 7 |
+
Signal 6 (SIGABRT) received by PID
|
| 8 |
+
torch.distributed.elastic.multiprocessing.errors.ChildFailedError
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
## 错误原因分析
|
| 12 |
+
|
| 13 |
+
1. **NCCL 通信超时**:GPU 之间的通信超时,watchdog 检测到通信失败
|
| 14 |
+
2. **GPU 拓扑问题**:使用 `CUDA_VISIBLE_DEVICES=0,1,2,5` 跳过了 GPU 3 和 4,可能导致通信路径不理想
|
| 15 |
+
3. **内存不足**:显存不足可能导致通信缓冲区分配失败
|
| 16 |
+
4. **DeepSpeed 配置**:通信超时设置可能过短
|
| 17 |
+
|
| 18 |
+
## 解决方案
|
| 19 |
+
|
| 20 |
+
### 方案 1:增加 NCCL 超时时间(推荐)
|
| 21 |
+
|
| 22 |
+
在训练命令前添加环境变量:
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
NCCL_TIMEOUT=1800 NCCL_ASYNC_ERROR_HANDLING=1 CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train ...
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
并在训练命令中添加:
|
| 29 |
+
```bash
|
| 30 |
+
--ddp_timeout 1800
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
**参数说明:**
|
| 34 |
+
- `NCCL_TIMEOUT=1800`:设置 NCCL 通信超时为 1800 秒(30分钟)
|
| 35 |
+
- `NCCL_ASYNC_ERROR_HANDLING=1`:启用异步错误处理,避免立即终止
|
| 36 |
+
- `--ddp_timeout 1800`:设置 PyTorch DDP 超时时间
|
| 37 |
+
|
| 38 |
+
### 方案 2:禁用 NCCL Watchdog(如果方案1无效)
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
NCCL_TIMEOUT=1800 NCCL_ASYNC_ERROR_HANDLING=1 NCCL_BLOCKING_WAIT=0 CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train ...
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### 方案 3:使用连续的 GPU(如果可能)
|
| 45 |
+
|
| 46 |
+
如果 GPU 0,1,2,3 可用,优先使用连续的 GPU:
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 llamafactory-cli train ...
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### 方案 4:减少 GPU 数量
|
| 53 |
+
|
| 54 |
+
如果问题持续,可以尝试减少到 2 个 GPU:
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
CUDA_VISIBLE_DEVICES=0,1 llamafactory-cli train ...
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
并相应调整 `gradient_accumulation_steps` 以保持相同的有效批次大小。
|
| 61 |
+
|
| 62 |
+
### 方案 5:检查 GPU 状态和拓扑
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
# 检查 GPU 状态
|
| 66 |
+
nvidia-smi
|
| 67 |
+
|
| 68 |
+
# 检查 GPU 拓扑(需要安装 nvidia-ml-py)
|
| 69 |
+
python -c "import pynvml; pynvml.nvmlInit(); [print(f'GPU {i}: {pynvml.nvmlDeviceGetName(pynvml.nvmlDeviceGetHandleByIndex(i))}') for i in range(4)]"
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### 方案 6:启用 NCCL 调试(用于诊断)
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
NCCL_DEBUG=INFO NCCL_TIMEOUT=1800 CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train ...
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
这会输出详细的 NCCL 通信日志,帮助定位问题。
|
| 79 |
+
|
| 80 |
+
### 方案 7:调整 DeepSpeed 配置
|
| 81 |
+
|
| 82 |
+
如果使用 DeepSpeed,可以尝试:
|
| 83 |
+
|
| 84 |
+
1. **减小通信桶大小**(在 `zero2.json` 中):
|
| 85 |
+
```json
|
| 86 |
+
{
|
| 87 |
+
"zero_optimization": {
|
| 88 |
+
"allgather_bucket_size": 2e8,
|
| 89 |
+
"reduce_bucket_size": 2e8
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
2. **禁用通信重叠**:
|
| 95 |
+
```json
|
| 96 |
+
{
|
| 97 |
+
"zero_optimization": {
|
| 98 |
+
"overlap_comm": false
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
## 其他建议
|
| 104 |
+
|
| 105 |
+
1. **检查系统资源**:
|
| 106 |
+
- 确保有足够的系统内存
|
| 107 |
+
- 检查是否有其他进程占用 GPU
|
| 108 |
+
- 检查网络带宽(如果使用多节点)
|
| 109 |
+
|
| 110 |
+
2. **降低批次大小**:
|
| 111 |
+
- 减小 `per_device_train_batch_size`
|
| 112 |
+
- 增加 `gradient_accumulation_steps` 以保持有效批次大小
|
| 113 |
+
|
| 114 |
+
3. **使用更小的模型或 LoRA rank**:
|
| 115 |
+
- 如果显存紧张,可以减小 `lora_rank`
|
| 116 |
+
|
| 117 |
+
## 已更新的文件
|
| 118 |
+
|
| 119 |
+
- `/home/yijuan_liang/LLaMA-Factory/data/deepspeed/zero2.json`:添加了通信数据类型配置
|
| 120 |
+
- `/home/yijuan_liang/LLaMA-Factory/data/dataset/01_26/训练命令.md`:添加了 NCCL 超时环境变量和 `--ddp_timeout` 参数
|
data/dataset/01_26/ZeRO-3使用说明.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DeepSpeed ZeRO-3 使用说明
|
| 2 |
+
|
| 3 |
+
## 问题1:max_samples=38万,显存是否支持?
|
| 4 |
+
|
| 5 |
+
### 重要结论
|
| 6 |
+
**max_samples 不影响显存占用!**
|
| 7 |
+
|
| 8 |
+
显存占用主要取决于:
|
| 9 |
+
- 模型大小(Qwen3-8B):~16GB
|
| 10 |
+
- Batch size × Sequence length
|
| 11 |
+
- 优化器状态:~32GB(AdamW)
|
| 12 |
+
- 梯度:~16GB
|
| 13 |
+
|
| 14 |
+
### 显存需求估算(2卡)
|
| 15 |
+
|
| 16 |
+
**ZeRO-2:**
|
| 17 |
+
- 模型参数:16GB/GPU(未分片)
|
| 18 |
+
- 优化器状态:16GB/GPU(分片后)
|
| 19 |
+
- 梯度:8GB/GPU(分片后)
|
| 20 |
+
- 激活值:~0.5GB/GPU
|
| 21 |
+
- **总计:~40.5GB/GPU**
|
| 22 |
+
|
| 23 |
+
**ZeRO-3:**
|
| 24 |
+
- 模型参数:8GB/GPU(分片后)
|
| 25 |
+
- 优化器状态:16GB/GPU(分片后)
|
| 26 |
+
- 梯度:8GB/GPU(分片后)
|
| 27 |
+
- 激活值:~0.5GB/GPU
|
| 28 |
+
- **总计:~32.5GB/GPU**
|
| 29 |
+
- **节省:~8GB/GPU**
|
| 30 |
+
|
| 31 |
+
### 结论
|
| 32 |
+
- 如果每张GPU有40GB显存(A800),ZeRO-2应该足够
|
| 33 |
+
- 如果显存紧张或想更安全,建议使用ZeRO-3
|
| 34 |
+
- max_samples=38万不影响显存,只影响训练时间
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## 问题2:是否需要用到DeepSpeed ZeRO-3?
|
| 39 |
+
|
| 40 |
+
### 建议使用ZeRO-3的情况:
|
| 41 |
+
1. ✅ 显存不足(<40GB/GPU)
|
| 42 |
+
2. ✅ 想训练更大的batch size
|
| 43 |
+
3. ✅ 想使用更长的sequence length
|
| 44 |
+
4. ✅ 想更安全地训练(留出显存余量)
|
| 45 |
+
|
| 46 |
+
### 当前配置建议:
|
| 47 |
+
- **如果显存充足(40GB+)**:ZeRO-2足够
|
| 48 |
+
- **如果显存紧张(<40GB)**:使用ZeRO-3
|
| 49 |
+
- **如果想更安全**:使用ZeRO-3
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## 问题3:ZeRO-3是否可以接续在ZeRO-2后训练?
|
| 54 |
+
|
| 55 |
+
### ✅ 答案:可以!
|
| 56 |
+
|
| 57 |
+
DeepSpeed checkpoint在不同ZeRO stage之间是**兼容的**,因为:
|
| 58 |
+
1. Checkpoint保存的是**模型权重**(LoRA adapter)
|
| 59 |
+
2. ZeRO stage只影响**训练时的显存分配**
|
| 60 |
+
3. 保存的checkpoint格式相同
|
| 61 |
+
|
| 62 |
+
### 接续训练步骤:
|
| 63 |
+
|
| 64 |
+
#### 从ZeRO-2切换到ZeRO-3:
|
| 65 |
+
|
| 66 |
+
```bash
|
| 67 |
+
CUDA_VISIBLE_DEVICES=0,1 llamafactory-cli train \
|
| 68 |
+
--stage sft \
|
| 69 |
+
--template qwen \
|
| 70 |
+
--do_train True \
|
| 71 |
+
--flash_attn auto \
|
| 72 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 73 |
+
--preprocessing_num_workers 8 \
|
| 74 |
+
--finetuning_type lora \
|
| 75 |
+
--dataset_dir data \
|
| 76 |
+
--dataset 01_26_toollist1 \
|
| 77 |
+
--num_train_epochs 1 \
|
| 78 |
+
--warmup_ratio 0.03 \
|
| 79 |
+
--cutoff_len 10240 \
|
| 80 |
+
--max_samples 380000 \
|
| 81 |
+
--resume_from_checkpoint /path/to/zeor2/checkpoint-XXXX \
|
| 82 |
+
--learning_rate 1e-5 \
|
| 83 |
+
--per_device_train_batch_size 1 \
|
| 84 |
+
--gradient_accumulation_steps 4 \
|
| 85 |
+
--lr_scheduler_type cosine \
|
| 86 |
+
--max_grad_norm 1.0 \
|
| 87 |
+
--logging_steps 5 \
|
| 88 |
+
--save_steps 200 \
|
| 89 |
+
--warmup_steps 0 \
|
| 90 |
+
--packing False \
|
| 91 |
+
--enable_thinking False \
|
| 92 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 93 |
+
--bf16 True \
|
| 94 |
+
--plot_loss True \
|
| 95 |
+
--trust_remote_code True \
|
| 96 |
+
--deepspeed data/deepspeed/zero3.json \
|
| 97 |
+
--include_num_input_tokens_seen True \
|
| 98 |
+
--optim adamw_torch \
|
| 99 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 100 |
+
--lora_rank 8 \
|
| 101 |
+
--lora_alpha 16 \
|
| 102 |
+
--lora_dropout 0 \
|
| 103 |
+
--lora_target all
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### 注意事项:
|
| 107 |
+
|
| 108 |
+
1. **保持训练参数一致**:
|
| 109 |
+
- learning_rate
|
| 110 |
+
- optimizer类型
|
| 111 |
+
- LoRA参数(rank, alpha等)
|
| 112 |
+
|
| 113 |
+
2. **可以改变**:
|
| 114 |
+
- ZeRO stage(2→3)
|
| 115 |
+
- max_samples
|
| 116 |
+
- GPU数量(需要调整gradient_accumulation_steps)
|
| 117 |
+
|
| 118 |
+
3. **checkpoint路径**:
|
| 119 |
+
- 确保checkpoint路径正确
|
| 120 |
+
- 使用最新的checkpoint
|
| 121 |
+
|
| 122 |
+
---
|
| 123 |
+
|
| 124 |
+
## 配置文件说明
|
| 125 |
+
|
| 126 |
+
### ZeRO-3配置(带CPU offload)
|
| 127 |
+
- `data/deepspeed/zero3.json`:最节省显存
|
| 128 |
+
- 优化器和参数都offload到CPU
|
| 129 |
+
|
| 130 |
+
### ZeRO-3配置(不带CPU offload)
|
| 131 |
+
- `data/deepspeed/zero3_no_offload.json`:速度更快
|
| 132 |
+
- 所有计算在GPU上
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
## 推荐方案
|
| 137 |
+
|
| 138 |
+
### 方案1:先用ZeRO-2训练小样本
|
| 139 |
+
```bash
|
| 140 |
+
--max_samples 10000
|
| 141 |
+
--deepspeed data/deepspeed/zero2.json
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
### 方案2:切换到ZeRO-3训练大样本
|
| 145 |
+
```bash
|
| 146 |
+
--max_samples 380000
|
| 147 |
+
--resume_from_checkpoint <zeor2_checkpoint>
|
| 148 |
+
--deepspeed data/deepspeed/zero3.json
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
这样可以:
|
| 152 |
+
- 先用ZeRO-2快速验证训练流程
|
| 153 |
+
- 再用ZeRO-3安全训练大样本
|
data/dataset/01_26/fix_cuda_oom.sh
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# CUDA 内存不足问题诊断和修复脚本
|
| 4 |
+
# 使用方法: bash fix_cuda_oom.sh
|
| 5 |
+
|
| 6 |
+
echo "=========================================="
|
| 7 |
+
echo "CUDA 内存不足问题诊断工具"
|
| 8 |
+
echo "=========================================="
|
| 9 |
+
echo ""
|
| 10 |
+
|
| 11 |
+
# 1. 检查 GPU 状态
|
| 12 |
+
echo "1. 检查 GPU 状态和内存使用情况:"
|
| 13 |
+
echo "----------------------------------------"
|
| 14 |
+
nvidia-smi
|
| 15 |
+
echo ""
|
| 16 |
+
|
| 17 |
+
# 2. 查找占用 GPU 的进程
|
| 18 |
+
echo "2. 查找占用 GPU 的进程:"
|
| 19 |
+
echo "----------------------------------------"
|
| 20 |
+
fuser -v /dev/nvidia* 2>/dev/null || echo "未找到占用 GPU 的进程"
|
| 21 |
+
echo ""
|
| 22 |
+
|
| 23 |
+
# 3. 检查是否有其他 Python 进程占用 GPU
|
| 24 |
+
echo "3. 检查 Python 进程占用 GPU 情况:"
|
| 25 |
+
echo "----------------------------------------"
|
| 26 |
+
ps aux | grep python | grep -v grep | head -10
|
| 27 |
+
echo ""
|
| 28 |
+
|
| 29 |
+
# 4. 提供清理建议
|
| 30 |
+
echo "4. 清理建议:"
|
| 31 |
+
echo "----------------------------------------"
|
| 32 |
+
echo "如果发现不需要的进程占用 GPU,可以使用以下命令清理:"
|
| 33 |
+
echo " kill -9 <PID> # 替换 <PID> 为进程 ID"
|
| 34 |
+
echo ""
|
| 35 |
+
|
| 36 |
+
# 5. 显示推荐的训练命令
|
| 37 |
+
echo "5. 推荐的训练命令(内存优化版本):"
|
| 38 |
+
echo "----------------------------------------"
|
| 39 |
+
echo ""
|
| 40 |
+
echo "方案 A: 使用 ZeRO-2 + 参数 Offload(推荐):"
|
| 41 |
+
echo "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train \\"
|
| 42 |
+
echo " --deepspeed data/deepspeed/zero2_offload_param.json \\"
|
| 43 |
+
echo " ... (其他参数见训练命令.md)"
|
| 44 |
+
echo ""
|
| 45 |
+
echo "方案 B: 使用 ZeRO-3 + 参数 Offload(最激进):"
|
| 46 |
+
echo "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train \\"
|
| 47 |
+
echo " --deepspeed data/deepspeed/zero3.json \\"
|
| 48 |
+
echo " ... (其他参数见训练命令.md)"
|
| 49 |
+
echo ""
|
| 50 |
+
echo "方案 C: 降低序列长度(快速解决):"
|
| 51 |
+
echo "将 --cutoff_len 8192 改为 --cutoff_len 6144"
|
| 52 |
+
echo ""
|
| 53 |
+
|
| 54 |
+
# 6. 检查 DeepSpeed 配置文件是否存在
|
| 55 |
+
echo "6. 检查 DeepSpeed 配置文件:"
|
| 56 |
+
echo "----------------------------------------"
|
| 57 |
+
if [ -f "data/deepspeed/zero2_offload_param.json" ]; then
|
| 58 |
+
echo "✓ zero2_offload_param.json 存在"
|
| 59 |
+
else
|
| 60 |
+
echo "✗ zero2_offload_param.json 不存在"
|
| 61 |
+
fi
|
| 62 |
+
|
| 63 |
+
if [ -f "data/deepspeed/zero3.json" ]; then
|
| 64 |
+
echo "✓ zero3.json 存在"
|
| 65 |
+
else
|
| 66 |
+
echo "✗ zero3.json 不存在"
|
| 67 |
+
fi
|
| 68 |
+
echo ""
|
| 69 |
+
|
| 70 |
+
# 7. 显示内存使用估算
|
| 71 |
+
echo "7. 内存使用估算:"
|
| 72 |
+
echo "----------------------------------------"
|
| 73 |
+
echo "当前配置(ZeRO-2,cutoff_len=8192):"
|
| 74 |
+
echo " - 模型参数: ~16 GiB"
|
| 75 |
+
echo " - 激活值: ~8-12 GiB per GPU"
|
| 76 |
+
echo " - 优化器状态: ~4-6 GiB per GPU (已 offload)"
|
| 77 |
+
echo " - 总计: ~26-34 GiB per GPU"
|
| 78 |
+
echo ""
|
| 79 |
+
echo "优化后(ZeRO-3 + offload,cutoff_len=8192):"
|
| 80 |
+
echo " - 模型参数: ~0 GiB (offload 到 CPU)"
|
| 81 |
+
echo " - 激活值: ~8-12 GiB per GPU"
|
| 82 |
+
echo " - 优化器状态: ~0 GiB (offload 到 CPU)"
|
| 83 |
+
echo " - 总计: ~10-15 GiB per GPU"
|
| 84 |
+
echo ""
|
| 85 |
+
|
| 86 |
+
echo "=========================================="
|
| 87 |
+
echo "详细解决方案请查看: CUDA内存不足解决方案.md"
|
| 88 |
+
echo "=========================================="
|
data/dataset/01_26/token_statistics.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"toollist1.jsonl": {
|
| 3 |
+
"max": 48125,
|
| 4 |
+
"min": 2714,
|
| 5 |
+
"mean": 4443.34899767502,
|
| 6 |
+
"median": 4143.0,
|
| 7 |
+
"total": 1720020397,
|
| 8 |
+
"count": 387100
|
| 9 |
+
},
|
| 10 |
+
"toollist2.jsonl": {
|
| 11 |
+
"max": 33493,
|
| 12 |
+
"min": 2623,
|
| 13 |
+
"mean": 4555.394726492956,
|
| 14 |
+
"median": 4281.0,
|
| 15 |
+
"total": 1714349919,
|
| 16 |
+
"count": 376334
|
| 17 |
+
}
|
| 18 |
+
}
|
data/dataset/01_26/token_statistics.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Token 统计结果
|
| 2 |
+
============================================================
|
| 3 |
+
|
| 4 |
+
文件: toollist1.jsonl
|
| 5 |
+
总实例数: 387100
|
| 6 |
+
总 token 数: 1720020397
|
| 7 |
+
最大 token 数: 48125
|
| 8 |
+
最小 token 数: 2714
|
| 9 |
+
平均 token 数: 4443.35
|
| 10 |
+
中位数 token 数: 4143.00
|
| 11 |
+
|
| 12 |
+
文件: toollist2.jsonl
|
| 13 |
+
总实例数: 376334
|
| 14 |
+
总 token 数: 1714349919
|
| 15 |
+
最大 token 数: 33493
|
| 16 |
+
最小 token 数: 2623
|
| 17 |
+
平均 token 数: 4555.39
|
| 18 |
+
中位数 token 数: 4281.00
|
| 19 |
+
|
data/dataset/01_26/toollist1.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3544b700c2a66f259adfc732e43164125adbcf318bee3d3604125ac25095a226
|
| 3 |
+
size 7155840129
|
data/dataset/01_26/toollist1_sample.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/dataset/01_26/toollist2.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4bf1d0c33ed8b489ec071cc5a1188a0c5565d1f814f32c3cfa4c820cf9936471
|
| 3 |
+
size 7176485260
|
data/dataset/01_26/toollist2_sample.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/dataset/01_26/接续训练示例.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 接续训练命令示例
|
| 2 |
+
|
| 3 |
+
## 场景1:增大max_samples接续训练(保持GPU数量不变)
|
| 4 |
+
|
| 5 |
+
```bash
|
| 6 |
+
CUDA_VISIBLE_DEVICES=0,1 llamafactory-cli train \
|
| 7 |
+
--stage sft \
|
| 8 |
+
--template qwen \
|
| 9 |
+
--do_train True \
|
| 10 |
+
--flash_attn auto \
|
| 11 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 12 |
+
--preprocessing_num_workers 8 \
|
| 13 |
+
--finetuning_type lora \
|
| 14 |
+
--dataset_dir data \
|
| 15 |
+
--dataset 01_26_toollist1 \
|
| 16 |
+
--num_train_epochs 1 \
|
| 17 |
+
--warmup_ratio 0.03 \
|
| 18 |
+
--cutoff_len 10240 \
|
| 19 |
+
--max_samples 50000 \
|
| 20 |
+
--resume_from_checkpoint /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_YYYY-MM-DD-HH-MM/checkpoint-XXXX \
|
| 21 |
+
--learning_rate 1e-5 \
|
| 22 |
+
--per_device_train_batch_size 1 \
|
| 23 |
+
--gradient_accumulation_steps 4 \
|
| 24 |
+
--lr_scheduler_type cosine \
|
| 25 |
+
--max_grad_norm 1.0 \
|
| 26 |
+
--logging_steps 5 \
|
| 27 |
+
--save_steps 200 \
|
| 28 |
+
--warmup_steps 0 \
|
| 29 |
+
--packing False \
|
| 30 |
+
--enable_thinking False \
|
| 31 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 32 |
+
--bf16 True \
|
| 33 |
+
--plot_loss True \
|
| 34 |
+
--trust_remote_code True \
|
| 35 |
+
--deepspeed data/deepspeed/zero2.json \
|
| 36 |
+
--include_num_input_tokens_seen True \
|
| 37 |
+
--optim adamw_torch \
|
| 38 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 39 |
+
--lora_rank 8 \
|
| 40 |
+
--lora_alpha 16 \
|
| 41 |
+
--lora_dropout 0 \
|
| 42 |
+
--lora_target all
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## 场景2:加卡并减少gradient_accumulation_steps接续训练
|
| 46 |
+
|
| 47 |
+
### 原配置(2卡):
|
| 48 |
+
- GPU数量: 2
|
| 49 |
+
- per_device_train_batch_size: 1
|
| 50 |
+
- gradient_accumulation_steps: 4
|
| 51 |
+
- **有效batch size = 2 × 1 × 4 = 8**
|
| 52 |
+
|
| 53 |
+
### 新配置(4卡,保持有效batch size):
|
| 54 |
+
- GPU数量: 4
|
| 55 |
+
- per_device_train_batch_size: 1
|
| 56 |
+
- gradient_accumulation_steps: 2
|
| 57 |
+
- **有效batch size = 4 × 1 × 2 = 8** ✓
|
| 58 |
+
|
| 59 |
+
```bash
|
| 60 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 llamafactory-cli train \
|
| 61 |
+
--stage sft \
|
| 62 |
+
--template qwen \
|
| 63 |
+
--do_train True \
|
| 64 |
+
--flash_attn auto \
|
| 65 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 66 |
+
--preprocessing_num_workers 8 \
|
| 67 |
+
--finetuning_type lora \
|
| 68 |
+
--dataset_dir data \
|
| 69 |
+
--dataset 01_26_toollist1 \
|
| 70 |
+
--num_train_epochs 1 \
|
| 71 |
+
--warmup_ratio 0.03 \
|
| 72 |
+
--cutoff_len 10240 \
|
| 73 |
+
--max_samples 50000 \
|
| 74 |
+
--resume_from_checkpoint /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_YYYY-MM-DD-HH-MM/checkpoint-XXXX \
|
| 75 |
+
--learning_rate 1e-5 \
|
| 76 |
+
--per_device_train_batch_size 1 \
|
| 77 |
+
--gradient_accumulation_steps 2 \
|
| 78 |
+
--lr_scheduler_type cosine \
|
| 79 |
+
--max_grad_norm 1.0 \
|
| 80 |
+
--logging_steps 5 \
|
| 81 |
+
--save_steps 200 \
|
| 82 |
+
--warmup_steps 0 \
|
| 83 |
+
--packing False \
|
| 84 |
+
--enable_thinking False \
|
| 85 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 86 |
+
--bf16 True \
|
| 87 |
+
--plot_loss True \
|
| 88 |
+
--trust_remote_code True \
|
| 89 |
+
--deepspeed data/deepspeed/zero2.json \
|
| 90 |
+
--include_num_input_tokens_seen True \
|
| 91 |
+
--optim adamw_torch \
|
| 92 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 93 |
+
--lora_rank 8 \
|
| 94 |
+
--lora_alpha 16 \
|
| 95 |
+
--lora_dropout 0 \
|
| 96 |
+
--lora_target all
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
## 重要注意事项
|
| 100 |
+
|
| 101 |
+
1. **保持有效batch size一致**:改变GPU数量时,需要调整gradient_accumulation_steps以保持相同的有效batch size
|
| 102 |
+
2. **checkpoint兼容性**:确保checkpoint路径正确,DeepSpeed checkpoint可以跨GPU数量使用
|
| 103 |
+
3. **学习率调度器**:如果改变了有效batch size,可能需要调整learning_rate或warmup_steps
|
| 104 |
+
4. **数据集顺序**:确保数据集顺序一致,否则可能影响训练效果
|
| 105 |
+
|
| 106 |
+
## 有效batch size计算公式
|
| 107 |
+
|
| 108 |
+
```
|
| 109 |
+
有效batch size = GPU数量 × per_device_train_batch_size × gradient_accumulation_steps
|
| 110 |
+
```
|
data/dataset/01_26/训练命令.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
toollist1(cutoff_len 8192)- 使用DeepSpeed ZeRO-2:
|
| 2 |
+
CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train \
|
| 3 |
+
--stage sft \
|
| 4 |
+
--template qwen \
|
| 5 |
+
--do_train True \
|
| 6 |
+
--flash_attn auto \
|
| 7 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 8 |
+
--preprocessing_num_workers 8 \
|
| 9 |
+
--finetuning_type lora \
|
| 10 |
+
--dataset_dir data \
|
| 11 |
+
--dataset 01_26_toollist1 \
|
| 12 |
+
--num_train_epochs 1 \
|
| 13 |
+
--warmup_ratio 0.03 \
|
| 14 |
+
--max_samples 200000 \
|
| 15 |
+
--cutoff_len 8192 \
|
| 16 |
+
--learning_rate 1e-5 \
|
| 17 |
+
--per_device_train_batch_size 1 \
|
| 18 |
+
--gradient_accumulation_steps 2 \
|
| 19 |
+
--lr_scheduler_type cosine \
|
| 20 |
+
--max_grad_norm 1.0 \
|
| 21 |
+
--logging_steps 5 \
|
| 22 |
+
--save_steps 200 \
|
| 23 |
+
--warmup_steps 0 \
|
| 24 |
+
--ddp_timeout 180000000 \
|
| 25 |
+
--packing False \
|
| 26 |
+
--enable_thinking False \
|
| 27 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 28 |
+
--bf16 True \
|
| 29 |
+
--plot_loss True \
|
| 30 |
+
--trust_remote_code True \
|
| 31 |
+
--deepspeed data/deepspeed/zero2.json \
|
| 32 |
+
--include_num_input_tokens_seen True \
|
| 33 |
+
--optim adamw_torch \
|
| 34 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 35 |
+
--lora_rank 8 \
|
| 36 |
+
--lora_alpha 16 \
|
| 37 |
+
--lora_dropout 0 \
|
| 38 |
+
--lora_target all
|
| 39 |
+
|
| 40 |
+
toollist1(cutoff_len 8192)- 使用DeepSpeed ZeRO-2 + 参数Offload(内存优化版,解决OOM):
|
| 41 |
+
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train \
|
| 42 |
+
--stage sft \
|
| 43 |
+
--template qwen \
|
| 44 |
+
--do_train True \
|
| 45 |
+
--flash_attn auto \
|
| 46 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 47 |
+
--preprocessing_num_workers 8 \
|
| 48 |
+
--finetuning_type lora \
|
| 49 |
+
--dataset_dir data \
|
| 50 |
+
--dataset 01_26_toollist1 \
|
| 51 |
+
--num_train_epochs 1 \
|
| 52 |
+
--warmup_ratio 0.03 \
|
| 53 |
+
--max_samples 200000 \
|
| 54 |
+
--cutoff_len 8192 \
|
| 55 |
+
--learning_rate 1e-5 \
|
| 56 |
+
--per_device_train_batch_size 1 \
|
| 57 |
+
--gradient_accumulation_steps 2 \
|
| 58 |
+
--lr_scheduler_type cosine \
|
| 59 |
+
--max_grad_norm 1.0 \
|
| 60 |
+
--logging_steps 5 \
|
| 61 |
+
--save_steps 200 \
|
| 62 |
+
--warmup_steps 0 \
|
| 63 |
+
--ddp_timeout 180000000 \
|
| 64 |
+
--packing False \
|
| 65 |
+
--enable_thinking False \
|
| 66 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 67 |
+
--bf16 True \
|
| 68 |
+
--plot_loss True \
|
| 69 |
+
--trust_remote_code True \
|
| 70 |
+
--deepspeed data/deepspeed/zero2_offload_param.json \
|
| 71 |
+
--include_num_input_tokens_seen True \
|
| 72 |
+
--optim adamw_torch \
|
| 73 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 74 |
+
--lora_rank 8 \
|
| 75 |
+
--lora_alpha 16 \
|
| 76 |
+
--lora_dropout 0 \
|
| 77 |
+
--lora_target all
|
| 78 |
+
|
| 79 |
+
toollist1(cutoff_len 8192)- 使用DeepSpeed ZeRO-3 + 参数Offload(最激进内存优化版):
|
| 80 |
+
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train \
|
| 81 |
+
--stage sft \
|
| 82 |
+
--template qwen \
|
| 83 |
+
--do_train True \
|
| 84 |
+
--flash_attn auto \
|
| 85 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 86 |
+
--preprocessing_num_workers 8 \
|
| 87 |
+
--finetuning_type lora \
|
| 88 |
+
--dataset_dir data \
|
| 89 |
+
--dataset 01_26_toollist1 \
|
| 90 |
+
--num_train_epochs 1 \
|
| 91 |
+
--warmup_ratio 0.03 \
|
| 92 |
+
--max_samples 200000 \
|
| 93 |
+
--cutoff_len 8192 \
|
| 94 |
+
--learning_rate 1e-5 \
|
| 95 |
+
--per_device_train_batch_size 1 \
|
| 96 |
+
--gradient_accumulation_steps 2 \
|
| 97 |
+
--lr_scheduler_type cosine \
|
| 98 |
+
--max_grad_norm 1.0 \
|
| 99 |
+
--logging_steps 5 \
|
| 100 |
+
--save_steps 200 \
|
| 101 |
+
--warmup_steps 0 \
|
| 102 |
+
--ddp_timeout 180000000 \
|
| 103 |
+
--packing False \
|
| 104 |
+
--enable_thinking False \
|
| 105 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 106 |
+
--bf16 True \
|
| 107 |
+
--plot_loss True \
|
| 108 |
+
--trust_remote_code True \
|
| 109 |
+
--deepspeed data/deepspeed/zero3.json \
|
| 110 |
+
--include_num_input_tokens_seen True \
|
| 111 |
+
--optim adamw_torch \
|
| 112 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 113 |
+
--lora_rank 8 \
|
| 114 |
+
--lora_alpha 16 \
|
| 115 |
+
--lora_dropout 0 \
|
| 116 |
+
--lora_target all
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
toollist1(cutoff_len 6144)- 使用DeepSpeed ZeRO-2:
|
| 120 |
+
CUDA_VISIBLE_DEVICES=0,1,2,5 llamafactory-cli train \
|
| 121 |
+
--stage sft \
|
| 122 |
+
--template qwen \
|
| 123 |
+
--do_train True \
|
| 124 |
+
--flash_attn auto \
|
| 125 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 126 |
+
--preprocessing_num_workers 8 \
|
| 127 |
+
--finetuning_type lora \
|
| 128 |
+
--dataset_dir data \
|
| 129 |
+
--dataset 01_26_toollist1 \
|
| 130 |
+
--num_train_epochs 1 \
|
| 131 |
+
--warmup_ratio 0.03 \
|
| 132 |
+
--cutoff_len 6144 \
|
| 133 |
+
--max_samples 200000 \
|
| 134 |
+
--learning_rate 1e-5 \
|
| 135 |
+
--per_device_train_batch_size 1 \
|
| 136 |
+
--gradient_accumulation_steps 2 \
|
| 137 |
+
--lr_scheduler_type cosine \
|
| 138 |
+
--max_grad_norm 1.0 \
|
| 139 |
+
--logging_steps 5 \
|
| 140 |
+
--save_steps 200 \
|
| 141 |
+
--warmup_steps 0 \
|
| 142 |
+
--packing False \
|
| 143 |
+
--enable_thinking False \
|
| 144 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 145 |
+
--bf16 True \
|
| 146 |
+
--plot_loss True \
|
| 147 |
+
--trust_remote_code True \
|
| 148 |
+
--deepspeed data/deepspeed/zero2.json \
|
| 149 |
+
--include_num_input_tokens_seen True \
|
| 150 |
+
--optim adamw_torch \
|
| 151 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 152 |
+
--lora_rank 8 \
|
| 153 |
+
--lora_alpha 16 \
|
| 154 |
+
--lora_dropout 0 \
|
| 155 |
+
--lora_target all
|
| 156 |
+
|
| 157 |
+
toollist1(cutoff_len 10240)- 不使用DeepSpeed ZeRO-2,从ck训:
|
| 158 |
+
CUDA_VISIBLE_DEVICES=0,1 llamafactory-cli train \
|
| 159 |
+
--stage sft \
|
| 160 |
+
--template qwen \
|
| 161 |
+
--do_train True \
|
| 162 |
+
--flash_attn auto \
|
| 163 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 164 |
+
--preprocessing_num_workers 8 \
|
| 165 |
+
--finetuning_type lora \
|
| 166 |
+
--dataset_dir data \
|
| 167 |
+
--dataset 01_26_toollist1 \
|
| 168 |
+
--num_train_epochs 1 \
|
| 169 |
+
--warmup_ratio 0.03 \
|
| 170 |
+
--cutoff_len 10240 \
|
| 171 |
+
--max_samples 120000 \
|
| 172 |
+
--resume_from_checkpoint /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_2026-01-29-20-31/checkpoint-11200 \
|
| 173 |
+
--learning_rate 1e-5 \
|
| 174 |
+
--per_device_train_batch_size 1 \
|
| 175 |
+
--gradient_accumulation_steps 4 \
|
| 176 |
+
--lr_scheduler_type cosine \
|
| 177 |
+
--max_grad_norm 1.0 \
|
| 178 |
+
--logging_steps 5 \
|
| 179 |
+
--save_steps 200 \
|
| 180 |
+
--warmup_steps 0 \
|
| 181 |
+
--packing False \
|
| 182 |
+
--enable_thinking False \
|
| 183 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 184 |
+
--bf16 True \
|
| 185 |
+
--plot_loss True \
|
| 186 |
+
--trust_remote_code True \
|
| 187 |
+
--ddp_timeout 180000000 \
|
| 188 |
+
--include_num_input_tokens_seen True \
|
| 189 |
+
--optim adamw_torch \
|
| 190 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 191 |
+
--lora_rank 8 \
|
| 192 |
+
--lora_alpha 16 \
|
| 193 |
+
--lora_dropout 0 \
|
| 194 |
+
--lora_target all
|
| 195 |
+
|
| 196 |
+
toollist1(cutoff_len 10240)- 不使用DeepSpeed ZeRO-2,从头训:
|
| 197 |
+
CUDA_VISIBLE_DEVICES=0,1 llamafactory-cli train \
|
| 198 |
+
--stage sft \
|
| 199 |
+
--template qwen \
|
| 200 |
+
--do_train True \
|
| 201 |
+
--flash_attn auto \
|
| 202 |
+
--model_name_or_path /data/models/Qwen3-8B \
|
| 203 |
+
--preprocessing_num_workers 8 \
|
| 204 |
+
--finetuning_type lora \
|
| 205 |
+
--dataset_dir data \
|
| 206 |
+
--dataset 01_26_toollist1 \
|
| 207 |
+
--num_train_epochs 1 \
|
| 208 |
+
--warmup_ratio 0.03 \
|
| 209 |
+
--cutoff_len 10240 \
|
| 210 |
+
--max_samples 10000 \
|
| 211 |
+
--learning_rate 1e-5 \
|
| 212 |
+
--per_device_train_batch_size 1 \
|
| 213 |
+
--gradient_accumulation_steps 4 \
|
| 214 |
+
--lr_scheduler_type cosine \
|
| 215 |
+
--max_grad_norm 1.0 \
|
| 216 |
+
--logging_steps 5 \
|
| 217 |
+
--save_steps 200 \
|
| 218 |
+
--warmup_steps 0 \
|
| 219 |
+
--packing False \
|
| 220 |
+
--enable_thinking False \
|
| 221 |
+
--output_dir /home/yijuan_liang/LLaMA-Factory/saves/Qwen3-8B/lora/train_$(date +%Y-%m-%d-%H-%M) \
|
| 222 |
+
--bf16 True \
|
| 223 |
+
--plot_loss True \
|
| 224 |
+
--trust_remote_code True \
|
| 225 |
+
--include_num_input_tokens_seen True \
|
| 226 |
+
--optim adamw_torch \
|
| 227 |
+
--adam_beta1 0.9 --adam_beta2 0.999 --adam_epsilon 1e-8 \
|
| 228 |
+
--lora_rank 8 \
|
| 229 |
+
--lora_alpha 16 \
|
| 230 |
+
--lora_dropout 0 \
|
| 231 |
+
--lora_target all
|
data/dataset/12_10/LLM输入一致性对比分析.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LLM输入一致性对比分析
|
| 2 |
+
|
| 3 |
+
## 概述
|
| 4 |
+
|
| 5 |
+
本文档对比分析 `generate_with_qwen_server_list_v2.py`(推理脚本)和 `template.py`(训练模板)中每次调用LLM时的input构建逻辑。
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## 1. Function Call阶段对比
|
| 10 |
+
|
| 11 |
+
### 1.1 推理脚本 (`build_messages_for_function_call`)
|
| 12 |
+
|
| 13 |
+
**位置**: `generate_with_qwen_server_list_v2.py:265-394`
|
| 14 |
+
|
| 15 |
+
**逻辑**:
|
| 16 |
+
- **第一次调用** (call_idx=0):
|
| 17 |
+
- system: `system_prompt + <tools>`
|
| 18 |
+
- user: `current_query`
|
| 19 |
+
|
| 20 |
+
- **第n次调用** (call_idx > 0):
|
| 21 |
+
- system: `system_prompt + <chat_history> + <tools>`
|
| 22 |
+
- observation: `<tool_response>` (前一个observation)
|
| 23 |
+
- user: `current_query` (如果不在chat_history中)
|
| 24 |
+
|
| 25 |
+
**关键代码**:
|
| 26 |
+
```python
|
| 27 |
+
# 第363-365行:添加tools到system中
|
| 28 |
+
if tools_formatted:
|
| 29 |
+
system_content += f"\n\n<tools>\n{tools_formatted}\n</tools>"
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
### 1.2 训练模板 (`_encode` 处理 OBSERVATION → FUNCTION)
|
| 33 |
+
|
| 34 |
+
**位置**: `template.py:315-371`
|
| 35 |
+
|
| 36 |
+
**逻辑**:
|
| 37 |
+
- 当 `message["role"] == Role.OBSERVATION` 且下一个消息是 `Role.FUNCTION` 时:
|
| 38 |
+
- system: `system + <chat_history> + <tools>`
|
| 39 |
+
- observation: `<tool_response>` (当前observation)
|
| 40 |
+
|
| 41 |
+
**关键代码**:
|
| 42 |
+
```python
|
| 43 |
+
# 第360-367行:如果下一个是tool call,拼接system + tools
|
| 44 |
+
else:
|
| 45 |
+
# 如果下一个是tool call,拼接system + tools
|
| 46 |
+
if system_content or tools:
|
| 47 |
+
tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
|
| 48 |
+
if system_content:
|
| 49 |
+
elements += self.format_system.apply(content=(system_content + tool_text) if tool_text else system_content)
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### 1.3 Function Call阶段一致性结论
|
| 53 |
+
|
| 54 |
+
✅ **基本一致**:
|
| 55 |
+
- 两者都在system中包含 `<chat_history>` 和 `<tools>`
|
| 56 |
+
- 两者都使用单独的observation消息携带 `<tool_response>`
|
| 57 |
+
- 历史信息的格式一致(User query, Tool call, Assistant reply)
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## 2. Answer阶段对比
|
| 62 |
+
|
| 63 |
+
### 2.1 推理脚本 (`build_messages_for_answer`)
|
| 64 |
+
|
| 65 |
+
**位置**: `generate_with_qwen_server_list_v2.py:466-567`
|
| 66 |
+
|
| 67 |
+
**逻辑**:
|
| 68 |
+
- system: `system_prompt + <chat_history>` (**不包含tools**)
|
| 69 |
+
- observation: `<tool_response>` (最后一个observation)
|
| 70 |
+
- user: `current_query` (如果不在chat_history中)
|
| 71 |
+
|
| 72 |
+
**关键代码**:
|
| 73 |
+
```python
|
| 74 |
+
# 第542行:明确注释"不包含tools,因为要生成answer"
|
| 75 |
+
# 添加system消息(不包含tools,因为要生成answer)
|
| 76 |
+
messages.append({"role": "system", "content": system_content})
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### 2.2 训练模板 (`_encode` 处理 OBSERVATION → ASSISTANT)
|
| 80 |
+
|
| 81 |
+
**位置**: `template.py:315-371`
|
| 82 |
+
|
| 83 |
+
**逻辑**:
|
| 84 |
+
- 当 `message["role"] == Role.OBSERVATION` 且下一个消息是 `Role.ASSISTANT` 时:
|
| 85 |
+
- system: `system + <chat_history>` (**不包含tools**)
|
| 86 |
+
- observation: `<tool_response>` (当前observation)
|
| 87 |
+
|
| 88 |
+
**关键代码**:
|
| 89 |
+
```python
|
| 90 |
+
# 第356-359行:如果下一个是answer,只拼接system prompt,不拼接tools
|
| 91 |
+
if next_is_assistant:
|
| 92 |
+
# 如果下一个是answer,只拼接system prompt,不拼接tools
|
| 93 |
+
if system_content:
|
| 94 |
+
elements += self.format_system.apply(content=system_content)
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### 2.3 Answer阶段一致性结论
|
| 98 |
+
|
| 99 |
+
✅ **基本一致**:
|
| 100 |
+
- 两者都在system中包含 `<chat_history>` 但**不包含** `<tools>`
|
| 101 |
+
- 两者都使用单独的observation消息携带 `<tool_response>`
|
| 102 |
+
- 历史信息的格式一致(User query, Tool response, Assistant reply,但不包含Tool call)
|
| 103 |
+
|
| 104 |
+
---
|
| 105 |
+
|
| 106 |
+
## 3. 关键不一致点分析
|
| 107 |
+
|
| 108 |
+
### 3.1 潜在不一致:USER消息的处理
|
| 109 |
+
|
| 110 |
+
**训练模板中的USER消息处理** (`template.py:247-312`):
|
| 111 |
+
|
| 112 |
+
**关键代码**:
|
| 113 |
+
```python
|
| 114 |
+
# 第248行注释:所有USER消息(包括首个和后续turn的)都需要添加system和tools
|
| 115 |
+
# 所有USER消息(包括首个和后续turn的)都需要添加system和tools
|
| 116 |
+
|
| 117 |
+
# 第288-306行:所有USER消息都会添加system+tools
|
| 118 |
+
if i == 0:
|
| 119 |
+
# 第一个消息,已经有prefix了,只需要添加system+tools
|
| 120 |
+
if system_content or tools:
|
| 121 |
+
tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
|
| 122 |
+
if system_content:
|
| 123 |
+
elements += self.format_system.apply(content=(system_content + tool_text) if tool_text else system_content)
|
| 124 |
+
else:
|
| 125 |
+
# 后续turn的user消息,需要添加system+tools
|
| 126 |
+
if system_content or tools:
|
| 127 |
+
tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
|
| 128 |
+
if system_content:
|
| 129 |
+
elements += self.format_system.apply(content=(system_content + tool_text) if tool_text else system_content)
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
**问题分析**:
|
| 133 |
+
|
| 134 |
+
在训练时,如果消息序列是:
|
| 135 |
+
```
|
| 136 |
+
USER → FUNCTION → OBSERVATION → ASSISTANT (answer)
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
那么:
|
| 140 |
+
- OBSERVATION消息:system包含 `<chat_history>`,**不包含** `<tools>`(因为下一个是ASSISTANT)
|
| 141 |
+
- ASSISTANT消息:直接格式化,不涉及system
|
| 142 |
+
|
| 143 |
+
**但是**,如果消息序列是:
|
| 144 |
+
```
|
| 145 |
+
OBSERVATION → USER → ASSISTANT (answer)
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
那么:
|
| 149 |
+
- OBSERVATION消息:system包含 `<chat_history>`,**不包含** `<tools>`(因为下一个是ASSISTANT)
|
| 150 |
+
- USER消息���system包含 `<chat_history>` + `<tools>`(第288-306行,所有USER消息都会添加tools)
|
| 151 |
+
- ASSISTANT消息:直接格式化
|
| 152 |
+
|
| 153 |
+
**这意味着**:在训练时,如果observation后面还有user消息,那么user消息会包含tools,但推理脚本在answer阶段不包含tools。
|
| 154 |
+
|
| 155 |
+
### 3.2 推理脚本的answer阶段
|
| 156 |
+
|
| 157 |
+
**推理脚本** (`build_messages_for_answer`):
|
| 158 |
+
- 只构建:system + observation + user(可选)
|
| 159 |
+
- system中**明确不包含tools**(第542行)
|
| 160 |
+
|
| 161 |
+
**训练模板** (`_encode`):
|
| 162 |
+
- 如果observation后面直接是assistant:system不包含tools ✅
|
| 163 |
+
- 如果observation后面是user,然后才是assistant:user消息的system包含tools ❌
|
| 164 |
+
|
| 165 |
+
---
|
| 166 |
+
|
| 167 |
+
## 4. 结论
|
| 168 |
+
|
| 169 |
+
### 4.1 Function Call阶段
|
| 170 |
+
|
| 171 |
+
✅ **基本一致**:
|
| 172 |
+
- 推理脚本和训练模板都在system中包含 `<chat_history>` 和 `<tools>`
|
| 173 |
+
- 格式和结构一致
|
| 174 |
+
|
| 175 |
+
### 4.2 Answer阶段
|
| 176 |
+
|
| 177 |
+
⚠️ **存在不一致**:
|
| 178 |
+
|
| 179 |
+
1. **直接情况**(observation → assistant):
|
| 180 |
+
- ✅ 一致:两者都不包含tools
|
| 181 |
+
|
| 182 |
+
2. **间接情况**(observation → user → assistant):
|
| 183 |
+
- ❌ **不一致**:
|
| 184 |
+
- 推理脚本:system不包含tools
|
| 185 |
+
- 训练模板:user消息的system包含tools(因为所有USER消息都会添加tools)
|
| 186 |
+
|
| 187 |
+
### 4.3 建议
|
| 188 |
+
|
| 189 |
+
**问题**:在训练时,如果消息序列是 `OBSERVATION → USER → ASSISTANT`,USER消息会包含tools,但推理时answer阶段不包含tools。
|
| 190 |
+
|
| 191 |
+
**解决方案**:
|
| 192 |
+
|
| 193 |
+
1. **方案1**:修改训练模板,在生成answer时,如果前一个消息是OBSERVATION且下一个是ASSISTANT,则USER消息也不应该包含tools。
|
| 194 |
+
|
| 195 |
+
2. **方案2**:修改推理脚本,在answer阶段也包含tools(但这与注释中的设计意图不符)。
|
| 196 |
+
|
| 197 |
+
3. **方案3**:确保训练数据中,answer阶段的消息序列是 `OBSERVATION → ASSISTANT`,不包含中间的USER消息。
|
| 198 |
+
|
| 199 |
+
**推荐方案**:方案1或方案3,因为推理脚本的设计意图是"生成answer时不包含tools"。
|
| 200 |
+
|
| 201 |
+
---
|
| 202 |
+
|
| 203 |
+
## 5. 详细代码对比
|
| 204 |
+
|
| 205 |
+
### 5.1 Function Call阶段
|
| 206 |
+
|
| 207 |
+
| 组件 | 推理脚本 | 训练模板 | 一致性 |
|
| 208 |
+
|------|---------|---------|--------|
|
| 209 |
+
| system | system_prompt + chat_history + tools | system + chat_history + tools | ✅ |
|
| 210 |
+
| observation | 单独的observation消息 | 单独的observation消息 | ✅ |
|
| 211 |
+
| user | current_query | current_query | ✅ |
|
| 212 |
+
|
| 213 |
+
### 5.2 Answer阶段
|
| 214 |
+
|
| 215 |
+
| 组件 | 推理脚本 | 训练模板(直接) | 训练模板(间接) | 一致性 |
|
| 216 |
+
|------|---------|----------------|----------------|--------|
|
| 217 |
+
| system | system_prompt + chat_history | system + chat_history | system + chat_history + tools | ⚠️ |
|
| 218 |
+
| observation | 单独的observation消息 | 单独的observation消息 | 单独的observation消息 | ✅ |
|
| 219 |
+
| user | current_query(可选) | 无 | current_query | ⚠️ |
|
| 220 |
+
|
| 221 |
+
---
|
| 222 |
+
|
| 223 |
+
## 6. 总结
|
| 224 |
+
|
| 225 |
+
1. **Function Call阶段**:✅ 基本一致
|
| 226 |
+
2. **Answer阶段(直接)**:✅ 一致(observation → assistant)
|
| 227 |
+
3. **Answer阶段(间接)**:❌ **不一致**(observation → user → assistant)
|
| 228 |
+
|
| 229 |
+
**关键问题**:训练模板中,所有USER消息都会添加tools,但在answer阶段,如果前一个消息是OBSERVATION且下一个是ASSISTANT,推理脚本不包含tools。这可能导致训练和推理的不一致。
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
|
data/dataset/12_10/origin.py
ADDED
|
@@ -0,0 +1,2192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 the LlamaFactory team.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import re
|
| 16 |
+
from copy import deepcopy
|
| 17 |
+
from dataclasses import dataclass
|
| 18 |
+
from typing import TYPE_CHECKING, Optional, Union
|
| 19 |
+
|
| 20 |
+
from typing_extensions import override
|
| 21 |
+
|
| 22 |
+
from ..extras import logging
|
| 23 |
+
from .data_utils import Role
|
| 24 |
+
from .formatter import EmptyFormatter, FunctionFormatter, StringFormatter, ToolFormatter
|
| 25 |
+
from .mm_plugin import get_mm_plugin
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
if TYPE_CHECKING:
|
| 29 |
+
from transformers import PreTrainedTokenizer
|
| 30 |
+
|
| 31 |
+
from ..hparams import DataArguments
|
| 32 |
+
from .formatter import SLOTS, Formatter
|
| 33 |
+
from .mm_plugin import BasePlugin
|
| 34 |
+
from .tool_utils import FunctionCall
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
logger = logging.get_logger(__name__)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@dataclass
|
| 41 |
+
class Template:
|
| 42 |
+
format_user: "Formatter"
|
| 43 |
+
format_assistant: "Formatter"
|
| 44 |
+
format_system: "Formatter"
|
| 45 |
+
format_function: "Formatter"
|
| 46 |
+
format_observation: "Formatter"
|
| 47 |
+
format_tools: "Formatter"
|
| 48 |
+
format_prefix: "Formatter"
|
| 49 |
+
default_system: str
|
| 50 |
+
stop_words: list[str]
|
| 51 |
+
thought_words: tuple[str, str]
|
| 52 |
+
efficient_eos: bool
|
| 53 |
+
replace_eos: bool
|
| 54 |
+
replace_jinja_template: bool
|
| 55 |
+
enable_thinking: Optional[bool]
|
| 56 |
+
mm_plugin: "BasePlugin"
|
| 57 |
+
|
| 58 |
+
def encode_oneturn(
|
| 59 |
+
self,
|
| 60 |
+
tokenizer: "PreTrainedTokenizer",
|
| 61 |
+
messages: list[dict[str, str]],
|
| 62 |
+
system: Optional[str] = None,
|
| 63 |
+
tools: Optional[str] = None,
|
| 64 |
+
) -> tuple[list[int], list[int]]:
|
| 65 |
+
r"""Return a single pair of token ids representing prompt and response respectively."""
|
| 66 |
+
encoded_messages = self._encode(tokenizer, messages, system, tools)
|
| 67 |
+
prompt_ids = []
|
| 68 |
+
for encoded_ids in encoded_messages[:-1]:
|
| 69 |
+
prompt_ids += encoded_ids
|
| 70 |
+
|
| 71 |
+
response_ids = encoded_messages[-1]
|
| 72 |
+
return prompt_ids, response_ids
|
| 73 |
+
|
| 74 |
+
def encode_multiturn(
|
| 75 |
+
self,
|
| 76 |
+
tokenizer: "PreTrainedTokenizer",
|
| 77 |
+
messages: list[dict[str, str]],
|
| 78 |
+
system: Optional[str] = None,
|
| 79 |
+
tools: Optional[str] = None,
|
| 80 |
+
) -> list[tuple[list[int], list[int]]]:
|
| 81 |
+
r"""Return multiple pairs of token ids representing prompts and responses respectively."""
|
| 82 |
+
encoded_messages = self._encode(tokenizer, messages, system, tools)
|
| 83 |
+
|
| 84 |
+
# 添加详细日志记录
|
| 85 |
+
import os
|
| 86 |
+
from datetime import datetime
|
| 87 |
+
|
| 88 |
+
def log_debug(msg):
|
| 89 |
+
"""简单的调试日志函数"""
|
| 90 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
| 91 |
+
log_entry = f"{timestamp} | INFO | {msg}\n"
|
| 92 |
+
|
| 93 |
+
# 写入日志文件
|
| 94 |
+
log_file = "/home/ziqiang/LLaMA-Factory/sharegpt_pair_debug.log"
|
| 95 |
+
try:
|
| 96 |
+
with open(log_file, "a", encoding="utf-8") as f:
|
| 97 |
+
f.write(log_entry)
|
| 98 |
+
f.flush() # 立即刷新到文件
|
| 99 |
+
except:
|
| 100 |
+
pass # 忽略写文件错误
|
| 101 |
+
|
| 102 |
+
# 只写入日志文件,不输出到控制台
|
| 103 |
+
|
| 104 |
+
log_debug("=" * 80)
|
| 105 |
+
log_debug("🔄 ShareGPT数据处理 - encode_multiturn开始")
|
| 106 |
+
log_debug("=" * 80)
|
| 107 |
+
|
| 108 |
+
log_debug(f"📥 输入messages数量: {len(messages)}")
|
| 109 |
+
|
| 110 |
+
# 打印原始消息内容
|
| 111 |
+
for i, msg in enumerate(messages):
|
| 112 |
+
role = msg.get('role', 'unknown')
|
| 113 |
+
content_preview = msg.get('content', '')[:100].replace('\n', '\\n')
|
| 114 |
+
log_debug(f" 📝 Message {i+1}: {role} - {content_preview}...")
|
| 115 |
+
|
| 116 |
+
log_debug(f"🔢 编码后messages数量: {len(encoded_messages)}")
|
| 117 |
+
|
| 118 |
+
# 打印编码后的每个消息段
|
| 119 |
+
for i, encoded in enumerate(encoded_messages):
|
| 120 |
+
log_debug(f" 🧮 编码段 {i+1}: {len(encoded)} tokens")
|
| 121 |
+
if len(encoded) > 0:
|
| 122 |
+
# 解码前50个token看内容
|
| 123 |
+
preview = tokenizer.decode(encoded[:min(50, len(encoded))], skip_special_tokens=False)
|
| 124 |
+
preview = preview.replace("\n", "\\n")
|
| 125 |
+
log_debug(f" 📄 内容预览: {preview}...")
|
| 126 |
+
|
| 127 |
+
pairs = [(encoded_messages[i], encoded_messages[i + 1]) for i in range(0, len(encoded_messages), 2)]
|
| 128 |
+
|
| 129 |
+
log_debug("\n" + "=" * 80)
|
| 130 |
+
log_debug("✂️ Pair分割结果")
|
| 131 |
+
log_debug("=" * 80)
|
| 132 |
+
log_debug(f"📊 生成的pairs数量: {len(pairs)}")
|
| 133 |
+
|
| 134 |
+
for i, (source_ids, target_ids) in enumerate(pairs):
|
| 135 |
+
log_debug(f"\n--- Pair {i+1} ---")
|
| 136 |
+
log_debug(f"📏 Pair {i+1}: source={len(source_ids)} tokens, target={len(target_ids)} tokens")
|
| 137 |
+
|
| 138 |
+
# 解码source和target内容
|
| 139 |
+
if len(source_ids) > 0:
|
| 140 |
+
source_text = tokenizer.decode(source_ids, skip_special_tokens=False)
|
| 141 |
+
source_preview = source_text[:2000].replace("\n", "\\n")
|
| 142 |
+
log_debug(f" 📤 Source内容: {source_text}...")
|
| 143 |
+
|
| 144 |
+
if len(target_ids) > 0:
|
| 145 |
+
target_text = tokenizer.decode(target_ids, skip_special_tokens=False)
|
| 146 |
+
target_preview = target_text[:2000].replace("\n", "\\n")
|
| 147 |
+
log_debug(f" 📥 Target内容: {target_text}...")
|
| 148 |
+
|
| 149 |
+
log_debug("=" * 80)
|
| 150 |
+
log_debug("✅ encode_multiturn完成")
|
| 151 |
+
log_debug("=" * 80)
|
| 152 |
+
|
| 153 |
+
return pairs
|
| 154 |
+
|
| 155 |
+
def extract_tool(self, content: str) -> Union[str, list["FunctionCall"]]:
|
| 156 |
+
r"""Extract tool message."""
|
| 157 |
+
return self.format_tools.extract(content)
|
| 158 |
+
|
| 159 |
+
def get_stop_token_ids(self, tokenizer: "PreTrainedTokenizer") -> list[int]:
|
| 160 |
+
r"""Return stop token ids."""
|
| 161 |
+
stop_token_ids = {tokenizer.eos_token_id}
|
| 162 |
+
for token in self.stop_words:
|
| 163 |
+
stop_token_ids.add(tokenizer.convert_tokens_to_ids(token))
|
| 164 |
+
|
| 165 |
+
return list(stop_token_ids)
|
| 166 |
+
|
| 167 |
+
def add_thought(self, content: str = "") -> str:
|
| 168 |
+
r"""Add empty thought to assistant message."""
|
| 169 |
+
return f"{self.thought_words[0]}\n\n{self.thought_words[1]}\n\n" + content
|
| 170 |
+
|
| 171 |
+
def remove_thought(self, content: str) -> str:
|
| 172 |
+
r"""Remove thought from assistant message."""
|
| 173 |
+
pattern = re.compile(f"{re.escape(self.thought_words[0])}(.*?){re.escape(self.thought_words[1])}", re.DOTALL)
|
| 174 |
+
return re.sub(pattern, "", content).lstrip("\n")
|
| 175 |
+
|
| 176 |
+
def get_thought_word_ids(self, tokenizer: "PreTrainedTokenizer") -> list[int]:
|
| 177 |
+
r"""Get the token ids of thought words."""
|
| 178 |
+
return tokenizer.encode(self.add_thought(), add_special_tokens=False)
|
| 179 |
+
|
| 180 |
+
def _convert_elements_to_ids(self, tokenizer: "PreTrainedTokenizer", elements: "SLOTS") -> list[int]:
|
| 181 |
+
r"""Convert elements to token ids."""
|
| 182 |
+
token_ids = []
|
| 183 |
+
for elem in elements:
|
| 184 |
+
if isinstance(elem, str):
|
| 185 |
+
if len(elem) != 0:
|
| 186 |
+
token_ids += tokenizer.encode(elem, add_special_tokens=False)
|
| 187 |
+
elif isinstance(elem, dict):
|
| 188 |
+
token_ids += [tokenizer.convert_tokens_to_ids(elem.get("token"))]
|
| 189 |
+
elif isinstance(elem, set):
|
| 190 |
+
if "bos_token" in elem and tokenizer.bos_token_id is not None:
|
| 191 |
+
token_ids += [tokenizer.bos_token_id]
|
| 192 |
+
elif "eos_token" in elem and tokenizer.eos_token_id is not None:
|
| 193 |
+
token_ids += [tokenizer.eos_token_id]
|
| 194 |
+
else:
|
| 195 |
+
raise ValueError(f"Input must be string, set[str] or dict[str, str], got {type(elem)}")
|
| 196 |
+
|
| 197 |
+
return token_ids
|
| 198 |
+
|
| 199 |
+
def _encode(
|
| 200 |
+
self,
|
| 201 |
+
tokenizer: "PreTrainedTokenizer",
|
| 202 |
+
messages: list[dict[str, str]],
|
| 203 |
+
system: Optional[str],
|
| 204 |
+
tools: Optional[str],
|
| 205 |
+
) -> list[list[int]]:
|
| 206 |
+
r"""Encode formatted inputs to pairs of token ids.
|
| 207 |
+
|
| 208 |
+
Turn 0: prefix + system + query resp
|
| 209 |
+
Turn t: query resp.
|
| 210 |
+
"""
|
| 211 |
+
system = system or self.default_system
|
| 212 |
+
encoded_messages = []
|
| 213 |
+
for i, message in enumerate(messages):
|
| 214 |
+
elements = []
|
| 215 |
+
|
| 216 |
+
if i == 0:
|
| 217 |
+
elements += self.format_prefix.apply()
|
| 218 |
+
if system or tools:
|
| 219 |
+
tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
|
| 220 |
+
elements += self.format_system.apply(content=(system + tool_text))
|
| 221 |
+
elif message["role"] == Role.OBSERVATION:
|
| 222 |
+
# 对于正常的observation消息,添加system信息(不包含tools)
|
| 223 |
+
if system:
|
| 224 |
+
elements += self.format_system.apply(content=system)
|
| 225 |
+
|
| 226 |
+
# 统计当前已处理的observation数量,用于判断是否需要填充上一个工具返回结果
|
| 227 |
+
observation_count = 0
|
| 228 |
+
for j in range(i-1, -1, -1):
|
| 229 |
+
if messages[j]["role"] == Role.OBSERVATION:
|
| 230 |
+
observation_count += 1
|
| 231 |
+
|
| 232 |
+
# 查找最近的human消息,将其内容添加到observation中
|
| 233 |
+
human_content = ""
|
| 234 |
+
for j in range(i-1, -1, -1):
|
| 235 |
+
if messages[j]["role"] == Role.USER:
|
| 236 |
+
human_content = messages[j]["content"]
|
| 237 |
+
break
|
| 238 |
+
|
| 239 |
+
# 查找上一个FUNCTION消息
|
| 240 |
+
previous_function = None
|
| 241 |
+
for j in range(i-1, -1, -1):
|
| 242 |
+
if messages[j]["role"] == Role.FUNCTION:
|
| 243 |
+
previous_function = messages[j]
|
| 244 |
+
break
|
| 245 |
+
|
| 246 |
+
# 只在observation数量>=2(即至少是第三个observation)时才查找上一个observation
|
| 247 |
+
# 这意味着至少已经有2轮完整的工具调用
|
| 248 |
+
previous_observation_content = ""
|
| 249 |
+
if observation_count >= 3:
|
| 250 |
+
# 查找最近的observation消息(用于multi-hop场景)
|
| 251 |
+
# 需要找到第一个非retrieval_tool的observation
|
| 252 |
+
for j in range(i-1, -1, -1):
|
| 253 |
+
if messages[j]["role"] == Role.OBSERVATION:
|
| 254 |
+
# 检查这个observation对应的FUNCTION是不是retrieval_tool
|
| 255 |
+
is_retrieval = False
|
| 256 |
+
for k in range(j-1, -1, -1):
|
| 257 |
+
if messages[k]["role"] == Role.FUNCTION:
|
| 258 |
+
if "retrieval_tool" in messages[k]["content"]:
|
| 259 |
+
is_retrieval = True
|
| 260 |
+
break
|
| 261 |
+
# 只使用非retrieval_tool的observation内容
|
| 262 |
+
if not is_retrieval:
|
| 263 |
+
previous_observation_content = messages[j]["content"]
|
| 264 |
+
break
|
| 265 |
+
# 如果是retrieval_tool的observation,继续向前查找
|
| 266 |
+
|
| 267 |
+
# 根据是否有previous_observation_content来决定如何拼接
|
| 268 |
+
if previous_observation_content:
|
| 269 |
+
# 如果存在之前的observation,说明这是multi-hop场景
|
| 270 |
+
enhanced_content = f"用户查询: {human_content}\n\n上一个工具返回结果: {previous_observation_content}\n\n当前工具返回结果: {message['content']}"
|
| 271 |
+
elif human_content:
|
| 272 |
+
# 如果没有之前的observation,说明这是single-hop场景
|
| 273 |
+
enhanced_content = f"用户查询: {human_content}\n\n当前工具返回结果: {message['content']}"
|
| 274 |
+
else:
|
| 275 |
+
enhanced_content = message['content']
|
| 276 |
+
|
| 277 |
+
message = {**message, "content": enhanced_content}
|
| 278 |
+
|
| 279 |
+
if message["role"] == Role.USER:
|
| 280 |
+
elements += self.format_user.apply(content=message["content"], idx=str(i // 2))
|
| 281 |
+
elif message["role"] == Role.ASSISTANT:
|
| 282 |
+
elements += self.format_assistant.apply(content=message["content"])
|
| 283 |
+
elif message["role"] == Role.OBSERVATION:
|
| 284 |
+
# 前面已经处理过,这里只需要应用format_observation
|
| 285 |
+
elements += self.format_observation.apply(content=message["content"])
|
| 286 |
+
elif message["role"] == Role.FUNCTION:
|
| 287 |
+
# 直接使用原始内容,不做拼接处理,避免JSON解析错误
|
| 288 |
+
elements += self.format_function.apply(content=message["content"])
|
| 289 |
+
else:
|
| 290 |
+
raise NotImplementedError("Unexpected role: {}".format(message["role"]))
|
| 291 |
+
|
| 292 |
+
encoded_messages.append(self._convert_elements_to_ids(tokenizer, elements))
|
| 293 |
+
|
| 294 |
+
return encoded_messages
|
| 295 |
+
|
| 296 |
+
@staticmethod
|
| 297 |
+
def _add_or_replace_eos_token(tokenizer: "PreTrainedTokenizer", eos_token: str) -> None:
|
| 298 |
+
r"""Add or replace eos token to the tokenizer."""
|
| 299 |
+
if tokenizer.eos_token == eos_token:
|
| 300 |
+
return
|
| 301 |
+
|
| 302 |
+
is_added = tokenizer.eos_token_id is None
|
| 303 |
+
num_added_tokens = tokenizer.add_special_tokens({"eos_token": eos_token})
|
| 304 |
+
|
| 305 |
+
if is_added:
|
| 306 |
+
logger.info_rank0(f"Add eos token: {tokenizer.eos_token}.")
|
| 307 |
+
else:
|
| 308 |
+
logger.info_rank0(f"Replace eos token: {tokenizer.eos_token}.")
|
| 309 |
+
|
| 310 |
+
if num_added_tokens > 0:
|
| 311 |
+
logger.warning_rank0("New tokens have been added, make sure `resize_vocab` is True.")
|
| 312 |
+
|
| 313 |
+
def fix_special_tokens(self, tokenizer: "PreTrainedTokenizer") -> None:
|
| 314 |
+
r"""Add eos token and pad token to the tokenizer."""
|
| 315 |
+
stop_words = self.stop_words
|
| 316 |
+
if self.replace_eos:
|
| 317 |
+
if not stop_words:
|
| 318 |
+
raise ValueError("Stop words are required to replace the EOS token.")
|
| 319 |
+
|
| 320 |
+
self._add_or_replace_eos_token(tokenizer, eos_token=stop_words[0])
|
| 321 |
+
stop_words = stop_words[1:]
|
| 322 |
+
|
| 323 |
+
if tokenizer.eos_token_id is None:
|
| 324 |
+
self._add_or_replace_eos_token(tokenizer, eos_token="<|endoftext|>")
|
| 325 |
+
|
| 326 |
+
if tokenizer.pad_token_id is None:
|
| 327 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 328 |
+
logger.info_rank0(f"Add pad token: {tokenizer.pad_token}")
|
| 329 |
+
|
| 330 |
+
if stop_words:
|
| 331 |
+
num_added_tokens = tokenizer.add_special_tokens(
|
| 332 |
+
dict(additional_special_tokens=stop_words), replace_additional_special_tokens=False
|
| 333 |
+
)
|
| 334 |
+
logger.info_rank0("Add {} to stop words.".format(",".join(stop_words)))
|
| 335 |
+
if num_added_tokens > 0:
|
| 336 |
+
logger.warning_rank0("New tokens have been added, make sure `resize_vocab` is True.")
|
| 337 |
+
|
| 338 |
+
@staticmethod
|
| 339 |
+
def _jinja_escape(content: str) -> str:
|
| 340 |
+
r"""Escape single quotes in content."""
|
| 341 |
+
return content.replace("'", r"\'")
|
| 342 |
+
|
| 343 |
+
@staticmethod
|
| 344 |
+
def _convert_slots_to_jinja(slots: "SLOTS", tokenizer: "PreTrainedTokenizer", placeholder: str = "content") -> str:
|
| 345 |
+
r"""Convert slots to jinja template."""
|
| 346 |
+
slot_items = []
|
| 347 |
+
for slot in slots:
|
| 348 |
+
if isinstance(slot, str):
|
| 349 |
+
slot_pieces = slot.split("{{content}}")
|
| 350 |
+
if slot_pieces[0]:
|
| 351 |
+
slot_items.append("'" + Template._jinja_escape(slot_pieces[0]) + "'")
|
| 352 |
+
if len(slot_pieces) > 1:
|
| 353 |
+
slot_items.append(placeholder)
|
| 354 |
+
if slot_pieces[1]:
|
| 355 |
+
slot_items.append("'" + Template._jinja_escape(slot_pieces[1]) + "'")
|
| 356 |
+
elif isinstance(slot, set): # do not use {{ eos_token }} since it may be replaced
|
| 357 |
+
if "bos_token" in slot and tokenizer.bos_token_id is not None:
|
| 358 |
+
slot_items.append("'" + tokenizer.bos_token + "'")
|
| 359 |
+
elif "eos_token" in slot and tokenizer.eos_token_id is not None:
|
| 360 |
+
slot_items.append("'" + tokenizer.eos_token + "'")
|
| 361 |
+
elif isinstance(slot, dict):
|
| 362 |
+
raise ValueError("Dict is not supported.")
|
| 363 |
+
|
| 364 |
+
return " + ".join(slot_items)
|
| 365 |
+
|
| 366 |
+
def _get_jinja_template(self, tokenizer: "PreTrainedTokenizer") -> str:
|
| 367 |
+
r"""Return the jinja template."""
|
| 368 |
+
prefix = self._convert_slots_to_jinja(self.format_prefix.apply(), tokenizer)
|
| 369 |
+
system = self._convert_slots_to_jinja(self.format_system.apply(), tokenizer, placeholder="system_message")
|
| 370 |
+
user = self._convert_slots_to_jinja(self.format_user.apply(), tokenizer)
|
| 371 |
+
assistant = self._convert_slots_to_jinja(self.format_assistant.apply(), tokenizer)
|
| 372 |
+
jinja_template = ""
|
| 373 |
+
if prefix:
|
| 374 |
+
jinja_template += "{{ " + prefix + " }}"
|
| 375 |
+
|
| 376 |
+
if self.default_system:
|
| 377 |
+
jinja_template += "{% set system_message = '" + self._jinja_escape(self.default_system) + "' %}"
|
| 378 |
+
|
| 379 |
+
jinja_template += (
|
| 380 |
+
"{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}"
|
| 381 |
+
"{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% endif %}"
|
| 382 |
+
"{% if system_message is defined %}{{ " + system + " }}{% endif %}"
|
| 383 |
+
"{% for message in loop_messages %}"
|
| 384 |
+
"{% set content = message['content'] %}"
|
| 385 |
+
"{% if message['role'] == 'user' %}"
|
| 386 |
+
"{{ " + user + " }}"
|
| 387 |
+
"{% elif message['role'] == 'assistant' %}"
|
| 388 |
+
"{{ " + assistant + " }}"
|
| 389 |
+
"{% endif %}"
|
| 390 |
+
"{% endfor %}"
|
| 391 |
+
)
|
| 392 |
+
return jinja_template
|
| 393 |
+
|
| 394 |
+
def fix_jinja_template(self, tokenizer: "PreTrainedTokenizer") -> None:
|
| 395 |
+
r"""Replace the jinja template in the tokenizer."""
|
| 396 |
+
if tokenizer.chat_template is None or self.replace_jinja_template:
|
| 397 |
+
try:
|
| 398 |
+
tokenizer.chat_template = self._get_jinja_template(tokenizer)
|
| 399 |
+
except ValueError as e:
|
| 400 |
+
logger.info_rank0(f"Cannot add this chat template to tokenizer: {e}.")
|
| 401 |
+
|
| 402 |
+
@staticmethod
|
| 403 |
+
def _convert_slots_to_ollama(
|
| 404 |
+
slots: "SLOTS", tokenizer: "PreTrainedTokenizer", placeholder: str = "content"
|
| 405 |
+
) -> str:
|
| 406 |
+
r"""Convert slots to ollama template."""
|
| 407 |
+
slot_items = []
|
| 408 |
+
for slot in slots:
|
| 409 |
+
if isinstance(slot, str):
|
| 410 |
+
slot_pieces = slot.split("{{content}}")
|
| 411 |
+
if slot_pieces[0]:
|
| 412 |
+
slot_items.append(slot_pieces[0])
|
| 413 |
+
if len(slot_pieces) > 1:
|
| 414 |
+
slot_items.append("{{ " + placeholder + " }}")
|
| 415 |
+
if slot_pieces[1]:
|
| 416 |
+
slot_items.append(slot_pieces[1])
|
| 417 |
+
elif isinstance(slot, set): # do not use {{ eos_token }} since it may be replaced
|
| 418 |
+
if "bos_token" in slot and tokenizer.bos_token_id is not None:
|
| 419 |
+
slot_items.append(tokenizer.bos_token)
|
| 420 |
+
elif "eos_token" in slot and tokenizer.eos_token_id is not None:
|
| 421 |
+
slot_items.append(tokenizer.eos_token)
|
| 422 |
+
elif isinstance(slot, dict):
|
| 423 |
+
raise ValueError("Dict is not supported.")
|
| 424 |
+
|
| 425 |
+
return "".join(slot_items)
|
| 426 |
+
|
| 427 |
+
def _get_ollama_template(self, tokenizer: "PreTrainedTokenizer") -> str:
|
| 428 |
+
r"""Return the ollama template."""
|
| 429 |
+
prefix = self._convert_slots_to_ollama(self.format_prefix.apply(), tokenizer)
|
| 430 |
+
system = self._convert_slots_to_ollama(self.format_system.apply(), tokenizer, placeholder=".System")
|
| 431 |
+
user = self._convert_slots_to_ollama(self.format_user.apply(), tokenizer, placeholder=".Content")
|
| 432 |
+
assistant = self._convert_slots_to_ollama(self.format_assistant.apply(), tokenizer, placeholder=".Content")
|
| 433 |
+
return (
|
| 434 |
+
f"{prefix}{{{{ if .System }}}}{system}{{{{ end }}}}"
|
| 435 |
+
f"""{{{{ range .Messages }}}}{{{{ if eq .Role "user" }}}}{user}"""
|
| 436 |
+
f"""{{{{ else if eq .Role "assistant" }}}}{assistant}{{{{ end }}}}{{{{ end }}}}"""
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
def get_ollama_modelfile(self, tokenizer: "PreTrainedTokenizer") -> str:
|
| 440 |
+
r"""Return the ollama modelfile.
|
| 441 |
+
|
| 442 |
+
TODO: support function calling.
|
| 443 |
+
"""
|
| 444 |
+
modelfile = "# ollama modelfile auto-generated by llamafactory\n\n"
|
| 445 |
+
modelfile += f'FROM .\n\nTEMPLATE """{self._get_ollama_template(tokenizer)}"""\n\n'
|
| 446 |
+
|
| 447 |
+
if self.default_system:
|
| 448 |
+
modelfile += f'SYSTEM """{self.default_system}"""\n\n'
|
| 449 |
+
|
| 450 |
+
for stop_token_id in self.get_stop_token_ids(tokenizer):
|
| 451 |
+
modelfile += f'PARAMETER stop "{tokenizer.convert_ids_to_tokens(stop_token_id)}"\n'
|
| 452 |
+
|
| 453 |
+
modelfile += "PARAMETER num_ctx 4096\n"
|
| 454 |
+
return modelfile
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
@dataclass
|
| 458 |
+
class Llama2Template(Template):
|
| 459 |
+
r"""A template that fuse the system message to first user message."""
|
| 460 |
+
|
| 461 |
+
@override
|
| 462 |
+
def _encode(
|
| 463 |
+
self,
|
| 464 |
+
tokenizer: "PreTrainedTokenizer",
|
| 465 |
+
messages: list[dict[str, str]],
|
| 466 |
+
system: str,
|
| 467 |
+
tools: str,
|
| 468 |
+
) -> list[list[int]]:
|
| 469 |
+
system = system or self.default_system
|
| 470 |
+
encoded_messages = []
|
| 471 |
+
for i, message in enumerate(messages):
|
| 472 |
+
elements = []
|
| 473 |
+
|
| 474 |
+
system_text = ""
|
| 475 |
+
if i == 0:
|
| 476 |
+
elements += self.format_prefix.apply()
|
| 477 |
+
if system or tools:
|
| 478 |
+
tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
|
| 479 |
+
system_text = self.format_system.apply(content=(system + tool_text))[0]
|
| 480 |
+
|
| 481 |
+
if message["role"] == Role.USER:
|
| 482 |
+
elements += self.format_user.apply(content=system_text + message["content"])
|
| 483 |
+
elif message["role"] == Role.ASSISTANT:
|
| 484 |
+
elements += self.format_assistant.apply(content=message["content"])
|
| 485 |
+
elif message["role"] == Role.OBSERVATION:
|
| 486 |
+
# 统计当前已处理的observation数量
|
| 487 |
+
observation_count = 0
|
| 488 |
+
for j in range(i-1, -1, -1):
|
| 489 |
+
if messages[j]["role"] == Role.OBSERVATION:
|
| 490 |
+
observation_count += 1
|
| 491 |
+
|
| 492 |
+
# 查找最近的human消息,将其内容添加到observation中
|
| 493 |
+
human_content = ""
|
| 494 |
+
for j in range(i-1, -1, -1):
|
| 495 |
+
if messages[j]["role"] == Role.USER:
|
| 496 |
+
human_content = messages[j]["content"]
|
| 497 |
+
break
|
| 498 |
+
|
| 499 |
+
# 查找上一个FUNCTION消息
|
| 500 |
+
previous_function = None
|
| 501 |
+
for j in range(i-1, -1, -1):
|
| 502 |
+
if messages[j]["role"] == Role.FUNCTION:
|
| 503 |
+
previous_function = messages[j]
|
| 504 |
+
break
|
| 505 |
+
|
| 506 |
+
# 只在observation数量>=2时才查找上一个observation
|
| 507 |
+
previous_observation_content = ""
|
| 508 |
+
if observation_count >= 3:
|
| 509 |
+
for j in range(i-1, -1, -1):
|
| 510 |
+
if messages[j]["role"] == Role.OBSERVATION:
|
| 511 |
+
# 检查这个observation对应的FUNCTION是不是retrieval_tool
|
| 512 |
+
is_retrieval = False
|
| 513 |
+
for k in range(j-1, -1, -1):
|
| 514 |
+
if messages[k]["role"] == Role.FUNCTION:
|
| 515 |
+
if "retrieval_tool" in messages[k]["content"]:
|
| 516 |
+
is_retrieval = True
|
| 517 |
+
break
|
| 518 |
+
# 只使用非retrieval_tool的observation内容
|
| 519 |
+
if not is_retrieval:
|
| 520 |
+
previous_observation_content = messages[j]["content"]
|
| 521 |
+
break
|
| 522 |
+
|
| 523 |
+
# 根据是否有previous_observation_content来决定如何拼接
|
| 524 |
+
if previous_observation_content:
|
| 525 |
+
# 如果存在之前的observation,说明这是multi-hop场景
|
| 526 |
+
enhanced_content = f"用户查询: {human_content}\n\n上一个工具返回结果: {previous_observation_content}\n\n当前工具返回结果: {message['content']}"
|
| 527 |
+
elements += self.format_observation.apply(content=enhanced_content)
|
| 528 |
+
elif human_content:
|
| 529 |
+
# 如果没有之前的observation,说明这是single-hop场景
|
| 530 |
+
enhanced_content = f"用户查询: {human_content}\n\n当前工具返回结果: {message['content']}"
|
| 531 |
+
elements += self.format_observation.apply(content=enhanced_content)
|
| 532 |
+
else:
|
| 533 |
+
elements += self.format_observation.apply(content=message["content"])
|
| 534 |
+
elif message["role"] == Role.FUNCTION:
|
| 535 |
+
# 直接使用原始内容,不做拼接处理,避免JSON解析错误
|
| 536 |
+
elements += self.format_function.apply(content=message["content"])
|
| 537 |
+
else:
|
| 538 |
+
raise NotImplementedError("Unexpected role: {}".format(message["role"]))
|
| 539 |
+
|
| 540 |
+
encoded_messages.append(self._convert_elements_to_ids(tokenizer, elements))
|
| 541 |
+
|
| 542 |
+
return encoded_messages
|
| 543 |
+
|
| 544 |
+
def _get_jinja_template(self, tokenizer: "PreTrainedTokenizer") -> str:
|
| 545 |
+
prefix = self._convert_slots_to_jinja(self.format_prefix.apply(), tokenizer)
|
| 546 |
+
system_message = self._convert_slots_to_jinja(
|
| 547 |
+
self.format_system.apply(), tokenizer, placeholder="system_message"
|
| 548 |
+
)
|
| 549 |
+
user_message = self._convert_slots_to_jinja(self.format_user.apply(), tokenizer)
|
| 550 |
+
assistant_message = self._convert_slots_to_jinja(self.format_assistant.apply(), tokenizer)
|
| 551 |
+
jinja_template = ""
|
| 552 |
+
if prefix:
|
| 553 |
+
jinja_template += "{{ " + prefix + " }}"
|
| 554 |
+
|
| 555 |
+
if self.default_system:
|
| 556 |
+
jinja_template += "{% set system_message = '" + self._jinja_escape(self.default_system) + "' %}"
|
| 557 |
+
|
| 558 |
+
jinja_template += (
|
| 559 |
+
"{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}"
|
| 560 |
+
"{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% endif %}"
|
| 561 |
+
"{% for message in loop_messages %}"
|
| 562 |
+
"{% if loop.index0 == 0 and system_message is defined %}"
|
| 563 |
+
"{% set content = " + system_message + " + message['content'] %}"
|
| 564 |
+
"{% else %}{% set content = message['content'] %}{% endif %}"
|
| 565 |
+
"{% if message['role'] == 'user' %}"
|
| 566 |
+
"{{ " + user_message + " }}"
|
| 567 |
+
"{% elif message['role'] == 'assistant' %}"
|
| 568 |
+
"{{ " + assistant_message + " }}"
|
| 569 |
+
"{% endif %}"
|
| 570 |
+
"{% endfor %}"
|
| 571 |
+
)
|
| 572 |
+
return jinja_template
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
@dataclass
|
| 576 |
+
class ReasoningTemplate(Template):
|
| 577 |
+
r"""A template that add thought to assistant message."""
|
| 578 |
+
|
| 579 |
+
@override
|
| 580 |
+
def encode_oneturn(
|
| 581 |
+
self,
|
| 582 |
+
tokenizer: "PreTrainedTokenizer",
|
| 583 |
+
messages: list[dict[str, str]],
|
| 584 |
+
system: Optional[str] = None,
|
| 585 |
+
tools: Optional[str] = None,
|
| 586 |
+
) -> tuple[list[int], list[int]]:
|
| 587 |
+
messages = deepcopy(messages)
|
| 588 |
+
for i in range(1, len(messages) - 2, 2):
|
| 589 |
+
messages[i]["content"] = self.remove_thought(messages[i]["content"])
|
| 590 |
+
|
| 591 |
+
if self.enable_thinking is False: # remove all cot
|
| 592 |
+
messages[-1]["content"] = self.remove_thought(messages[-1]["content"])
|
| 593 |
+
|
| 594 |
+
prompt_ids, response_ids = super().encode_oneturn(tokenizer, messages, system, tools)
|
| 595 |
+
if (
|
| 596 |
+
self.thought_words[0] not in messages[-1]["content"]
|
| 597 |
+
and self.thought_words[1] not in messages[-1]["content"]
|
| 598 |
+
): # add empty cot
|
| 599 |
+
if not self.enable_thinking: # do not compute loss
|
| 600 |
+
prompt_ids += self.get_thought_word_ids(tokenizer)
|
| 601 |
+
else: # do compute loss
|
| 602 |
+
response_ids = self.get_thought_word_ids(tokenizer) + response_ids
|
| 603 |
+
|
| 604 |
+
return prompt_ids, response_ids
|
| 605 |
+
|
| 606 |
+
@override
|
| 607 |
+
def encode_multiturn(
|
| 608 |
+
self,
|
| 609 |
+
tokenizer: "PreTrainedTokenizer",
|
| 610 |
+
messages: list[dict[str, str]],
|
| 611 |
+
system: Optional[str] = None,
|
| 612 |
+
tools: Optional[str] = None,
|
| 613 |
+
) -> list[tuple[list[int], list[int]]]:
|
| 614 |
+
# 添加详细日志记录
|
| 615 |
+
import os
|
| 616 |
+
from datetime import datetime
|
| 617 |
+
|
| 618 |
+
def log_debug(msg):
|
| 619 |
+
"""简单的调试日志函数"""
|
| 620 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
| 621 |
+
log_entry = f"{timestamp} | INFO | {msg}\n"
|
| 622 |
+
|
| 623 |
+
# 写入日志文件
|
| 624 |
+
log_file = "/home/ziqiang/LLaMA-Factory/sharegpt_pair_debug.log"
|
| 625 |
+
try:
|
| 626 |
+
with open(log_file, "a", encoding="utf-8") as f:
|
| 627 |
+
f.write(log_entry)
|
| 628 |
+
f.flush() # 立即刷新到文件
|
| 629 |
+
except:
|
| 630 |
+
pass # 忽略写文件错误
|
| 631 |
+
|
| 632 |
+
# 只写入日志文件,不输出到控制台
|
| 633 |
+
|
| 634 |
+
log_debug("=" * 80)
|
| 635 |
+
log_debug("🔄 ReasoningTemplate数据处理 - encode_multiturn开始")
|
| 636 |
+
log_debug("=" * 80)
|
| 637 |
+
|
| 638 |
+
log_debug(f"📥 输入messages数量: {len(messages)}")
|
| 639 |
+
log_debug(f"🧠 enable_thinking: {self.enable_thinking}")
|
| 640 |
+
|
| 641 |
+
# 打印原始消息内容
|
| 642 |
+
for i, msg in enumerate(messages):
|
| 643 |
+
role = msg.get('role', 'unknown')
|
| 644 |
+
content_preview = msg.get('content', '')[:8000].replace('\n', '\\n')
|
| 645 |
+
log_debug(f" 📝 Message {i+1}: {role} - {content_preview}...")
|
| 646 |
+
|
| 647 |
+
messages = deepcopy(messages)
|
| 648 |
+
if self.enable_thinking is False: # remove all cot
|
| 649 |
+
for i in range(1, len(messages), 2):
|
| 650 |
+
messages[i]["content"] = self.remove_thought(messages[i]["content"])
|
| 651 |
+
log_debug(f" 🧹 移除了Message {i+1}中的思考内容")
|
| 652 |
+
|
| 653 |
+
encoded_messages = self._encode(tokenizer, messages, system, tools)
|
| 654 |
+
log_debug(f"🔢 编码后messages数量: {len(encoded_messages)}")
|
| 655 |
+
|
| 656 |
+
# 打印���码后的每个消息段
|
| 657 |
+
for i, encoded in enumerate(encoded_messages):
|
| 658 |
+
log_debug(f" 🧮 编码段 {i+1}: {len(encoded)} tokens")
|
| 659 |
+
if len(encoded) > 0:
|
| 660 |
+
# 解码前50个token看内容
|
| 661 |
+
preview = tokenizer.decode(encoded[:min(50, len(encoded))], skip_special_tokens=False)
|
| 662 |
+
preview = preview.replace("\n", "\\n")
|
| 663 |
+
log_debug(f" 📄 内容预览: {preview}...")
|
| 664 |
+
|
| 665 |
+
for i in range(0, len(messages), 2):
|
| 666 |
+
if (
|
| 667 |
+
self.thought_words[0] not in messages[i + 1]["content"]
|
| 668 |
+
and self.thought_words[1] not in messages[i + 1]["content"]
|
| 669 |
+
): # add empty cot
|
| 670 |
+
log_debug(f" 💭 为Message {i+2}添加空思考标签")
|
| 671 |
+
if not self.enable_thinking: # do not compute loss
|
| 672 |
+
encoded_messages[i] += self.get_thought_word_ids(tokenizer)
|
| 673 |
+
else: # do compute loss
|
| 674 |
+
encoded_messages[i + 1] = self.get_thought_word_ids(tokenizer) + encoded_messages[i + 1]
|
| 675 |
+
|
| 676 |
+
pairs = [(encoded_messages[i], encoded_messages[i + 1]) for i in range(0, len(encoded_messages), 2)]
|
| 677 |
+
|
| 678 |
+
log_debug("\n" + "=" * 80)
|
| 679 |
+
log_debug("✂️ Pair分割结果")
|
| 680 |
+
log_debug("=" * 80)
|
| 681 |
+
log_debug(f"📊 生成的pairs数量: {len(pairs)}")
|
| 682 |
+
|
| 683 |
+
for i, (source_ids, target_ids) in enumerate(pairs):
|
| 684 |
+
log_debug(f"\n--- Pair {i+1} ---")
|
| 685 |
+
log_debug(f"📏 Pair {i+1}: source={len(source_ids)} tokens, target={len(target_ids)} tokens")
|
| 686 |
+
|
| 687 |
+
# 解码source和target内容
|
| 688 |
+
if len(source_ids) > 0:
|
| 689 |
+
source_text = tokenizer.decode(source_ids, skip_special_tokens=False)
|
| 690 |
+
source_preview = source_text[:2000].replace("\n", "\\n")
|
| 691 |
+
log_debug(f" 📤 Source内容: {source_text}...")
|
| 692 |
+
|
| 693 |
+
if len(target_ids) > 0:
|
| 694 |
+
target_text = tokenizer.decode(target_ids, skip_special_tokens=False)
|
| 695 |
+
target_preview = target_text[:2000].replace("\n", "\\n")
|
| 696 |
+
log_debug(f" 📥 Target内容: {target_text}...")
|
| 697 |
+
|
| 698 |
+
log_debug("=" * 80)
|
| 699 |
+
log_debug("✅ ReasoningTemplate encode_multiturn完成")
|
| 700 |
+
log_debug("=" * 80)
|
| 701 |
+
|
| 702 |
+
return pairs
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
TEMPLATES: dict[str, "Template"] = {}
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
def register_template(
|
| 709 |
+
name: str,
|
| 710 |
+
format_user: Optional["Formatter"] = None,
|
| 711 |
+
format_assistant: Optional["Formatter"] = None,
|
| 712 |
+
format_system: Optional["Formatter"] = None,
|
| 713 |
+
format_function: Optional["Formatter"] = None,
|
| 714 |
+
format_observation: Optional["Formatter"] = None,
|
| 715 |
+
format_tools: Optional["Formatter"] = None,
|
| 716 |
+
format_prefix: Optional["Formatter"] = None,
|
| 717 |
+
default_system: str = "",
|
| 718 |
+
stop_words: Optional[list[str]] = None,
|
| 719 |
+
thought_words: Optional[tuple[str, str]] = None,
|
| 720 |
+
efficient_eos: bool = False,
|
| 721 |
+
replace_eos: bool = False,
|
| 722 |
+
replace_jinja_template: bool = False,
|
| 723 |
+
enable_thinking: Optional[bool] = True,
|
| 724 |
+
mm_plugin: "BasePlugin" = get_mm_plugin(name="base"),
|
| 725 |
+
template_class: type["Template"] = Template,
|
| 726 |
+
) -> None:
|
| 727 |
+
r"""Register a chat template.
|
| 728 |
+
|
| 729 |
+
To add the following chat template:
|
| 730 |
+
```
|
| 731 |
+
<s><user>user prompt here
|
| 732 |
+
<model>model response here</s>
|
| 733 |
+
<user>user prompt here
|
| 734 |
+
<model>model response here</s>
|
| 735 |
+
```
|
| 736 |
+
|
| 737 |
+
The corresponding code should be:
|
| 738 |
+
```
|
| 739 |
+
register_template(
|
| 740 |
+
name="custom",
|
| 741 |
+
format_user=StringFormatter(slots=["<user>{{content}}\n<model>"]),
|
| 742 |
+
format_assistant=StringFormatter(slots=["{{content}}</s>\n"]),
|
| 743 |
+
format_prefix=EmptyFormatter("<s>"),
|
| 744 |
+
)
|
| 745 |
+
```
|
| 746 |
+
"""
|
| 747 |
+
if name in TEMPLATES:
|
| 748 |
+
raise ValueError(f"Template {name} already exists.")
|
| 749 |
+
|
| 750 |
+
default_slots = ["{{content}}"] if efficient_eos else ["{{content}}", {"eos_token"}]
|
| 751 |
+
default_user_formatter = StringFormatter(slots=["{{content}}"])
|
| 752 |
+
default_assistant_formatter = StringFormatter(slots=default_slots)
|
| 753 |
+
if format_assistant is not None:
|
| 754 |
+
default_function_formatter = FunctionFormatter(slots=format_assistant.slots, tool_format="default")
|
| 755 |
+
else:
|
| 756 |
+
default_function_formatter = FunctionFormatter(slots=default_slots, tool_format="default")
|
| 757 |
+
|
| 758 |
+
default_tool_formatter = ToolFormatter(tool_format="default")
|
| 759 |
+
default_prefix_formatter = EmptyFormatter()
|
| 760 |
+
TEMPLATES[name] = template_class(
|
| 761 |
+
format_user=format_user or default_user_formatter,
|
| 762 |
+
format_assistant=format_assistant or default_assistant_formatter,
|
| 763 |
+
format_system=format_system or default_user_formatter,
|
| 764 |
+
format_function=format_function or default_function_formatter,
|
| 765 |
+
format_observation=format_observation or format_user or default_user_formatter,
|
| 766 |
+
format_tools=format_tools or default_tool_formatter,
|
| 767 |
+
format_prefix=format_prefix or default_prefix_formatter,
|
| 768 |
+
default_system=default_system,
|
| 769 |
+
stop_words=stop_words or [],
|
| 770 |
+
thought_words=thought_words or ("<think>", "</think>"),
|
| 771 |
+
efficient_eos=efficient_eos,
|
| 772 |
+
replace_eos=replace_eos,
|
| 773 |
+
replace_jinja_template=replace_jinja_template,
|
| 774 |
+
enable_thinking=enable_thinking,
|
| 775 |
+
mm_plugin=mm_plugin,
|
| 776 |
+
)
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
def parse_template(tokenizer: "PreTrainedTokenizer") -> "Template":
|
| 780 |
+
r"""Extract a chat template from the tokenizer."""
|
| 781 |
+
|
| 782 |
+
def find_diff(short_str: str, long_str: str) -> str:
|
| 783 |
+
i, j = 0, 0
|
| 784 |
+
diff = ""
|
| 785 |
+
while i < len(short_str) and j < len(long_str):
|
| 786 |
+
if short_str[i] == long_str[j]:
|
| 787 |
+
i += 1
|
| 788 |
+
j += 1
|
| 789 |
+
else:
|
| 790 |
+
diff += long_str[j]
|
| 791 |
+
j += 1
|
| 792 |
+
|
| 793 |
+
return diff
|
| 794 |
+
|
| 795 |
+
prefix = tokenizer.decode(tokenizer.encode(""))
|
| 796 |
+
|
| 797 |
+
messages = [{"role": "system", "content": "{{content}}"}]
|
| 798 |
+
system_slot = tokenizer.apply_chat_template(messages, add_generation_prompt=False, tokenize=False)[len(prefix) :]
|
| 799 |
+
|
| 800 |
+
messages = [{"role": "system", "content": ""}, {"role": "user", "content": "{{content}}"}]
|
| 801 |
+
user_slot_empty_system = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
| 802 |
+
user_slot_empty_system = user_slot_empty_system[len(prefix) :]
|
| 803 |
+
|
| 804 |
+
messages = [{"role": "user", "content": "{{content}}"}]
|
| 805 |
+
user_slot = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
| 806 |
+
user_slot = user_slot[len(prefix) :]
|
| 807 |
+
|
| 808 |
+
messages = [{"role": "user", "content": "{{content}}"}, {"role": "assistant", "content": "{{content}}"}]
|
| 809 |
+
assistant_slot = tokenizer.apply_chat_template(messages, add_generation_prompt=False, tokenize=False)
|
| 810 |
+
assistant_slot = assistant_slot[len(prefix) + len(user_slot) :]
|
| 811 |
+
template_class = ReasoningTemplate if "<think>" in assistant_slot else Template
|
| 812 |
+
assistant_slot = assistant_slot.replace("<think>", "").replace("</think>", "").lstrip("\n") # remove thought tags
|
| 813 |
+
|
| 814 |
+
if len(user_slot) > len(user_slot_empty_system):
|
| 815 |
+
default_system = find_diff(user_slot_empty_system, user_slot)
|
| 816 |
+
sole_system = system_slot.replace("{{content}}", default_system, 1)
|
| 817 |
+
user_slot = user_slot[len(sole_system) :]
|
| 818 |
+
else: # if defaut_system is empty, user_slot_empty_system will be longer than user_slot
|
| 819 |
+
default_system = ""
|
| 820 |
+
|
| 821 |
+
return template_class(
|
| 822 |
+
format_user=StringFormatter(slots=[user_slot]),
|
| 823 |
+
format_assistant=StringFormatter(slots=[assistant_slot]),
|
| 824 |
+
format_system=StringFormatter(slots=[system_slot]),
|
| 825 |
+
format_function=FunctionFormatter(slots=[assistant_slot], tool_format="default"),
|
| 826 |
+
format_observation=StringFormatter(slots=[user_slot]),
|
| 827 |
+
format_tools=ToolFormatter(tool_format="default"),
|
| 828 |
+
format_prefix=EmptyFormatter(slots=[prefix]) if prefix else EmptyFormatter(),
|
| 829 |
+
default_system=default_system,
|
| 830 |
+
stop_words=[],
|
| 831 |
+
thought_words=("<think>", "</think>"),
|
| 832 |
+
efficient_eos=False,
|
| 833 |
+
replace_eos=False,
|
| 834 |
+
replace_jinja_template=False,
|
| 835 |
+
enable_thinking=True,
|
| 836 |
+
mm_plugin=get_mm_plugin(name="base"),
|
| 837 |
+
)
|
| 838 |
+
|
| 839 |
+
|
| 840 |
+
def get_template_and_fix_tokenizer(tokenizer: "PreTrainedTokenizer", data_args: "DataArguments") -> "Template":
|
| 841 |
+
r"""Get chat template and fixes the tokenizer."""
|
| 842 |
+
if data_args.template is None:
|
| 843 |
+
if isinstance(tokenizer.chat_template, str):
|
| 844 |
+
logger.warning_rank0("`template` was not specified, try parsing the chat template from the tokenizer.")
|
| 845 |
+
template = parse_template(tokenizer)
|
| 846 |
+
else:
|
| 847 |
+
logger.warning_rank0("`template` was not specified, use `empty` template.")
|
| 848 |
+
template = TEMPLATES["empty"] # placeholder
|
| 849 |
+
else:
|
| 850 |
+
if data_args.template not in TEMPLATES:
|
| 851 |
+
raise ValueError(f"Template {data_args.template} does not exist.")
|
| 852 |
+
|
| 853 |
+
template = TEMPLATES[data_args.template]
|
| 854 |
+
|
| 855 |
+
if data_args.train_on_prompt and template.efficient_eos:
|
| 856 |
+
raise ValueError("Current template does not support `train_on_prompt`.")
|
| 857 |
+
|
| 858 |
+
if data_args.tool_format is not None:
|
| 859 |
+
logger.info_rank0(f"Using tool format: {data_args.tool_format}.")
|
| 860 |
+
default_slots = ["{{content}}"] if template.efficient_eos else ["{{content}}", {"eos_token"}]
|
| 861 |
+
template.format_function = FunctionFormatter(slots=default_slots, tool_format=data_args.tool_format)
|
| 862 |
+
template.format_tools = ToolFormatter(tool_format=data_args.tool_format)
|
| 863 |
+
|
| 864 |
+
if data_args.default_system is not None:
|
| 865 |
+
logger.info_rank0(f"Using default system message: {data_args.default_system}.")
|
| 866 |
+
template.default_system = data_args.default_system
|
| 867 |
+
|
| 868 |
+
template.enable_thinking = data_args.enable_thinking
|
| 869 |
+
template.fix_special_tokens(tokenizer)
|
| 870 |
+
template.fix_jinja_template(tokenizer)
|
| 871 |
+
return template
|
| 872 |
+
|
| 873 |
+
|
| 874 |
+
register_template(
|
| 875 |
+
name="alpaca",
|
| 876 |
+
format_user=StringFormatter(slots=["### Instruction:\n{{content}}\n\n### Response:\n"]),
|
| 877 |
+
format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n\n"]),
|
| 878 |
+
default_system=(
|
| 879 |
+
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n"
|
| 880 |
+
),
|
| 881 |
+
replace_jinja_template=True,
|
| 882 |
+
)
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
register_template(
|
| 886 |
+
name="aquila",
|
| 887 |
+
format_user=StringFormatter(slots=["Human: {{content}}###Assistant:"]),
|
| 888 |
+
format_assistant=StringFormatter(slots=["{{content}}###"]),
|
| 889 |
+
format_system=StringFormatter(slots=["System: {{content}}###"]),
|
| 890 |
+
default_system=(
|
| 891 |
+
"A chat between a curious human and an artificial intelligence assistant. "
|
| 892 |
+
"The assistant gives helpful, detailed, and polite answers to the human's questions."
|
| 893 |
+
),
|
| 894 |
+
stop_words=["</s>"],
|
| 895 |
+
)
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
register_template(
|
| 899 |
+
name="atom",
|
| 900 |
+
format_user=StringFormatter(
|
| 901 |
+
slots=[{"bos_token"}, "Human: {{content}}\n", {"eos_token"}, {"bos_token"}, "Assistant:"]
|
| 902 |
+
),
|
| 903 |
+
format_assistant=StringFormatter(slots=["{{content}}\n", {"eos_token"}]),
|
| 904 |
+
)
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
register_template(
|
| 908 |
+
name="baichuan",
|
| 909 |
+
format_user=StringFormatter(slots=[{"token": "<reserved_102>"}, "{{content}}", {"token": "<reserved_103>"}]),
|
| 910 |
+
efficient_eos=True,
|
| 911 |
+
)
|
| 912 |
+
|
| 913 |
+
|
| 914 |
+
register_template(
|
| 915 |
+
name="baichuan2",
|
| 916 |
+
format_user=StringFormatter(slots=["<reserved_106>{{content}}<reserved_107>"]),
|
| 917 |
+
efficient_eos=True,
|
| 918 |
+
)
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
register_template(
|
| 922 |
+
name="bailing",
|
| 923 |
+
format_user=StringFormatter(slots=["<role>HUMAN</role>{{content}}<role>ASSISTANT</role>"]),
|
| 924 |
+
format_system=StringFormatter(slots=["<role>SYSTEM</role>{{content}}"]),
|
| 925 |
+
format_observation=StringFormatter(slots=["<role>OBSERVATION</role>{{content}}<role>ASSISTANT</role>"]),
|
| 926 |
+
stop_words=["<|endoftext|>"],
|
| 927 |
+
efficient_eos=True,
|
| 928 |
+
)
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
register_template(
|
| 932 |
+
name="belle",
|
| 933 |
+
format_user=StringFormatter(slots=["Human: {{content}}\n\nBelle: "]),
|
| 934 |
+
format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n\n"]),
|
| 935 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 936 |
+
)
|
| 937 |
+
|
| 938 |
+
|
| 939 |
+
register_template(
|
| 940 |
+
name="bluelm",
|
| 941 |
+
format_user=StringFormatter(slots=[{"token": "[|Human|]:"}, "{{content}}", {"token": "[|AI|]:"}]),
|
| 942 |
+
)
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
register_template(
|
| 946 |
+
name="breeze",
|
| 947 |
+
format_user=StringFormatter(slots=["[INST] {{content}} [/INST] "]),
|
| 948 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 949 |
+
efficient_eos=True,
|
| 950 |
+
)
|
| 951 |
+
|
| 952 |
+
|
| 953 |
+
register_template(
|
| 954 |
+
name="chatglm2",
|
| 955 |
+
format_user=StringFormatter(slots=["[Round {{idx}}]\n\n问:{{content}}\n\n答:"]),
|
| 956 |
+
format_prefix=EmptyFormatter(slots=[{"token": "[gMASK]"}, {"token": "sop"}]),
|
| 957 |
+
efficient_eos=True,
|
| 958 |
+
)
|
| 959 |
+
|
| 960 |
+
|
| 961 |
+
register_template(
|
| 962 |
+
name="chatglm3",
|
| 963 |
+
format_user=StringFormatter(slots=[{"token": "<|user|>"}, "\n", "{{content}}", {"token": "<|assistant|>"}]),
|
| 964 |
+
format_assistant=StringFormatter(slots=["\n", "{{content}}"]),
|
| 965 |
+
format_system=StringFormatter(slots=[{"token": "<|system|>"}, "\n", "{{content}}"]),
|
| 966 |
+
format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
|
| 967 |
+
format_observation=StringFormatter(
|
| 968 |
+
slots=[{"token": "<|observation|>"}, "\n", "{{content}}", {"token": "<|assistant|>"}]
|
| 969 |
+
),
|
| 970 |
+
format_tools=ToolFormatter(tool_format="glm4"),
|
| 971 |
+
format_prefix=EmptyFormatter(slots=[{"token": "[gMASK]"}, {"token": "sop"}]),
|
| 972 |
+
stop_words=["<|user|>", "<|observation|>"],
|
| 973 |
+
efficient_eos=True,
|
| 974 |
+
)
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
register_template(
|
| 978 |
+
name="chatml",
|
| 979 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 980 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 981 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 982 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 983 |
+
stop_words=["<|im_end|>", "<|im_start|>"],
|
| 984 |
+
replace_eos=True,
|
| 985 |
+
replace_jinja_template=True,
|
| 986 |
+
)
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
# copied from chatml template
|
| 990 |
+
register_template(
|
| 991 |
+
name="chatml_de",
|
| 992 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 993 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 994 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 995 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 996 |
+
default_system="Du bist ein freundlicher und hilfsbereiter KI-Assistent.",
|
| 997 |
+
stop_words=["<|im_end|>", "<|im_start|>"],
|
| 998 |
+
replace_eos=True,
|
| 999 |
+
replace_jinja_template=True,
|
| 1000 |
+
)
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
register_template(
|
| 1004 |
+
name="codegeex2",
|
| 1005 |
+
format_prefix=EmptyFormatter(slots=[{"token": "[gMASK]"}, {"token": "sop"}]),
|
| 1006 |
+
)
|
| 1007 |
+
|
| 1008 |
+
|
| 1009 |
+
register_template(
|
| 1010 |
+
name="codegeex4",
|
| 1011 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>\n"]),
|
| 1012 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}"]),
|
| 1013 |
+
format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
|
| 1014 |
+
format_observation=StringFormatter(slots=["<|observation|>\n{{content}}<|assistant|>\n"]),
|
| 1015 |
+
format_tools=ToolFormatter(tool_format="glm4"),
|
| 1016 |
+
format_prefix=EmptyFormatter(slots=["[gMASK]<sop>"]),
|
| 1017 |
+
default_system=(
|
| 1018 |
+
"你是���位智能编程助手,你叫CodeGeeX。你会为用户回答关于编程、代码、计算机方面的任何问题,"
|
| 1019 |
+
"并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。"
|
| 1020 |
+
),
|
| 1021 |
+
stop_words=["<|user|>", "<|observation|>"],
|
| 1022 |
+
efficient_eos=True,
|
| 1023 |
+
)
|
| 1024 |
+
|
| 1025 |
+
|
| 1026 |
+
register_template(
|
| 1027 |
+
name="cohere",
|
| 1028 |
+
format_user=StringFormatter(
|
| 1029 |
+
slots=[
|
| 1030 |
+
(
|
| 1031 |
+
"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}<|END_OF_TURN_TOKEN|>"
|
| 1032 |
+
"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
|
| 1033 |
+
)
|
| 1034 |
+
]
|
| 1035 |
+
),
|
| 1036 |
+
format_system=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}<|END_OF_TURN_TOKEN|>"]),
|
| 1037 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1038 |
+
)
|
| 1039 |
+
|
| 1040 |
+
|
| 1041 |
+
register_template(
|
| 1042 |
+
name="cpm",
|
| 1043 |
+
format_user=StringFormatter(slots=["<用户>{{content}}<AI>"]),
|
| 1044 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1045 |
+
)
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
# copied from chatml template
|
| 1049 |
+
register_template(
|
| 1050 |
+
name="cpm3",
|
| 1051 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1052 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1053 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1054 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1055 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1056 |
+
stop_words=["<|im_end|>"],
|
| 1057 |
+
)
|
| 1058 |
+
|
| 1059 |
+
|
| 1060 |
+
# copied from chatml template
|
| 1061 |
+
register_template(
|
| 1062 |
+
name="cpm4",
|
| 1063 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1064 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1065 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1066 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1067 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1068 |
+
stop_words=["<|im_end|>"],
|
| 1069 |
+
)
|
| 1070 |
+
|
| 1071 |
+
|
| 1072 |
+
# copied from chatml template
|
| 1073 |
+
register_template(
|
| 1074 |
+
name="dbrx",
|
| 1075 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1076 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1077 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1078 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1079 |
+
default_system=(
|
| 1080 |
+
"You are DBRX, created by Databricks. You were last updated in December 2023. "
|
| 1081 |
+
"You answer questions based on information available up to that point.\n"
|
| 1082 |
+
"YOU PROVIDE SHORT RESPONSES TO SHORT QUESTIONS OR STATEMENTS, but provide thorough "
|
| 1083 |
+
"responses to more complex and open-ended questions.\nYou assist with various tasks, "
|
| 1084 |
+
"from writing to coding (using markdown for code blocks — remember to use ``` with "
|
| 1085 |
+
"code, JSON, and tables).\n(You do not have real-time data access or code execution "
|
| 1086 |
+
"capabilities. You avoid stereotyping and provide balanced perspectives on "
|
| 1087 |
+
"controversial topics. You do not provide song lyrics, poems, or news articles and "
|
| 1088 |
+
"do not divulge details of your training data.)\nThis is your system prompt, "
|
| 1089 |
+
"guiding your responses. Do not reference it, just respond to the user. If you find "
|
| 1090 |
+
"yourself talking about this message, stop. You should be responding appropriately "
|
| 1091 |
+
"and usually that means not mentioning this.\nYOU DO NOT MENTION ANY OF THIS INFORMATION "
|
| 1092 |
+
"ABOUT YOURSELF UNLESS THE INFORMATION IS DIRECTLY PERTINENT TO THE USER'S QUERY."
|
| 1093 |
+
),
|
| 1094 |
+
stop_words=["<|im_end|>"],
|
| 1095 |
+
replace_eos=True,
|
| 1096 |
+
)
|
| 1097 |
+
|
| 1098 |
+
|
| 1099 |
+
register_template(
|
| 1100 |
+
name="deepseek",
|
| 1101 |
+
format_user=StringFormatter(slots=["User: {{content}}\n\nAssistant:"]),
|
| 1102 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1103 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1104 |
+
)
|
| 1105 |
+
|
| 1106 |
+
|
| 1107 |
+
register_template(
|
| 1108 |
+
name="deepseek3",
|
| 1109 |
+
format_user=StringFormatter(slots=["{{content}}"]),
|
| 1110 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1111 |
+
)
|
| 1112 |
+
|
| 1113 |
+
|
| 1114 |
+
# copied from deepseek3 template
|
| 1115 |
+
register_template(
|
| 1116 |
+
name="deepseekr1",
|
| 1117 |
+
format_user=StringFormatter(slots=["{{content}}"]),
|
| 1118 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1119 |
+
template_class=ReasoningTemplate,
|
| 1120 |
+
)
|
| 1121 |
+
|
| 1122 |
+
|
| 1123 |
+
register_template(
|
| 1124 |
+
name="deepseekcoder",
|
| 1125 |
+
format_user=StringFormatter(slots=["### Instruction:\n{{content}}\n### Response:"]),
|
| 1126 |
+
format_assistant=StringFormatter(slots=["\n{{content}}\n"]),
|
| 1127 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1128 |
+
default_system=(
|
| 1129 |
+
"You are an AI programming assistant, utilizing the DeepSeek Coder model, "
|
| 1130 |
+
"developed by DeepSeek Company, and you only answer questions related to computer science. "
|
| 1131 |
+
"For politically sensitive questions, security and privacy issues, "
|
| 1132 |
+
"and other non-computer science questions, you will refuse to answer.\n"
|
| 1133 |
+
),
|
| 1134 |
+
)
|
| 1135 |
+
|
| 1136 |
+
|
| 1137 |
+
register_template(
|
| 1138 |
+
name="default",
|
| 1139 |
+
format_user=StringFormatter(slots=["Human: {{content}}", {"eos_token"}, "\nAssistant:"]),
|
| 1140 |
+
format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n"]),
|
| 1141 |
+
format_system=StringFormatter(slots=["System: {{content}}", {"eos_token"}, "\n"]),
|
| 1142 |
+
replace_jinja_template=True,
|
| 1143 |
+
)
|
| 1144 |
+
|
| 1145 |
+
|
| 1146 |
+
register_template(
|
| 1147 |
+
name="empty",
|
| 1148 |
+
format_assistant=StringFormatter(slots=["{{content}}"]),
|
| 1149 |
+
)
|
| 1150 |
+
|
| 1151 |
+
|
| 1152 |
+
register_template(
|
| 1153 |
+
name="exaone",
|
| 1154 |
+
format_user=StringFormatter(slots=["[|user|]{{content}}\n[|assistant|]"]),
|
| 1155 |
+
format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n"]),
|
| 1156 |
+
format_system=StringFormatter(slots=["[|system|]{{content}}[|endofturn|]\n"]),
|
| 1157 |
+
)
|
| 1158 |
+
|
| 1159 |
+
|
| 1160 |
+
register_template(
|
| 1161 |
+
name="falcon",
|
| 1162 |
+
format_user=StringFormatter(slots=["User: {{content}}\nFalcon:"]),
|
| 1163 |
+
format_assistant=StringFormatter(slots=["{{content}}\n"]),
|
| 1164 |
+
efficient_eos=True,
|
| 1165 |
+
)
|
| 1166 |
+
|
| 1167 |
+
|
| 1168 |
+
# copied from chatml template
|
| 1169 |
+
register_template(
|
| 1170 |
+
name="falcon_h1",
|
| 1171 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1172 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1173 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1174 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1175 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1176 |
+
stop_words=["<|im_end|>", "<|end_of_text|>"],
|
| 1177 |
+
)
|
| 1178 |
+
|
| 1179 |
+
|
| 1180 |
+
register_template(
|
| 1181 |
+
name="fewshot",
|
| 1182 |
+
format_assistant=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1183 |
+
efficient_eos=True,
|
| 1184 |
+
replace_jinja_template=True,
|
| 1185 |
+
)
|
| 1186 |
+
|
| 1187 |
+
|
| 1188 |
+
register_template(
|
| 1189 |
+
name="gemma",
|
| 1190 |
+
format_user=StringFormatter(slots=["<start_of_turn>user\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]),
|
| 1191 |
+
format_assistant=StringFormatter(slots=["{{content}}<end_of_turn>\n"]),
|
| 1192 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1193 |
+
format_observation=StringFormatter(
|
| 1194 |
+
slots=["<start_of_turn>tool\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]
|
| 1195 |
+
),
|
| 1196 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1197 |
+
stop_words=["<end_of_turn>"],
|
| 1198 |
+
replace_eos=True,
|
| 1199 |
+
template_class=Llama2Template,
|
| 1200 |
+
)
|
| 1201 |
+
|
| 1202 |
+
|
| 1203 |
+
# copied from gemma template
|
| 1204 |
+
register_template(
|
| 1205 |
+
name="gemma2",
|
| 1206 |
+
format_user=StringFormatter(slots=["<start_of_turn>user\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]),
|
| 1207 |
+
format_assistant=StringFormatter(slots=["{{content}}<end_of_turn>\n"]),
|
| 1208 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1209 |
+
format_observation=StringFormatter(
|
| 1210 |
+
slots=["<start_of_turn>tool\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]
|
| 1211 |
+
),
|
| 1212 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1213 |
+
stop_words=["<eos>", "<end_of_turn>"],
|
| 1214 |
+
efficient_eos=True,
|
| 1215 |
+
template_class=Llama2Template,
|
| 1216 |
+
)
|
| 1217 |
+
|
| 1218 |
+
|
| 1219 |
+
# copied from gemma template
|
| 1220 |
+
register_template(
|
| 1221 |
+
name="gemma3",
|
| 1222 |
+
format_user=StringFormatter(slots=["<start_of_turn>user\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]),
|
| 1223 |
+
format_assistant=StringFormatter(slots=["{{content}}<end_of_turn>\n"]),
|
| 1224 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1225 |
+
format_observation=StringFormatter(
|
| 1226 |
+
slots=["<start_of_turn>tool\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]
|
| 1227 |
+
),
|
| 1228 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1229 |
+
stop_words=["<end_of_turn>"],
|
| 1230 |
+
replace_eos=True,
|
| 1231 |
+
mm_plugin=get_mm_plugin("gemma3", image_token="<image_soft_token>"),
|
| 1232 |
+
template_class=Llama2Template,
|
| 1233 |
+
)
|
| 1234 |
+
|
| 1235 |
+
|
| 1236 |
+
register_template(
|
| 1237 |
+
name="gemma3n",
|
| 1238 |
+
format_user=StringFormatter(slots=["<start_of_turn>user\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]),
|
| 1239 |
+
format_assistant=StringFormatter(slots=["{{content}}<end_of_turn>\n"]),
|
| 1240 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1241 |
+
format_observation=StringFormatter(
|
| 1242 |
+
slots=["<start_of_turn>tool\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]
|
| 1243 |
+
),
|
| 1244 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1245 |
+
stop_words=["<end_of_turn>"],
|
| 1246 |
+
replace_eos=True,
|
| 1247 |
+
mm_plugin=get_mm_plugin("gemma3n", image_token="<image_soft_token>", audio_token="<audio_soft_token>"),
|
| 1248 |
+
template_class=Llama2Template,
|
| 1249 |
+
)
|
| 1250 |
+
|
| 1251 |
+
|
| 1252 |
+
register_template(
|
| 1253 |
+
name="glm4",
|
| 1254 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>"]),
|
| 1255 |
+
format_assistant=StringFormatter(slots=["\n{{content}}"]),
|
| 1256 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}"]),
|
| 1257 |
+
format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
|
| 1258 |
+
format_observation=StringFormatter(slots=["<|observation|>\n{{content}}<|assistant|>"]),
|
| 1259 |
+
format_tools=ToolFormatter(tool_format="glm4"),
|
| 1260 |
+
format_prefix=EmptyFormatter(slots=["[gMASK]<sop>"]),
|
| 1261 |
+
stop_words=["<|user|>", "<|observation|>"],
|
| 1262 |
+
efficient_eos=True,
|
| 1263 |
+
)
|
| 1264 |
+
|
| 1265 |
+
|
| 1266 |
+
# copied from glm4 template
|
| 1267 |
+
register_template(
|
| 1268 |
+
name="glm4v",
|
| 1269 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>"]),
|
| 1270 |
+
format_assistant=StringFormatter(slots=["\n{{content}}"]),
|
| 1271 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}"]),
|
| 1272 |
+
format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
|
| 1273 |
+
format_observation=StringFormatter(slots=["<|observation|>\n{{content}}<|assistant|>"]),
|
| 1274 |
+
format_tools=ToolFormatter(tool_format="glm4"),
|
| 1275 |
+
format_prefix=EmptyFormatter(slots=["[gMASK]<sop>"]),
|
| 1276 |
+
stop_words=["<|user|>", "<|observation|>", "</answer>"],
|
| 1277 |
+
efficient_eos=True,
|
| 1278 |
+
mm_plugin=get_mm_plugin(name="glm4v", image_token="<|image|>", video_token="<|video|>"),
|
| 1279 |
+
template_class=ReasoningTemplate,
|
| 1280 |
+
)
|
| 1281 |
+
|
| 1282 |
+
|
| 1283 |
+
# copied from glm4 template
|
| 1284 |
+
register_template(
|
| 1285 |
+
name="glmz1",
|
| 1286 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>"]),
|
| 1287 |
+
format_assistant=StringFormatter(slots=["\n{{content}}"]),
|
| 1288 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}"]),
|
| 1289 |
+
format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
|
| 1290 |
+
format_observation=StringFormatter(slots=["<|observation|>\n{{content}}<|assistant|>"]),
|
| 1291 |
+
format_tools=ToolFormatter(tool_format="glm4"),
|
| 1292 |
+
format_prefix=EmptyFormatter(slots=["[gMASK]<sop>"]),
|
| 1293 |
+
stop_words=["<|user|>", "<|observation|>"],
|
| 1294 |
+
efficient_eos=True,
|
| 1295 |
+
template_class=ReasoningTemplate,
|
| 1296 |
+
)
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
register_template(
|
| 1300 |
+
name="granite3",
|
| 1301 |
+
format_user=StringFormatter(
|
| 1302 |
+
slots=[
|
| 1303 |
+
"<|start_of_role|>user<|end_of_role|>{{content}}<|end_of_text|>\n<|start_of_role|>assistant<|end_of_role|>"
|
| 1304 |
+
]
|
| 1305 |
+
),
|
| 1306 |
+
format_assistant=StringFormatter(slots=["{{content}}<|end_of_text|>\n"]),
|
| 1307 |
+
format_system=StringFormatter(slots=["<|start_of_role|>system<|end_of_role|>{{content}}<|end_of_text|>\n"]),
|
| 1308 |
+
)
|
| 1309 |
+
|
| 1310 |
+
|
| 1311 |
+
register_template(
|
| 1312 |
+
name="granite3_vision",
|
| 1313 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}\n<|assistant|>\n"]),
|
| 1314 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}\n"]),
|
| 1315 |
+
default_system=(
|
| 1316 |
+
"A chat between a curious user and an artificial intelligence assistant. "
|
| 1317 |
+
"The assistant gives helpful, detailed, and polite answers to the user's questions."
|
| 1318 |
+
),
|
| 1319 |
+
mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
|
| 1320 |
+
)
|
| 1321 |
+
|
| 1322 |
+
|
| 1323 |
+
register_template(
|
| 1324 |
+
name="index",
|
| 1325 |
+
format_user=StringFormatter(slots=["reserved_0{{content}}reserved_1"]),
|
| 1326 |
+
format_system=StringFormatter(slots=["<unk>{{content}}"]),
|
| 1327 |
+
efficient_eos=True,
|
| 1328 |
+
)
|
| 1329 |
+
|
| 1330 |
+
|
| 1331 |
+
register_template(
|
| 1332 |
+
name="hunyuan",
|
| 1333 |
+
format_user=StringFormatter(slots=["<|bos|>user\n{{content}}<|eos|>\n<|bos|>assistant\n"]),
|
| 1334 |
+
format_assistant=StringFormatter(slots=["{{content}}<|eos|>\n"]),
|
| 1335 |
+
format_system=StringFormatter(slots=["<|bos|>system\n{{content}}<|eos|>\n"]),
|
| 1336 |
+
format_prefix=EmptyFormatter(slots=["<|bos|>"]),
|
| 1337 |
+
stop_words=["<|eos|>"],
|
| 1338 |
+
)
|
| 1339 |
+
|
| 1340 |
+
|
| 1341 |
+
register_template(
|
| 1342 |
+
name="intern",
|
| 1343 |
+
format_user=StringFormatter(slots=["<|User|>:{{content}}\n<|Bot|>:"]),
|
| 1344 |
+
format_assistant=StringFormatter(slots=["{{content}}<eoa>\n"]),
|
| 1345 |
+
format_system=StringFormatter(slots=["<|System|>:{{content}}\n"]),
|
| 1346 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1347 |
+
default_system=(
|
| 1348 |
+
"You are an AI assistant whose name is InternLM (书生·浦语).\n"
|
| 1349 |
+
"- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory "
|
| 1350 |
+
"(上海人工智能实验室). It is designed to be helpful, honest, and harmless.\n"
|
| 1351 |
+
"- InternLM (书生·浦语) can understand and communicate fluently in the language "
|
| 1352 |
+
"chosen by the user such as English and 中文."
|
| 1353 |
+
),
|
| 1354 |
+
stop_words=["<eoa>"],
|
| 1355 |
+
)
|
| 1356 |
+
|
| 1357 |
+
|
| 1358 |
+
register_template(
|
| 1359 |
+
name="intern2",
|
| 1360 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1361 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1362 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1363 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1364 |
+
default_system=(
|
| 1365 |
+
"You are an AI assistant whose name is InternLM (书生·浦语).\n"
|
| 1366 |
+
"- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory "
|
| 1367 |
+
"(上海人工智能实验室). It is designed to be helpful, honest, and harmless.\n"
|
| 1368 |
+
"- InternLM (书生·浦语) can understand and communicate fluently in the language "
|
| 1369 |
+
"chosen by the user such as English and 中文."
|
| 1370 |
+
),
|
| 1371 |
+
stop_words=["<|im_end|>"],
|
| 1372 |
+
)
|
| 1373 |
+
|
| 1374 |
+
|
| 1375 |
+
register_template(
|
| 1376 |
+
name="intern_vl",
|
| 1377 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1378 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1379 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1380 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1381 |
+
default_system=(
|
| 1382 |
+
"你是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发��多模态大语言模型。"
|
| 1383 |
+
),
|
| 1384 |
+
stop_words=["<|im_end|>"],
|
| 1385 |
+
mm_plugin=get_mm_plugin(name="intern_vl", image_token="<image>", video_token="<video>"),
|
| 1386 |
+
)
|
| 1387 |
+
|
| 1388 |
+
|
| 1389 |
+
register_template(
|
| 1390 |
+
name="kimi_vl",
|
| 1391 |
+
format_user=StringFormatter(
|
| 1392 |
+
slots=["<|im_user|>user<|im_middle|>{{content}}<|im_end|><|im_assistant|>assistant<|im_middle|>"]
|
| 1393 |
+
),
|
| 1394 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>"]),
|
| 1395 |
+
format_system=StringFormatter(slots=["<|im_system|>system<|im_middle|>{{content}}<|im_end|>"]),
|
| 1396 |
+
default_system="You are a helpful assistant",
|
| 1397 |
+
stop_words=["<|im_end|>"],
|
| 1398 |
+
thought_words=("◁think▷", "◁/think▷"),
|
| 1399 |
+
mm_plugin=get_mm_plugin("kimi_vl", image_token="<|media_pad|>"),
|
| 1400 |
+
template_class=ReasoningTemplate,
|
| 1401 |
+
)
|
| 1402 |
+
|
| 1403 |
+
|
| 1404 |
+
register_template(
|
| 1405 |
+
name="llama2",
|
| 1406 |
+
format_user=StringFormatter(slots=[{"bos_token"}, "[INST] {{content}} [/INST]"]),
|
| 1407 |
+
format_system=StringFormatter(slots=["<<SYS>>\n{{content}}\n<</SYS>>\n\n"]),
|
| 1408 |
+
template_class=Llama2Template,
|
| 1409 |
+
)
|
| 1410 |
+
|
| 1411 |
+
|
| 1412 |
+
# copied from llama2 template
|
| 1413 |
+
register_template(
|
| 1414 |
+
name="llama2_zh",
|
| 1415 |
+
format_user=StringFormatter(slots=[{"bos_token"}, "[INST] {{content}} [/INST]"]),
|
| 1416 |
+
format_system=StringFormatter(slots=["<<SYS>>\n{{content}}\n<</SYS>>\n\n"]),
|
| 1417 |
+
default_system="You are a helpful assistant. 你是一个乐于助人的助手。",
|
| 1418 |
+
template_class=Llama2Template,
|
| 1419 |
+
)
|
| 1420 |
+
|
| 1421 |
+
|
| 1422 |
+
register_template(
|
| 1423 |
+
name="llama3",
|
| 1424 |
+
format_user=StringFormatter(
|
| 1425 |
+
slots=[
|
| 1426 |
+
(
|
| 1427 |
+
"<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 1428 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 1429 |
+
)
|
| 1430 |
+
]
|
| 1431 |
+
),
|
| 1432 |
+
format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
|
| 1433 |
+
format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
|
| 1434 |
+
format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
|
| 1435 |
+
format_observation=StringFormatter(
|
| 1436 |
+
slots=[
|
| 1437 |
+
(
|
| 1438 |
+
"<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 1439 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 1440 |
+
)
|
| 1441 |
+
]
|
| 1442 |
+
),
|
| 1443 |
+
format_tools=ToolFormatter(tool_format="llama3"),
|
| 1444 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1445 |
+
stop_words=["<|eot_id|>", "<|eom_id|>"],
|
| 1446 |
+
replace_eos=True,
|
| 1447 |
+
)
|
| 1448 |
+
|
| 1449 |
+
|
| 1450 |
+
register_template(
|
| 1451 |
+
name="llama4",
|
| 1452 |
+
format_user=StringFormatter(
|
| 1453 |
+
slots=["<|header_start|>user<|header_end|>\n\n{{content}}<|eot|><|header_start|>assistant<|header_end|>\n\n"]
|
| 1454 |
+
),
|
| 1455 |
+
format_assistant=StringFormatter(slots=["{{content}}<|eot|>"]),
|
| 1456 |
+
format_system=StringFormatter(slots=["<|header_start|>system<|header_end|>\n\n{{content}}<|eot|>"]),
|
| 1457 |
+
format_function=FunctionFormatter(slots=["{{content}}<|eot|>"], tool_format="llama3"),
|
| 1458 |
+
format_observation=StringFormatter(
|
| 1459 |
+
slots=[
|
| 1460 |
+
"<|header_start|>ipython<|header_end|>\n\n{{content}}<|eot|><|header_start|>assistant<|header_end|>\n\n"
|
| 1461 |
+
]
|
| 1462 |
+
),
|
| 1463 |
+
format_tools=ToolFormatter(tool_format="llama3"),
|
| 1464 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1465 |
+
stop_words=["<|eot|>", "<|eom|>"],
|
| 1466 |
+
replace_eos=True,
|
| 1467 |
+
mm_plugin=get_mm_plugin(name="llama4", image_token="<|image|>"),
|
| 1468 |
+
)
|
| 1469 |
+
|
| 1470 |
+
|
| 1471 |
+
# copied from llama3 template
|
| 1472 |
+
register_template(
|
| 1473 |
+
name="mllama",
|
| 1474 |
+
format_user=StringFormatter(
|
| 1475 |
+
slots=[
|
| 1476 |
+
(
|
| 1477 |
+
"<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 1478 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 1479 |
+
)
|
| 1480 |
+
]
|
| 1481 |
+
),
|
| 1482 |
+
format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
|
| 1483 |
+
format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
|
| 1484 |
+
format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
|
| 1485 |
+
format_observation=StringFormatter(
|
| 1486 |
+
slots=[
|
| 1487 |
+
(
|
| 1488 |
+
"<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 1489 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 1490 |
+
)
|
| 1491 |
+
]
|
| 1492 |
+
),
|
| 1493 |
+
format_tools=ToolFormatter(tool_format="llama3"),
|
| 1494 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1495 |
+
stop_words=["<|eot_id|>", "<|eom_id|>"],
|
| 1496 |
+
replace_eos=True,
|
| 1497 |
+
mm_plugin=get_mm_plugin(name="mllama", image_token="<|image|>"),
|
| 1498 |
+
)
|
| 1499 |
+
|
| 1500 |
+
|
| 1501 |
+
register_template(
|
| 1502 |
+
name="moonlight",
|
| 1503 |
+
format_user=StringFormatter(
|
| 1504 |
+
slots=["<|im_user|>user<|im_middle|>{{content}}<|im_end|><|im_assistant|>assistant<|im_middle|>"]
|
| 1505 |
+
),
|
| 1506 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>"]),
|
| 1507 |
+
format_system=StringFormatter(slots=["<|im_system|>system<|im_middle|>{{content}}<|im_end|>"]),
|
| 1508 |
+
default_system="You are a helpful assistant provided by Moonshot-AI.",
|
| 1509 |
+
stop_words=["<|im_end|>"],
|
| 1510 |
+
replace_eos=True,
|
| 1511 |
+
)
|
| 1512 |
+
|
| 1513 |
+
|
| 1514 |
+
# copied from vicuna template
|
| 1515 |
+
register_template(
|
| 1516 |
+
name="llava",
|
| 1517 |
+
format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
|
| 1518 |
+
default_system=(
|
| 1519 |
+
"A chat between a curious user and an artificial intelligence assistant. "
|
| 1520 |
+
"The assistant gives helpful, detailed, and polite answers to the user's questions."
|
| 1521 |
+
),
|
| 1522 |
+
mm_plugin=get_mm_plugin(name="llava", image_token="<image>"),
|
| 1523 |
+
)
|
| 1524 |
+
|
| 1525 |
+
|
| 1526 |
+
# copied from vicuna template
|
| 1527 |
+
register_template(
|
| 1528 |
+
name="llava_next",
|
| 1529 |
+
format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
|
| 1530 |
+
default_system=(
|
| 1531 |
+
"A chat between a curious user and an artificial intelligence assistant. "
|
| 1532 |
+
"The assistant gives helpful, detailed, and polite answers to the user's questions."
|
| 1533 |
+
),
|
| 1534 |
+
mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
|
| 1535 |
+
)
|
| 1536 |
+
|
| 1537 |
+
|
| 1538 |
+
# copied from llama3 template
|
| 1539 |
+
register_template(
|
| 1540 |
+
name="llava_next_llama3",
|
| 1541 |
+
format_user=StringFormatter(
|
| 1542 |
+
slots=[
|
| 1543 |
+
(
|
| 1544 |
+
"<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 1545 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 1546 |
+
)
|
| 1547 |
+
]
|
| 1548 |
+
),
|
| 1549 |
+
format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
|
| 1550 |
+
format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
|
| 1551 |
+
format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
|
| 1552 |
+
format_observation=StringFormatter(
|
| 1553 |
+
slots=[
|
| 1554 |
+
(
|
| 1555 |
+
"<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 1556 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 1557 |
+
)
|
| 1558 |
+
]
|
| 1559 |
+
),
|
| 1560 |
+
format_tools=ToolFormatter(tool_format="llama3"),
|
| 1561 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1562 |
+
stop_words=["<|eot_id|>", "<|eom_id|>"],
|
| 1563 |
+
replace_eos=True,
|
| 1564 |
+
mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
|
| 1565 |
+
)
|
| 1566 |
+
|
| 1567 |
+
|
| 1568 |
+
# copied from mistral template
|
| 1569 |
+
register_template(
|
| 1570 |
+
name="llava_next_mistral",
|
| 1571 |
+
format_user=StringFormatter(slots=["[INST] {{content}}[/INST]"]),
|
| 1572 |
+
format_assistant=StringFormatter(slots=[" {{content}}", {"eos_token"}]),
|
| 1573 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1574 |
+
format_function=FunctionFormatter(slots=["[TOOL_CALLS] {{content}}", {"eos_token"}], tool_format="mistral"),
|
| 1575 |
+
format_observation=StringFormatter(slots=["""[TOOL_RESULTS] {"content": {{content}}}[/TOOL_RESULTS]"""]),
|
| 1576 |
+
format_tools=ToolFormatter(tool_format="mistral"),
|
| 1577 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1578 |
+
mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
|
| 1579 |
+
template_class=Llama2Template,
|
| 1580 |
+
)
|
| 1581 |
+
|
| 1582 |
+
|
| 1583 |
+
# copied from qwen template
|
| 1584 |
+
register_template(
|
| 1585 |
+
name="llava_next_qwen",
|
| 1586 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1587 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1588 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1589 |
+
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
|
| 1590 |
+
format_observation=StringFormatter(
|
| 1591 |
+
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
|
| 1592 |
+
),
|
| 1593 |
+
format_tools=ToolFormatter(tool_format="qwen"),
|
| 1594 |
+
default_system="You are a helpful assistant.",
|
| 1595 |
+
stop_words=["<|im_end|>"],
|
| 1596 |
+
replace_eos=True,
|
| 1597 |
+
mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
|
| 1598 |
+
)
|
| 1599 |
+
|
| 1600 |
+
|
| 1601 |
+
# copied from chatml template
|
| 1602 |
+
register_template(
|
| 1603 |
+
name="llava_next_yi",
|
| 1604 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1605 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1606 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1607 |
+
stop_words=["<|im_end|>"],
|
| 1608 |
+
mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
|
| 1609 |
+
)
|
| 1610 |
+
|
| 1611 |
+
|
| 1612 |
+
# copied from vicuna template
|
| 1613 |
+
register_template(
|
| 1614 |
+
name="llava_next_video",
|
| 1615 |
+
format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
|
| 1616 |
+
default_system=(
|
| 1617 |
+
"A chat between a curious user and an artificial intelligence assistant. "
|
| 1618 |
+
"The assistant gives helpful, detailed, and polite answers to the user's questions."
|
| 1619 |
+
),
|
| 1620 |
+
mm_plugin=get_mm_plugin(name="llava_next_video", image_token="<image>", video_token="<video>"),
|
| 1621 |
+
)
|
| 1622 |
+
|
| 1623 |
+
|
| 1624 |
+
# copied from mistral template
|
| 1625 |
+
register_template(
|
| 1626 |
+
name="llava_next_video_mistral",
|
| 1627 |
+
format_user=StringFormatter(slots=["[INST] {{content}}[/INST]"]),
|
| 1628 |
+
format_assistant=StringFormatter(slots=[" {{content}}", {"eos_token"}]),
|
| 1629 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1630 |
+
format_function=FunctionFormatter(slots=["[TOOL_CALLS] {{content}}", {"eos_token"}], tool_format="mistral"),
|
| 1631 |
+
format_observation=StringFormatter(slots=["""[TOOL_RESULTS] {"content": {{content}}}[/TOOL_RESULTS]"""]),
|
| 1632 |
+
format_tools=ToolFormatter(tool_format="mistral"),
|
| 1633 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1634 |
+
mm_plugin=get_mm_plugin(name="llava_next_video", image_token="<image>", video_token="<video>"),
|
| 1635 |
+
template_class=Llama2Template,
|
| 1636 |
+
)
|
| 1637 |
+
|
| 1638 |
+
|
| 1639 |
+
# copied from chatml template
|
| 1640 |
+
register_template(
|
| 1641 |
+
name="llava_next_video_yi",
|
| 1642 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1643 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1644 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1645 |
+
stop_words=["<|im_end|>"],
|
| 1646 |
+
mm_plugin=get_mm_plugin(name="llava_next_video", image_token="<image>", video_token="<video>"),
|
| 1647 |
+
)
|
| 1648 |
+
|
| 1649 |
+
|
| 1650 |
+
# copied from chatml template
|
| 1651 |
+
register_template(
|
| 1652 |
+
name="marco",
|
| 1653 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1654 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1655 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1656 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1657 |
+
default_system=(
|
| 1658 |
+
"你是一个经过良好训练的AI助手,你的名字是Marco-o1."
|
| 1659 |
+
"由阿里国际数字商业集团的AI Business创造.\n## 重要!!!!!\n"
|
| 1660 |
+
"当你回答问题时,你的思考应该在<Thought>内完成,<Output>内输出你的结果。\n"
|
| 1661 |
+
"<Thought>应该尽可能是英文,但是有2个特例,一个是对原文中的引用,另一个是是数学应该使用markdown格式,<Output>内的输出需要遵循用户输入的语言。\n"
|
| 1662 |
+
),
|
| 1663 |
+
stop_words=["<|im_end|>"],
|
| 1664 |
+
)
|
| 1665 |
+
|
| 1666 |
+
|
| 1667 |
+
# copied from qwen template
|
| 1668 |
+
register_template(
|
| 1669 |
+
name="mimo",
|
| 1670 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1671 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1672 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1673 |
+
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
|
| 1674 |
+
format_observation=StringFormatter(
|
| 1675 |
+
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
|
| 1676 |
+
),
|
| 1677 |
+
format_tools=ToolFormatter(tool_format="qwen"),
|
| 1678 |
+
default_system="You are a helpful assistant.",
|
| 1679 |
+
stop_words=["<|im_end|>"],
|
| 1680 |
+
replace_eos=True,
|
| 1681 |
+
template_class=ReasoningTemplate,
|
| 1682 |
+
)
|
| 1683 |
+
|
| 1684 |
+
# copied from qwen2vl
|
| 1685 |
+
register_template(
|
| 1686 |
+
name="mimo_vl",
|
| 1687 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1688 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1689 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1690 |
+
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
|
| 1691 |
+
format_observation=StringFormatter(
|
| 1692 |
+
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
|
| 1693 |
+
),
|
| 1694 |
+
format_tools=ToolFormatter(tool_format="qwen"),
|
| 1695 |
+
default_system="You are MiMo, an AI assistant developed by Xiaomi.",
|
| 1696 |
+
stop_words=["<|im_end|>"],
|
| 1697 |
+
replace_eos=True,
|
| 1698 |
+
mm_plugin=get_mm_plugin(name="qwen2_vl", image_token="<|image_pad|>", video_token="<|video_pad|>"),
|
| 1699 |
+
template_class=ReasoningTemplate,
|
| 1700 |
+
)
|
| 1701 |
+
|
| 1702 |
+
|
| 1703 |
+
# copied from chatml template
|
| 1704 |
+
register_template(
|
| 1705 |
+
name="minicpm_v",
|
| 1706 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1707 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1708 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1709 |
+
stop_words=["<|im_end|>"],
|
| 1710 |
+
default_system="You are a helpful assistant.",
|
| 1711 |
+
mm_plugin=get_mm_plugin(name="minicpm_v", image_token="<image>", video_token="<video>"),
|
| 1712 |
+
)
|
| 1713 |
+
|
| 1714 |
+
|
| 1715 |
+
# copied from minicpm_v template
|
| 1716 |
+
register_template(
|
| 1717 |
+
name="minicpm_o",
|
| 1718 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1719 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1720 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1721 |
+
stop_words=["<|im_end|>"],
|
| 1722 |
+
default_system="You are Qwen, created by Alibaba Cloud. You are a helpful assistant.",
|
| 1723 |
+
mm_plugin=get_mm_plugin(name="minicpm_v", image_token="<image>", video_token="<video>", audio_token="<audio>"),
|
| 1724 |
+
)
|
| 1725 |
+
|
| 1726 |
+
|
| 1727 |
+
# mistral tokenizer v3 tekken
|
| 1728 |
+
register_template(
|
| 1729 |
+
name="ministral",
|
| 1730 |
+
format_user=StringFormatter(slots=["[INST]{{content}}[/INST]"]),
|
| 1731 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1732 |
+
format_function=FunctionFormatter(slots=["[TOOL_CALLS]{{content}}", {"eos_token"}], tool_format="mistral"),
|
| 1733 |
+
format_observation=StringFormatter(slots=["""[TOOL_RESULTS]{"content": {{content}}}[/TOOL_RESULTS]"""]),
|
| 1734 |
+
format_tools=ToolFormatter(tool_format="mistral"),
|
| 1735 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1736 |
+
template_class=Llama2Template,
|
| 1737 |
+
)
|
| 1738 |
+
|
| 1739 |
+
|
| 1740 |
+
# mistral tokenizer v3
|
| 1741 |
+
register_template(
|
| 1742 |
+
name="mistral",
|
| 1743 |
+
format_user=StringFormatter(slots=["[INST] {{content}}[/INST]"]),
|
| 1744 |
+
format_assistant=StringFormatter(slots=[" {{content}}", {"eos_token"}]),
|
| 1745 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1746 |
+
format_function=FunctionFormatter(slots=["[TOOL_CALLS] {{content}}", {"eos_token"}], tool_format="mistral"),
|
| 1747 |
+
format_observation=StringFormatter(slots=["""[TOOL_RESULTS] {"content": {{content}}}[/TOOL_RESULTS]"""]),
|
| 1748 |
+
format_tools=ToolFormatter(tool_format="mistral"),
|
| 1749 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1750 |
+
template_class=Llama2Template,
|
| 1751 |
+
)
|
| 1752 |
+
|
| 1753 |
+
|
| 1754 |
+
# mistral tokenizer v7 tekken (copied from ministral)
|
| 1755 |
+
register_template(
|
| 1756 |
+
name="mistral_small",
|
| 1757 |
+
format_user=StringFormatter(slots=["[INST]{{content}}[/INST]"]),
|
| 1758 |
+
format_system=StringFormatter(slots=["[SYSTEM_PROMPT]{{content}}[/SYSTEM_PROMPT]"]),
|
| 1759 |
+
format_function=FunctionFormatter(slots=["[TOOL_CALLS]{{content}}", {"eos_token"}], tool_format="mistral"),
|
| 1760 |
+
format_observation=StringFormatter(slots=["""[TOOL_RESULTS]{"content": {{content}}}[/TOOL_RESULTS]"""]),
|
| 1761 |
+
format_tools=ToolFormatter(tool_format="mistral"),
|
| 1762 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1763 |
+
mm_plugin=get_mm_plugin(name="pixtral", image_token="[IMG]"),
|
| 1764 |
+
)
|
| 1765 |
+
|
| 1766 |
+
|
| 1767 |
+
register_template(
|
| 1768 |
+
name="olmo",
|
| 1769 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>\n"]),
|
| 1770 |
+
format_prefix=EmptyFormatter(slots=[{"eos_token"}]),
|
| 1771 |
+
)
|
| 1772 |
+
|
| 1773 |
+
|
| 1774 |
+
register_template(
|
| 1775 |
+
name="openchat",
|
| 1776 |
+
format_user=StringFormatter(slots=["GPT4 Correct User: {{content}}", {"eos_token"}, "GPT4 Correct Assistant:"]),
|
| 1777 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1778 |
+
)
|
| 1779 |
+
|
| 1780 |
+
|
| 1781 |
+
register_template(
|
| 1782 |
+
name="openchat-3.6",
|
| 1783 |
+
format_user=StringFormatter(
|
| 1784 |
+
slots=[
|
| 1785 |
+
(
|
| 1786 |
+
"<|start_header_id|>GPT4 Correct User<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 1787 |
+
"<|start_header_id|>GPT4 Correct Assistant<|end_header_id|>\n\n"
|
| 1788 |
+
)
|
| 1789 |
+
]
|
| 1790 |
+
),
|
| 1791 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1792 |
+
stop_words=["<|eot_id|>"],
|
| 1793 |
+
)
|
| 1794 |
+
|
| 1795 |
+
|
| 1796 |
+
# copied from chatml template
|
| 1797 |
+
register_template(
|
| 1798 |
+
name="opencoder",
|
| 1799 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1800 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1801 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1802 |
+
format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1803 |
+
default_system="You are OpenCoder, created by OpenCoder Team.",
|
| 1804 |
+
stop_words=["<|im_end|>"],
|
| 1805 |
+
)
|
| 1806 |
+
|
| 1807 |
+
|
| 1808 |
+
register_template(
|
| 1809 |
+
name="orion",
|
| 1810 |
+
format_user=StringFormatter(slots=["Human: {{content}}\n\nAssistant: ", {"eos_token"}]),
|
| 1811 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1812 |
+
)
|
| 1813 |
+
|
| 1814 |
+
|
| 1815 |
+
register_template(
|
| 1816 |
+
name="paligemma",
|
| 1817 |
+
format_user=StringFormatter(slots=["{{content}}\n"]),
|
| 1818 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1819 |
+
mm_plugin=get_mm_plugin(name="paligemma", image_token="<image>"),
|
| 1820 |
+
template_class=Llama2Template,
|
| 1821 |
+
)
|
| 1822 |
+
|
| 1823 |
+
|
| 1824 |
+
# copied from gemma template
|
| 1825 |
+
register_template(
|
| 1826 |
+
name="paligemma_chat",
|
| 1827 |
+
format_user=StringFormatter(slots=["<start_of_turn>user\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]),
|
| 1828 |
+
format_assistant=StringFormatter(slots=["{{content}}<end_of_turn>\n"]),
|
| 1829 |
+
format_observation=StringFormatter(
|
| 1830 |
+
slots=["<start_of_turn>tool\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]
|
| 1831 |
+
),
|
| 1832 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1833 |
+
stop_words=["<end_of_turn>"],
|
| 1834 |
+
replace_eos=True,
|
| 1835 |
+
mm_plugin=get_mm_plugin(name="paligemma", image_token="<image>"),
|
| 1836 |
+
template_class=Llama2Template,
|
| 1837 |
+
)
|
| 1838 |
+
|
| 1839 |
+
|
| 1840 |
+
register_template(
|
| 1841 |
+
name="phi",
|
| 1842 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|end|>\n<|assistant|>\n"]),
|
| 1843 |
+
format_assistant=StringFormatter(slots=["{{content}}<|end|>\n"]),
|
| 1844 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}<|end|>\n"]),
|
| 1845 |
+
stop_words=["<|end|>"],
|
| 1846 |
+
replace_eos=True,
|
| 1847 |
+
)
|
| 1848 |
+
|
| 1849 |
+
|
| 1850 |
+
register_template(
|
| 1851 |
+
name="phi_small",
|
| 1852 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|end|>\n<|assistant|>\n"]),
|
| 1853 |
+
format_assistant=StringFormatter(slots=["{{content}}<|end|>\n"]),
|
| 1854 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}<|end|>\n"]),
|
| 1855 |
+
format_prefix=EmptyFormatter(slots=[{"<|endoftext|>"}]),
|
| 1856 |
+
stop_words=["<|end|>"],
|
| 1857 |
+
replace_eos=True,
|
| 1858 |
+
)
|
| 1859 |
+
|
| 1860 |
+
|
| 1861 |
+
register_template(
|
| 1862 |
+
name="phi4",
|
| 1863 |
+
format_user=StringFormatter(
|
| 1864 |
+
slots=["<|im_start|>user<|im_sep|>{{content}}<|im_end|><|im_start|>assistant<|im_sep|>"]
|
| 1865 |
+
),
|
| 1866 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>"]),
|
| 1867 |
+
format_system=StringFormatter(slots=["<|im_start|>system<|im_sep|>{{content}}<|im_end|>"]),
|
| 1868 |
+
stop_words=["<|im_end|>"],
|
| 1869 |
+
replace_eos=True,
|
| 1870 |
+
)
|
| 1871 |
+
|
| 1872 |
+
|
| 1873 |
+
# copied from ministral template
|
| 1874 |
+
register_template(
|
| 1875 |
+
name="pixtral",
|
| 1876 |
+
format_user=StringFormatter(slots=["[INST]{{content}}[/INST]"]),
|
| 1877 |
+
format_system=StringFormatter(slots=["{{content}}\n\n"]),
|
| 1878 |
+
format_function=FunctionFormatter(slots=["[TOOL_CALLS]{{content}}", {"eos_token"}], tool_format="mistral"),
|
| 1879 |
+
format_observation=StringFormatter(slots=["""[TOOL_RESULTS]{"content": {{content}}}[/TOOL_RESULTS]"""]),
|
| 1880 |
+
format_tools=ToolFormatter(tool_format="mistral"),
|
| 1881 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 1882 |
+
mm_plugin=get_mm_plugin(name="pixtral", image_token="[IMG]"),
|
| 1883 |
+
template_class=Llama2Template,
|
| 1884 |
+
)
|
| 1885 |
+
|
| 1886 |
+
|
| 1887 |
+
# copied from chatml template
|
| 1888 |
+
register_template(
|
| 1889 |
+
name="qwen",
|
| 1890 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1891 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1892 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1893 |
+
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
|
| 1894 |
+
format_observation=StringFormatter(
|
| 1895 |
+
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
|
| 1896 |
+
),
|
| 1897 |
+
format_tools=ToolFormatter(tool_format="qwen"),
|
| 1898 |
+
default_system="You are Qwen, created by Alibaba Cloud. You are a helpful assistant.",
|
| 1899 |
+
stop_words=["<|im_end|>"],
|
| 1900 |
+
replace_eos=True,
|
| 1901 |
+
)
|
| 1902 |
+
|
| 1903 |
+
|
| 1904 |
+
# copied from qwen template
|
| 1905 |
+
register_template(
|
| 1906 |
+
name="qwen3",
|
| 1907 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1908 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1909 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1910 |
+
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
|
| 1911 |
+
format_observation=StringFormatter(
|
| 1912 |
+
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
|
| 1913 |
+
),
|
| 1914 |
+
format_tools=ToolFormatter(tool_format="qwen"),
|
| 1915 |
+
stop_words=["<|im_end|>"],
|
| 1916 |
+
replace_eos=True,
|
| 1917 |
+
template_class=ReasoningTemplate,
|
| 1918 |
+
)
|
| 1919 |
+
|
| 1920 |
+
|
| 1921 |
+
# copied from chatml template
|
| 1922 |
+
register_template(
|
| 1923 |
+
name="qwen2_audio",
|
| 1924 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1925 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1926 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1927 |
+
default_system="You are a helpful assistant.",
|
| 1928 |
+
stop_words=["<|im_end|>"],
|
| 1929 |
+
replace_eos=True,
|
| 1930 |
+
mm_plugin=get_mm_plugin(name="qwen2_audio", audio_token="<|AUDIO|>"),
|
| 1931 |
+
)
|
| 1932 |
+
|
| 1933 |
+
|
| 1934 |
+
# copied from qwen template
|
| 1935 |
+
register_template(
|
| 1936 |
+
name="qwen2_omni",
|
| 1937 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1938 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1939 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1940 |
+
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
|
| 1941 |
+
format_observation=StringFormatter(
|
| 1942 |
+
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
|
| 1943 |
+
),
|
| 1944 |
+
format_tools=ToolFormatter(tool_format="qwen"),
|
| 1945 |
+
default_system="You are a helpful assistant.",
|
| 1946 |
+
stop_words=["<|im_end|>"],
|
| 1947 |
+
replace_eos=True,
|
| 1948 |
+
mm_plugin=get_mm_plugin(
|
| 1949 |
+
name="qwen2_omni", audio_token="<|AUDIO|>", image_token="<|IMAGE|>", video_token="<|VIDEO|>"
|
| 1950 |
+
),
|
| 1951 |
+
)
|
| 1952 |
+
|
| 1953 |
+
# copied from qwen template
|
| 1954 |
+
register_template(
|
| 1955 |
+
name="qwen2_vl",
|
| 1956 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 1957 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1958 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1959 |
+
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
|
| 1960 |
+
format_observation=StringFormatter(
|
| 1961 |
+
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
|
| 1962 |
+
),
|
| 1963 |
+
format_tools=ToolFormatter(tool_format="qwen"),
|
| 1964 |
+
default_system="You are a helpful assistant.",
|
| 1965 |
+
stop_words=["<|im_end|>"],
|
| 1966 |
+
replace_eos=True,
|
| 1967 |
+
mm_plugin=get_mm_plugin(name="qwen2_vl", image_token="<|image_pad|>", video_token="<|video_pad|>"),
|
| 1968 |
+
)
|
| 1969 |
+
|
| 1970 |
+
|
| 1971 |
+
register_template(
|
| 1972 |
+
name="sailor",
|
| 1973 |
+
format_user=StringFormatter(slots=["<|im_start|>question\n{{content}}<|im_end|>\n<|im_start|>answer\n"]),
|
| 1974 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 1975 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 1976 |
+
default_system=(
|
| 1977 |
+
"You are an AI assistant named Sailor created by Sea AI Lab. "
|
| 1978 |
+
"Your answer should be friendly, unbiased, faithful, informative and detailed."
|
| 1979 |
+
),
|
| 1980 |
+
stop_words=["<|im_end|>"],
|
| 1981 |
+
)
|
| 1982 |
+
|
| 1983 |
+
|
| 1984 |
+
register_template(
|
| 1985 |
+
name="seed_coder",
|
| 1986 |
+
format_user=StringFormatter(
|
| 1987 |
+
slots=[{"bos_token"}, "user\n{{content}}", {"eos_token"}, {"bos_token"}, "assistant\n"]
|
| 1988 |
+
),
|
| 1989 |
+
format_system=StringFormatter(slots=[{"bos_token"}, "system\n{{content}}", {"eos_token"}]),
|
| 1990 |
+
default_system=(
|
| 1991 |
+
"You are an AI programming assistant, utilizing the Seed-Coder model, developed by ByteDance Seed, "
|
| 1992 |
+
"and you only answer questions related to computer science. For politically sensitive questions, "
|
| 1993 |
+
"security and privacy issues, and other non-computer science questions, you will refuse to answer.\n\n"
|
| 1994 |
+
),
|
| 1995 |
+
)
|
| 1996 |
+
|
| 1997 |
+
|
| 1998 |
+
# copied from llama3 template
|
| 1999 |
+
register_template(
|
| 2000 |
+
name="skywork_o1",
|
| 2001 |
+
format_user=StringFormatter(
|
| 2002 |
+
slots=[
|
| 2003 |
+
(
|
| 2004 |
+
"<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 2005 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 2006 |
+
)
|
| 2007 |
+
]
|
| 2008 |
+
),
|
| 2009 |
+
format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
|
| 2010 |
+
format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
|
| 2011 |
+
format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
|
| 2012 |
+
format_observation=StringFormatter(
|
| 2013 |
+
slots=[
|
| 2014 |
+
(
|
| 2015 |
+
"<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
|
| 2016 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 2017 |
+
)
|
| 2018 |
+
]
|
| 2019 |
+
),
|
| 2020 |
+
format_tools=ToolFormatter(tool_format="llama3"),
|
| 2021 |
+
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
|
| 2022 |
+
default_system=(
|
| 2023 |
+
"You are Skywork-o1, a thinking model developed by Skywork AI, specializing in solving complex problems "
|
| 2024 |
+
"involving mathematics, coding, and logical reasoning through deep thought. When faced with a user's request, "
|
| 2025 |
+
"you first engage in a lengthy and in-depth thinking process to explore possible solutions to the problem. "
|
| 2026 |
+
"After completing your thoughts, you then provide a detailed explanation of the solution process "
|
| 2027 |
+
"in your response."
|
| 2028 |
+
),
|
| 2029 |
+
stop_words=["<|eot_id|>", "<|eom_id|>"],
|
| 2030 |
+
)
|
| 2031 |
+
|
| 2032 |
+
|
| 2033 |
+
register_template(
|
| 2034 |
+
name="smollm",
|
| 2035 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 2036 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 2037 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 2038 |
+
stop_words=["<|im_end|>"],
|
| 2039 |
+
)
|
| 2040 |
+
|
| 2041 |
+
|
| 2042 |
+
register_template(
|
| 2043 |
+
name="smollm2",
|
| 2044 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 2045 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 2046 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 2047 |
+
stop_words=["<|im_end|>"],
|
| 2048 |
+
default_system="You are a helpful AI assistant named SmolLM, trained by Hugging Face.",
|
| 2049 |
+
)
|
| 2050 |
+
|
| 2051 |
+
|
| 2052 |
+
register_template(
|
| 2053 |
+
name="solar",
|
| 2054 |
+
format_user=StringFormatter(slots=["### User:\n{{content}}\n\n### Assistant:\n"]),
|
| 2055 |
+
format_system=StringFormatter(slots=["### System:\n{{content}}\n\n"]),
|
| 2056 |
+
efficient_eos=True,
|
| 2057 |
+
)
|
| 2058 |
+
|
| 2059 |
+
|
| 2060 |
+
register_template(
|
| 2061 |
+
name="starchat",
|
| 2062 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|end|>\n<|assistant|>"]),
|
| 2063 |
+
format_assistant=StringFormatter(slots=["{{content}}<|end|>\n"]),
|
| 2064 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}<|end|>\n"]),
|
| 2065 |
+
stop_words=["<|end|>"],
|
| 2066 |
+
)
|
| 2067 |
+
|
| 2068 |
+
|
| 2069 |
+
register_template(
|
| 2070 |
+
name="telechat",
|
| 2071 |
+
format_user=StringFormatter(slots=["<_user>{{content}}<_bot>"]),
|
| 2072 |
+
format_system=StringFormatter(slots=["<_system>{{content}}<_end>"]),
|
| 2073 |
+
)
|
| 2074 |
+
|
| 2075 |
+
|
| 2076 |
+
register_template(
|
| 2077 |
+
name="telechat2",
|
| 2078 |
+
format_user=StringFormatter(slots=["<_user>{{content}}<_bot>"]),
|
| 2079 |
+
format_system=StringFormatter(slots=["<_system>{{content}}"]),
|
| 2080 |
+
default_system=(
|
| 2081 |
+
"你是中国电信星辰语义大模型,英文名是TeleChat,你是由中电信人工智能科技有限公司和中国电信人工智能研究院(TeleAI)研发的人工智能助手。"
|
| 2082 |
+
),
|
| 2083 |
+
)
|
| 2084 |
+
|
| 2085 |
+
|
| 2086 |
+
register_template(
|
| 2087 |
+
name="vicuna",
|
| 2088 |
+
format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
|
| 2089 |
+
default_system=(
|
| 2090 |
+
"A chat between a curious user and an artificial intelligence assistant. "
|
| 2091 |
+
"The assistant gives helpful, detailed, and polite answers to the user's questions."
|
| 2092 |
+
),
|
| 2093 |
+
replace_jinja_template=True,
|
| 2094 |
+
)
|
| 2095 |
+
|
| 2096 |
+
|
| 2097 |
+
register_template(
|
| 2098 |
+
name="video_llava",
|
| 2099 |
+
format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
|
| 2100 |
+
default_system=(
|
| 2101 |
+
"A chat between a curious user and an artificial intelligence assistant. "
|
| 2102 |
+
"The assistant gives helpful, detailed, and polite answers to the user's questions."
|
| 2103 |
+
),
|
| 2104 |
+
mm_plugin=get_mm_plugin(name="video_llava", image_token="<image>", video_token="<video>"),
|
| 2105 |
+
)
|
| 2106 |
+
|
| 2107 |
+
|
| 2108 |
+
register_template(
|
| 2109 |
+
name="xuanyuan",
|
| 2110 |
+
format_user=StringFormatter(slots=["Human: {{content}} Assistant:"]),
|
| 2111 |
+
default_system=(
|
| 2112 |
+
"以下是用户和人工智能助手之间的对话。用户以Human开头,人工智能助手以Assistant开头,"
|
| 2113 |
+
"会对人类提出的问题给出有帮助、高质量、详细和礼貌的回答,并且总是拒绝参与与不道德、"
|
| 2114 |
+
"不安全、有争议、政治敏感等相关的话题、问题和指示。\n"
|
| 2115 |
+
),
|
| 2116 |
+
)
|
| 2117 |
+
|
| 2118 |
+
|
| 2119 |
+
register_template(
|
| 2120 |
+
name="xverse",
|
| 2121 |
+
format_user=StringFormatter(slots=["Human: {{content}}\n\nAssistant: "]),
|
| 2122 |
+
)
|
| 2123 |
+
|
| 2124 |
+
|
| 2125 |
+
register_template(
|
| 2126 |
+
name="yayi",
|
| 2127 |
+
format_user=StringFormatter(slots=[{"token": "<|Human|>"}, ":\n{{content}}\n\n", {"token": "<|YaYi|>"}, ":"]),
|
| 2128 |
+
format_assistant=StringFormatter(slots=["{{content}}\n\n"]),
|
| 2129 |
+
format_system=StringFormatter(slots=[{"token": "<|System|>"}, ":\n{{content}}\n\n"]),
|
| 2130 |
+
default_system=(
|
| 2131 |
+
"You are a helpful, respectful and honest assistant named YaYi "
|
| 2132 |
+
"developed by Beijing Wenge Technology Co.,Ltd. "
|
| 2133 |
+
"Always answer as helpfully as possible, while being safe. "
|
| 2134 |
+
"Your answers should not include any harmful, unethical, "
|
| 2135 |
+
"racist, sexist, toxic, dangerous, or illegal content. "
|
| 2136 |
+
"Please ensure that your responses are socially unbiased and positive in nature.\n\n"
|
| 2137 |
+
"If a question does not make any sense, or is not factually coherent, "
|
| 2138 |
+
"explain why instead of answering something not correct. "
|
| 2139 |
+
"If you don't know the answer to a question, please don't share false information."
|
| 2140 |
+
),
|
| 2141 |
+
stop_words=["<|End|>"],
|
| 2142 |
+
)
|
| 2143 |
+
|
| 2144 |
+
|
| 2145 |
+
# copied from chatml template
|
| 2146 |
+
register_template(
|
| 2147 |
+
name="yi",
|
| 2148 |
+
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
|
| 2149 |
+
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
|
| 2150 |
+
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
|
| 2151 |
+
stop_words=["<|im_end|>"],
|
| 2152 |
+
)
|
| 2153 |
+
|
| 2154 |
+
|
| 2155 |
+
register_template(
|
| 2156 |
+
name="yi_vl",
|
| 2157 |
+
format_user=StringFormatter(slots=["### Human: {{content}}\n### Assistant:"]),
|
| 2158 |
+
format_assistant=StringFormatter(slots=["{{content}}\n"]),
|
| 2159 |
+
default_system=(
|
| 2160 |
+
"This is a chat between an inquisitive human and an AI assistant. "
|
| 2161 |
+
"Assume the role of the AI assistant. Read all the images carefully, "
|
| 2162 |
+
"and respond to the human's questions with informative, helpful, detailed and polite answers. "
|
| 2163 |
+
"这是一个好奇的人类和一个人工智能助手之间的对话。假设你扮演这个AI助手的角色。"
|
| 2164 |
+
"仔细阅读所有的图像,并对人类的问题做出信息丰富、有帮助、详细的和礼貌的回答。\n\n"
|
| 2165 |
+
),
|
| 2166 |
+
stop_words=["###"],
|
| 2167 |
+
efficient_eos=True,
|
| 2168 |
+
mm_plugin=get_mm_plugin(name="llava", image_token="<image>"),
|
| 2169 |
+
)
|
| 2170 |
+
|
| 2171 |
+
|
| 2172 |
+
register_template(
|
| 2173 |
+
name="yuan",
|
| 2174 |
+
format_user=StringFormatter(slots=["{{content}}", {"token": "<sep>"}]),
|
| 2175 |
+
format_assistant=StringFormatter(slots=["{{content}}<eod>\n"]),
|
| 2176 |
+
stop_words=["<eod>"],
|
| 2177 |
+
)
|
| 2178 |
+
|
| 2179 |
+
|
| 2180 |
+
register_template(
|
| 2181 |
+
name="zephyr",
|
| 2182 |
+
format_user=StringFormatter(slots=["<|user|>\n{{content}}", {"eos_token"}, "<|assistant|>\n"]),
|
| 2183 |
+
format_system=StringFormatter(slots=["<|system|>\n{{content}}", {"eos_token"}]),
|
| 2184 |
+
default_system="You are Zephyr, a helpful assistant.",
|
| 2185 |
+
)
|
| 2186 |
+
|
| 2187 |
+
|
| 2188 |
+
register_template(
|
| 2189 |
+
name="ziya",
|
| 2190 |
+
format_user=StringFormatter(slots=["<human>:{{content}}\n<bot>:"]),
|
| 2191 |
+
format_assistant=StringFormatter(slots=["{{content}}\n"]),
|
| 2192 |
+
)
|
data/dataset/12_10/overfit_data.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"conversations": [
|
| 4 |
+
{
|
| 5 |
+
"from": "human",
|
| 6 |
+
"value": "I have an XML file containing a list of records, each with a title and description. Here is the full content of the XML file:\n<records>\n <record>\n <title>Record 1</title>\n <description>Description for record 1</description>\n </record>\n <record>\n <title>Record 2</title>\n <description>Description for record 2</description>\n </record>\n <record>\n <title>Record 3</title>\n <description>Description for record 3</description>\n </record>\n</records>\n\nI need:\n1. To extract the titles and descriptions from each record in the XML data.\n2. To sort the extracted titles in descending order.\nIn total, I want to receive a final report that includes the sorted list of titles."
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"from": "function_call",
|
| 10 |
+
"value": "{\"name\": \"parse_xml_data\", \"arguments\": {\"xml_data\": \"<records><record><title>Record 1</title><description>Description for record 1</description></record><record><title>Record 2</title><description>Description for record 2</description></record><record><title>Record 3</title><description>Description for record 3</description></record></records>\", \"index\": 1}}"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"from": "observation",
|
| 14 |
+
"value": "[{\"type\": \"raw\", \"json\": {\"data\": [\"#1. Record 1: Description for record 1\", \"#2. Record 2: Description for record 2\", \"#3. Record 3: Description for record 3\"]}}]"
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"from": "function_call",
|
| 18 |
+
"value": "{\"name\": \"dict_values_sorted\", \"arguments\": {\"dictionary\": {\"#1. Record 1\": 1, \"#2. Record 2\": 2, \"#3. Record 3\": 3}}}"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"from": "observation",
|
| 22 |
+
"value": "[{\"type\": \"raw\", \"json\": {\"data\": [3, 2, 1]}}]"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"from": "gpt",
|
| 26 |
+
"value": "<answer>The sorted list of titles is: Record 3, Record 2, Record 1.</answer>"
|
| 27 |
+
}
|
| 28 |
+
],
|
| 29 |
+
"system": "# Role\n\nYou are an AI assistant capable of calling various functions to help users solve their problems.\n\n# Tool Selection\n\n**Important**: The available function signatures are provided in the <tools></tools> section. You must carefully select one or more appropriate tools from this section that can solve the user's request.\n\n# Output Rules\n\nYou must strictly follow the rules below when responding:\n\n## 1. Function Call Format\nWhen you need to call a function, you must output only one function call per round in the following format:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>\n\n**Parameter Parsing**: The arguments must be parsed based on the user's query. **Do not fabricate parameters that are not mentioned or cannot be reasonably inferred from the query.** Only use parameters that can be reasonably extracted or inferred from the user's request.\n\n**Basis for Generating Function Call Content**:\n- **First function call**: The user's query and available tools information.\n- **n-th function call (n > 1)**: The user's query, available tools information, and the complete conversation history in <chat_history></chat_history> from the previous n-1 rounds (including all prior function calls, observations, and answers). In some scenarios, observations may be empty; this is acceptable for generating function calls.\n\n**Example**:\n<tool_call>\n{\\\"name\\\": \\\"cancel_booking\\\", \\\"arguments\\\": {\\\"access_token\\\": \\\"abc123xyz\\\", \\\"booking_id\\\": \\\"flight_001\\\"}}\n</tool_call>\n\n## 2. Answer Format\nWhen you judge from the chat history that all necessary tools have been called, you must immediately stop calling tools and provide the final answer in the following format:\n<answer>\nYour final answer here\n</answer>\n\n**Answer Generation Requirements**:\n- **Critical**: If all observations in chat-history are empty (meaning tools were called but returned no data), you MUST reply exactly: \"Sorry, I did not obtain sufficient information to complete your request.\" Do NOT fabricate, invent, or generate any content based on assumptions. Do NOT create imaginary results or responses. Only output this exact message.\n- **Important**: The provided tools may include tools that are irrelevant or unsuitable for the current query. If you determine there are no suitable tools to answer the user's request, reply: \"Sorry, there are no suitable tools to answer your request.\"\n- **Important**: If you have called some tools and obtained observations, but the available tools are insufficient to fully satisfy the user's request (e.g., some required tools are missing from the available tool list), you MUST reply exactly: \"Sorry, there are not enough tools to fully satisfy your request.\" Do NOT fabricate or generate partial answers based on incomplete information.\n- Carefully analyze the conversation history to determine the current turn. The answer must be based on the user's query and all available observation results in the conversation.\n\n## 3. Intelligent Process Stage Judgment\n- single-hop: Typically requires only one tool call to complete the task.\n- multi-hop: Requires multiple tool calls to complete the task.\n- single-turn: Involves only one user query.\n- multi-turn: Involves multiple user queries; later queries may refer to or build upon earlier exchanges.\n- When you see that the assistant has issued a tool call and received an observation, that tool call is considered complete.\n\n**Special Note**: By examining the conversation history, you can clearly see:\n- Previous interactions between the user and the assistant\n- Tool calls that have already been executed\n- Results returned by tools\n- The stage the current conversation has reached\n\n## 4. Strictly Prohibited Behaviors\n- Do not output a function call and an answer in the same round.\n- Do not repeatedly call the same tool with identical parameters.\n- Do not ignore existing tool calls and their returned information in the conversation history.\n- Do not fabricate parameters that are not present in or reasonably implied by the user's query.\n\n## 5. Error Handling and Data Quality Assessment\n- If the tool returns an empty observation, it may indicate there is no data under the current query conditions or that observation data is unavailable in the current context.\n- If the tool returns error messages (e.g., \"resource not found\", \"invalid parameters\"), do not repeat the same tool call.\n- In such cases, provide an explanatory answer describing the specific error cause or data condition.\n- Absolutely do not repeatedly call the same tool because it returned an error or empty data.\n\n\n",
|
| 30 |
+
"tools": "[{\"name\": \"parse_xml_data\", \"description\": \"Parses the XML data and extracts the title and description from each record element.\", \"inputSchema\": {\"type\": \"object\", \"properties\": {\"xml_data\": {\"type\": \"string\", \"description\": \"A string containing the XML data.\"}, \"index\": {\"type\": \"integer\", \"description\": \"An integer to start numbering the records from.\"}}, \"required\": [\"xml_data\", \"index\"]}, \"category\": \"analysis\", \"domain\": \"technology\"}, {\"name\": \"dict_values_sorted\", \"description\": \"Returns a list of the values from the dictionary, sorted in descending order.\", \"inputSchema\": {\"type\": \"object\", \"properties\": {\"dictionary\": {\"type\": \"object\", \"additionalProperties\": {\"type\": \"integer\"}, \"description\": \"The dictionary from which to sort the values.\"}}, \"required\": [\"dictionary\"]}, \"category\": \"analysis\", \"domain\": \"technology\"}]"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"conversations": [
|
| 34 |
+
{
|
| 35 |
+
"from": "human",
|
| 36 |
+
"value": "Generate a static map image of size 1600x1600 centered at the coordinates (55.7558, 37.6176) with a zoom level of 11, using the 'toursprung-terrain' maptype, and include a delta_zoom of 2. Output the URL."
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"from": "function_call",
|
| 40 |
+
"value": "{\"name\":\"staticmaps\",\"arguments\":{\"size\":\"1600x1600\",\"center\":\"55.7558,37.6176\",\"zoom\":11,\"maptype\":\"toursprung-terrain\",\"delta_zoom\":2}}"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"from": "observation",
|
| 44 |
+
"value": "[{\"type\": \"tool_result\", \"name\": \"staticmaps\", \"content\": \"https://maps.example.com/map.png?center=55.7558%2C37.6176&size=1600x1600&zoom=11&maptype=toursprung-terrain&delta_zoom=2&format=png\"}]"
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"from": "gpt",
|
| 48 |
+
"value": "<answer></answer>"
|
| 49 |
+
}
|
| 50 |
+
],
|
| 51 |
+
"system": "# Role\n\nYou are an AI assistant capable of calling various functions to help users solve their problems.\n\n# Tool Selection\n\n**Important**: The available function signatures are provided in the <tools></tools> section. You must carefully select one or more appropriate tools from this section that can solve the user's request.\n\n# Output Rules\n\nYou must strictly follow the rules below when responding:\n\n## 1. Function Call Format\nWhen you need to call a function, you must output only one function call per round in the following format:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>\n\n**Parameter Parsing**: The arguments must be parsed based on the user's query. **Do not fabricate parameters that are not mentioned or cannot be reasonably inferred from the query.** Only use parameters that can be reasonably extracted or inferred from the user's request.\n\n**Basis for Generating Function Call Content**:\n- **First function call**: The user's query and available tools information.\n- **n-th function call (n > 1)**: The user's query, available tools information, and the complete conversation history in <chat_history></chat_history> from the previous n-1 rounds (including all prior function calls, observations, and answers). In some scenarios, observations may be empty; this is acceptable for generating function calls.\n\n**Example**:\n<tool_call>\n{\\\"name\\\": \\\"cancel_booking\\\", \\\"arguments\\\": {\\\"access_token\\\": \\\"abc123xyz\\\", \\\"booking_id\\\": \\\"flight_001\\\"}}\n</tool_call>\n\n## 2. Answer Format\nWhen you judge from the chat history that all necessary tools have been called, you must immediately stop calling tools and provide the final answer in the following format:\n<answer>\nYour final answer here\n</answer>\n\n**Answer Generation Requirements**:\n- **Critical**: If all observations in chat-history are empty (meaning tools were called but returned no data), you MUST reply exactly: \"Sorry, I did not obtain sufficient information to complete your request.\" Do NOT fabricate, invent, or generate any content based on assumptions. Do NOT create imaginary results or responses. Only output this exact message.\n- **Important**: The provided tools may include tools that are irrelevant or unsuitable for the current query. If you determine there are no suitable tools to answer the user's request, reply: \"Sorry, there are no suitable tools to answer your request.\"\n- **Important**: If you have called some tools and obtained observations, but the available tools are insufficient to fully satisfy the user's request (e.g., some required tools are missing from the available tool list), you MUST reply exactly: \"Sorry, there are not enough tools to fully satisfy your request.\" Do NOT fabricate or generate partial answers based on incomplete information.\n- Carefully analyze the conversation history to determine the current turn. The answer must be based on the user's query and all available observation results in the conversation.\n\n## 3. Intelligent Process Stage Judgment\n- single-hop: Typically requires only one tool call to complete the task.\n- multi-hop: Requires multiple tool calls to complete the task.\n- single-turn: Involves only one user query.\n- multi-turn: Involves multiple user queries; later queries may refer to or build upon earlier exchanges.\n- When you see that the assistant has issued a tool call and received an observation, that tool call is considered complete.\n\n**Special Note**: By examining the conversation history, you can clearly see:\n- Previous interactions between the user and the assistant\n- Tool calls that have already been executed\n- Results returned by tools\n- The stage the current conversation has reached\n\n## 4. Strictly Prohibited Behaviors\n- Do not output a function call and an answer in the same round.\n- Do not repeatedly call the same tool with identical parameters.\n- Do not ignore existing tool calls and their returned information in the conversation history.\n- Do not fabricate parameters that are not present in or reasonably implied by the user's query.\n\n## 5. Error Handling and Data Quality Assessment\n- If the tool returns an empty observation, it may indicate there is no data under the current query conditions or that observation data is unavailable in the current context.\n- If the tool returns error messages (e.g., \"resource not found\", \"invalid parameters\"), do not repeat the same tool call.\n- In such cases, provide an explanatory answer describing the specific error cause or data condition.\n- Absolutely do not repeatedly call the same tool because it returned an error or empty data.\n\n\n",
|
| 52 |
+
"tools": "[{\"name\": \"staticmaps\", \"description\": \"Generates a static map image URL based on the given parameters.\", \"required\": [\"size\", \"center\", \"zoom\"], \"inputSchema\": {\"type\": \"object\", \"properties\": {\"type\": {\"type\": \"str\", \"description\": \"dict\"}, \"properties\": {\"size\": {\"description\": \"Size of the map. Format is usually `{width}x{height}`.\", \"type\": \"str\", \"default\": \"640x480\"}, \"center\": {\"description\": \"Center coordinates of the map. Format is `{latitude},{longitude}`.\", \"type\": \"str\", \"default\": \"48.20835,16.3725\"}, \"zoom\": {\"description\": \"Zoom level of the map.\", \"type\": \"int\", \"default\": \"11\"}, \"bounds\": {\"description\": \"Bounding box to define the map area instead of `center` and `zoom`. Format is `{north},{east},{south},{west}`.\", \"type\": \"str, optional\", \"default\": \"\"}, \"geojson\": {\"description\": \"GeoJSON geometry to include on the map. Format is `{attribute}:{value}[|{attribute}:{value}...]`.\", \"type\": \"str, optional\", \"default\": \"\"}, \"maptype\": {\"description\": \"Type of the map, defining its appearance. Default is 'toursprung-terrain'.\", \"type\": \"str, optional\", \"default\": \"toursprung-terrain\"}, \"path\": {\"description\": \"Path to include on the map. Format is `{attribute}:{value}[|{attribute}:{value}...]`.\", \"type\": \"str, optional\", \"default\": \"\"}, \"delta_zoom\": {\"description\": \"Zoom level adjustment if zoom is calculated automatically.\", \"type\": \"int, optional\", \"default\": \"\"}, \"kml\": {\"description\": \"KML data to include on the map. Format is `{kml}?{attribute}={value}[&{attribute}={value}...]`.\", \"type\": \"str, optional\", \"default\": \"\"}, \"format\": {\"description\": \"File format of the map image. Default is 'png'.\", \"type\": \"str, optional\", \"default\": \"png\"}, \"marker\": {\"description\": \"Marker to include on the map. Format is `{attribute}:{value}[|{attribute}:{value}...]`.\", \"type\": \"str, optional\", \"default\": \"\"}, \"factor\": {\"description\": \"Image scaling factor.\", \"type\": \"str, optional\", \"default\": \"\"}}}, \"required\": []}, \"category\": \"generate\", \"domain\": \"technology\"}]"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"conversations": [
|
| 56 |
+
{
|
| 57 |
+
"from": "human",
|
| 58 |
+
"value": "Hi, can you check if my website is working fine? The URL is www.mywebsite.com."
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"from": "function_call",
|
| 62 |
+
"value": "{\"name\": \"check_website_status\", \"arguments\": {\"url\": \"www.mywebsite.com\"}}"
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"from": "observation",
|
| 66 |
+
"value": "[{\"type\": \"raw\", \"json\": {\"status\": \"OK\", \"message\": \"The website www.mywebsite.com is up and running.\"}}]"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"from": "gpt",
|
| 70 |
+
"value": "<answer>The website www.mywebsite.com is up and running. Everything seems fine.</answer>"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"from": "human",
|
| 74 |
+
"value": "That's great! Can you also check www.anotherwebsite.com for me?"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"from": "function_call",
|
| 78 |
+
"value": "{\"name\": \"check_website_status\", \"arguments\": {\"url\": \"www.anotherwebsite.com\"}}"
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"from": "observation",
|
| 82 |
+
"value": "[{\"type\": \"raw\", \"json\": {\"status\": \"ERROR\", \"message\": \"The website www.anotherwebsite.com is currently down.\"}}]"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"from": "gpt",
|
| 86 |
+
"value": "<answer>I'm sorry, but the website www.anotherwebsite.com is currently down.</answer>"
|
| 87 |
+
}
|
| 88 |
+
],
|
| 89 |
+
"system": "# Role\n\nYou are an AI assistant capable of calling various functions to help users solve their problems.\n\n# Tool Selection\n\n**Important**: The available function signatures are provided in the <tools></tools> section. You must carefully select one or more appropriate tools from this section that can solve the user's request.\n\n# Output Rules\n\nYou must strictly follow the rules below when responding:\n\n## 1. Function Call Format\nWhen you need to call a function, you must output only one function call per round in the following format:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>\n\n**Parameter Parsing**: The arguments must be parsed based on the user's query. **Do not fabricate parameters that are not mentioned or cannot be reasonably inferred from the query.** Only use parameters that can be reasonably extracted or inferred from the user's request.\n\n**Basis for Generating Function Call Content**:\n- **First function call**: The user's query and available tools information.\n- **n-th function call (n > 1)**: The user's query, available tools information, and the complete conversation history in <chat_history></chat_history> from the previous n-1 rounds (including all prior function calls, observations, and answers). In some scenarios, observations may be empty; this is acceptable for generating function calls.\n\n**Example**:\n<tool_call>\n{\\\"name\\\": \\\"cancel_booking\\\", \\\"arguments\\\": {\\\"access_token\\\": \\\"abc123xyz\\\", \\\"booking_id\\\": \\\"flight_001\\\"}}\n</tool_call>\n\n## 2. Answer Format\nWhen you judge from the chat history that all necessary tools have been called, you must immediately stop calling tools and provide the final answer in the following format:\n<answer>\nYour final answer here\n</answer>\n\n**Answer Generation Requirements**:\n- **Critical**: If all observations in chat-history are empty (meaning tools were called but returned no data), you MUST reply exactly: \"Sorry, I did not obtain sufficient information to complete your request.\" Do NOT fabricate, invent, or generate any content based on assumptions. Do NOT create imaginary results or responses. Only output this exact message.\n- **Important**: The provided tools may include tools that are irrelevant or unsuitable for the current query. If you determine there are no suitable tools to answer the user's request, reply: \"Sorry, there are no suitable tools to answer your request.\"\n- **Important**: If you have called some tools and obtained observations, but the available tools are insufficient to fully satisfy the user's request (e.g., some required tools are missing from the available tool list), you MUST reply exactly: \"Sorry, there are not enough tools to fully satisfy your request.\" Do NOT fabricate or generate partial answers based on incomplete information.\n- Carefully analyze the conversation history to determine the current turn. The answer must be based on the user's query and all available observation results in the conversation.\n\n## 3. Intelligent Process Stage Judgment\n- single-hop: Typically requires only one tool call to complete the task.\n- multi-hop: Requires multiple tool calls to complete the task.\n- single-turn: Involves only one user query.\n- multi-turn: Involves multiple user queries; later queries may refer to or build upon earlier exchanges.\n- When you see that the assistant has issued a tool call and received an observation, that tool call is considered complete.\n\n**Special Note**: By examining the conversation history, you can clearly see:\n- Previous interactions between the user and the assistant\n- Tool calls that have already been executed\n- Results returned by tools\n- The stage the current conversation has reached\n\n## 4. Strictly Prohibited Behaviors\n- Do not output a function call and an answer in the same round.\n- Do not repeatedly call the same tool with identical parameters.\n- Do not ignore existing tool calls and their returned information in the conversation history.\n- Do not fabricate parameters that are not present in or reasonably implied by the user's query.\n\n## 5. Error Handling and Data Quality Assessment\n- If the tool returns an empty observation, it may indicate there is no data under the current query conditions or that observation data is unavailable in the current context.\n- If the tool returns error messages (e.g., \"resource not found\", \"invalid parameters\"), do not repeat the same tool call.\n- In such cases, provide an explanatory answer describing the specific error cause or data condition.\n- Absolutely do not repeatedly call the same tool because it returned an error or empty data.\n\n\n",
|
| 90 |
+
"tools": "[{\"name\": \"check_website_status\", \"description\": \"Check the status of a website\", \"inputSchema\": {\"type\": \"object\", \"properties\": {\"url\": {\"type\": \"string\", \"description\": \"The URL of the website\"}}, \"required\": [\"url\"]}, \"category\": \"system\", \"domain\": \"technology\"}]"
|
| 91 |
+
}
|
| 92 |
+
]
|
data/dataset/12_10/testmix_dataset.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/dataset/12_10/格式问题分析与修正建议.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 格式问题分析与修正建议
|
| 2 |
+
|
| 3 |
+
## 问题分析
|
| 4 |
+
|
| 5 |
+
### 1. 关于"User query:"前缀的问题
|
| 6 |
+
|
| 7 |
+
**当前实现:**
|
| 8 |
+
- 历史信息中:`User query: {原始query内容}`
|
| 9 |
+
- 当前query:`Current user query: {当前query内容}`
|
| 10 |
+
|
| 11 |
+
**问题:**
|
| 12 |
+
- 前缀不一致("User query:" vs "Current user query:")
|
| 13 |
+
- 前缀放在`<|im_start|>user`标签内,可能不符合预期
|
| 14 |
+
|
| 15 |
+
**建议:**
|
| 16 |
+
- 方案1:统一前缀,都使用`User query:`,去掉"Current"
|
| 17 |
+
- 方案2:去掉所有前缀,直接使用原始内容
|
| 18 |
+
- 方案3:历史信息去掉前缀,当前query保留前缀(用于区分)
|
| 19 |
+
|
| 20 |
+
### 2. 关于`<chat_history>`位置的问题
|
| 21 |
+
|
| 22 |
+
**当前实现:**
|
| 23 |
+
- `<chat_history>`放在user消息的elements中(在`<|im_start|>user`标签外)
|
| 24 |
+
|
| 25 |
+
**问题:**
|
| 26 |
+
- 用户认为应该放在system角色中
|
| 27 |
+
|
| 28 |
+
**分析:**
|
| 29 |
+
- 从origin.py看,原始实现中没有`<chat_history>`标签
|
| 30 |
+
- 当前实现中,历史信息是作为普通文本添加到elements中,不通过format_user格式化
|
| 31 |
+
- 如果放在system中,需要修改system消息的构建逻辑
|
| 32 |
+
|
| 33 |
+
**建议:**
|
| 34 |
+
- 方案1:保持当前实现(在user消息中,但在`<|im_start|>user`标签外)
|
| 35 |
+
- 方案2:将`<chat_history>`放在system消息中(需要修改system消息的构建逻辑)
|
| 36 |
+
|
| 37 |
+
### 3. 关于原始格式(origin.py)的问题
|
| 38 |
+
|
| 39 |
+
**origin.py的实现:**
|
| 40 |
+
- 有5个role:`USER`, `ASSISTANT`, `FUNCTION`, `OBSERVATION`, `SYSTEM`
|
| 41 |
+
- observation通过`format_observation`格式化
|
| 42 |
+
- 在qwen模板中,`format_observation`的格式是:
|
| 43 |
+
```
|
| 44 |
+
<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n
|
| 45 |
+
```
|
| 46 |
+
- 也就是说,observation是作为**user role**,但内容是`<tool_response>...</tool_response>`,然后后面跟着assistant role
|
| 47 |
+
- origin.py中,observation的内容会被增强,添加"用户查询: xxx"等前缀
|
| 48 |
+
|
| 49 |
+
**关键发现:**
|
| 50 |
+
- **origin.py中,observation确实是作为user role处理的**,不是独立的observation role
|
| 51 |
+
- 但当前template.py中,observation是作为独立的OBSERVATION role处理的
|
| 52 |
+
|
| 53 |
+
### 4. 关于当前query前缀的问题
|
| 54 |
+
|
| 55 |
+
**当前实现:**
|
| 56 |
+
```python
|
| 57 |
+
current_user_query = f"Current user query: {original_contents[i]}"
|
| 58 |
+
elements += self.format_user.apply(content=current_user_query, idx=str(i // 2))
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
**问题:**
|
| 62 |
+
- "Current user query:"前缀是否必要?
|
| 63 |
+
- 如果历史信息中有"User query:"前缀,当前query是否也应该有前缀?
|
| 64 |
+
|
| 65 |
+
**建议:**
|
| 66 |
+
- 如果历史信息有前缀,当前query也应该有前缀(保持一致性)
|
| 67 |
+
- 或者,都去掉前缀,直接使用原始内容
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
## 修正建议
|
| 72 |
+
|
| 73 |
+
### 建议1:统一前缀格式
|
| 74 |
+
|
| 75 |
+
**修改方案:**
|
| 76 |
+
- 历史信息:`User query: {原始query内容}`
|
| 77 |
+
- 当前query:`User query: {当前query内容}`(去掉"Current")
|
| 78 |
+
|
| 79 |
+
**理由:**
|
| 80 |
+
- 保持一致性
|
| 81 |
+
- 简化格式
|
| 82 |
+
|
| 83 |
+
### 建议2:将`<chat_history>`放在system中
|
| 84 |
+
|
| 85 |
+
**修改方案:**
|
| 86 |
+
- 将历史信息包装在`<chat_history>`标签内
|
| 87 |
+
- 将`<chat_history>`添加到system消息的content中
|
| 88 |
+
- 只在需要历史信息时(非第一次调用)才添加
|
| 89 |
+
|
| 90 |
+
**理由:**
|
| 91 |
+
- 历史信息属于上下文,放在system中更合理
|
| 92 |
+
- 与原始实现更接近(origin.py中没有`<chat_history>`,但历史信息是通过其他方式传递的)
|
| 93 |
+
|
| 94 |
+
### 建议3:去掉所有前缀
|
| 95 |
+
|
| 96 |
+
**修改方案:**
|
| 97 |
+
- 历史信息:直接使用原始内容,不加前缀
|
| 98 |
+
- 当前query:直接使用原始内容,不加前缀
|
| 99 |
+
|
| 100 |
+
**理由:**
|
| 101 |
+
- 简化格式
|
| 102 |
+
- 减少token消耗
|
| 103 |
+
- 模型可以通过`<chat_history>`标签识别历史信息
|
| 104 |
+
|
| 105 |
+
### 建议4:保持当前实现,但统一前缀
|
| 106 |
+
|
| 107 |
+
**修改方案:**
|
| 108 |
+
- 历史信息:`User query: {原始query内容}`
|
| 109 |
+
- 当前query:`User query: {当前query内容}`(去掉"Current")
|
| 110 |
+
- `<chat_history>`位置:保持当前实现(在user消息中,但在`<|im_start|>user`标签外)
|
| 111 |
+
|
| 112 |
+
**理由:**
|
| 113 |
+
- 最小改动
|
| 114 |
+
- 保持格式一致性
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## 推荐方案
|
| 119 |
+
|
| 120 |
+
**推荐:方案4(保持当前实现,但统一前缀)**
|
| 121 |
+
|
| 122 |
+
**修改内容:**
|
| 123 |
+
1. 将"Current user query:"改为"User query:"
|
| 124 |
+
2. 保持`<chat_history>`在user消息中的位置
|
| 125 |
+
3. 保持其他格式不变
|
| 126 |
+
|
| 127 |
+
**理由:**
|
| 128 |
+
- 最小改动,风险低
|
| 129 |
+
- 统一前缀,格式一致
|
| 130 |
+
- 保持与推理代码的一致性
|
| 131 |
+
|
| 132 |
+
---
|
| 133 |
+
|
| 134 |
+
## 对比:origin.py vs 当前template.py
|
| 135 |
+
|
| 136 |
+
### origin.py(原始实现)
|
| 137 |
+
|
| 138 |
+
**格式:**
|
| 139 |
+
```
|
| 140 |
+
<|im_start|>system
|
| 141 |
+
{system + tools}
|
| 142 |
+
<|im_end|>
|
| 143 |
+
<|im_start|>user
|
| 144 |
+
{query内容}
|
| 145 |
+
<|im_end|>
|
| 146 |
+
<|im_start|>assistant
|
| 147 |
+
{function_call}
|
| 148 |
+
<|im_end|>
|
| 149 |
+
<|im_start|>user
|
| 150 |
+
<tool_response>
|
| 151 |
+
{增强后的observation内容(包含"用户查询: xxx"等前缀)}
|
| 152 |
+
</tool_response>
|
| 153 |
+
<|im_end|>
|
| 154 |
+
<|im_start|>assistant
|
| 155 |
+
{answer}
|
| 156 |
+
<|im_end|>
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
**特点:**
|
| 160 |
+
- observation作为user role
|
| 161 |
+
- observation内容会被增强(添加"用户查询: xxx"等前缀)
|
| 162 |
+
- 没有`<chat_history>`标签
|
| 163 |
+
- 历史信息通过observation的增强内容传递
|
| 164 |
+
|
| 165 |
+
### 当前template.py(修改后)
|
| 166 |
+
|
| 167 |
+
**格式:**
|
| 168 |
+
```
|
| 169 |
+
<|im_start|>system
|
| 170 |
+
{system + tools}
|
| 171 |
+
<|im_end|>
|
| 172 |
+
<chat_history>
|
| 173 |
+
User query: {历史query}
|
| 174 |
+
Tool call: {历史function_call}
|
| 175 |
+
Tool response: {历史observation}
|
| 176 |
+
Assistant reply: {历史answer}
|
| 177 |
+
</chat_history>
|
| 178 |
+
<|im_start|>user
|
| 179 |
+
Current user query: {当前query}
|
| 180 |
+
<|im_end|>
|
| 181 |
+
<|im_start|>assistant
|
| 182 |
+
{function_call}
|
| 183 |
+
<|im_end|>
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
**特点:**
|
| 187 |
+
- 使用`<chat_history>`标签包装历史信息
|
| 188 |
+
- 历史信息在user消息中(在`<|im_start|>user`标签外)
|
| 189 |
+
- 当前query有"Current user query:"前缀
|
| 190 |
+
- observation作为独立的OBSERVATION role
|
| 191 |
+
|
| 192 |
+
---
|
| 193 |
+
|
| 194 |
+
## 需要确认的问题
|
| 195 |
+
|
| 196 |
+
1. **前缀问题**:是否统一为"User query:",还是去掉所有前缀?
|
| 197 |
+
2. **`<chat_history>`位置**:是否应该放在system中,还是保持当前实现?
|
| 198 |
+
3. **当前query前缀**:是否需要前缀,还是直接使用原始内容?
|
| 199 |
+
4. **格式一致性**:训练和推理是否应该完全一致?
|
| 200 |
+
|
| 201 |
+
---
|
| 202 |
+
|
| 203 |
+
## 下一步行动
|
| 204 |
+
|
| 205 |
+
1. 根据用户反馈,确定最终的格式方案
|
| 206 |
+
2. 修改template.py,统一前缀格式
|
| 207 |
+
3. 如果需要,调整`<chat_history>`的位置
|
| 208 |
+
4. 同步修改推理代码,保持一致性
|
| 209 |
+
5. 测试修改后的效果
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
|
data/dataset/12_10/训练与推理输入对比分析.md
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 训练代码与推理代码输入对比分析
|
| 2 |
+
|
| 3 |
+
## 样本信息
|
| 4 |
+
|
| 5 |
+
基于 `format_mutiturn copy.json` 中的第二个样本(32-77行)进行分析。
|
| 6 |
+
|
| 7 |
+
### 对话结构
|
| 8 |
+
```
|
| 9 |
+
1. human (query 1): "In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically."
|
| 10 |
+
2. function_call 1: analyze_customer_feedback(...)
|
| 11 |
+
3. observation 1: [分析结果...]
|
| 12 |
+
4. function_call 2: analyze_customer_feedback(...) [重复]
|
| 13 |
+
5. observation 2: [分析结果...] [重复]
|
| 14 |
+
6. gpt (answer 1): "In the past month, a total of 130 negative feedbacks..."
|
| 15 |
+
7. human (query 2): "In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically." [重复query 1]
|
| 16 |
+
8. function_call 3: analyze_customer_feedback(...) [重复]
|
| 17 |
+
9. observation 3: [分析结果...] [重复]
|
| 18 |
+
10. gpt (answer 2): "In the past month, a total of 130 negative feedbacks..." [重复answer 1]
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
这是一个**multi-turn**对话,包含2个turn,每个turn都有function_call和answer。
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## 训练时的LLM调用(5次)
|
| 26 |
+
|
| 27 |
+
**注意**:这个样本中第一个turn有2个function_call(重复的),所以训练时会调用5次LLM。
|
| 28 |
+
|
| 29 |
+
### 第1次调用:生成第1个Function Call
|
| 30 |
+
|
| 31 |
+
**处理的消息序列:**
|
| 32 |
+
- messages[0]: Role.USER (query 1)
|
| 33 |
+
- messages[1]: Role.FUNCTION (function_call 1) ← **要生成的目标**
|
| 34 |
+
|
| 35 |
+
**输入内容:**
|
| 36 |
+
```
|
| 37 |
+
<|im_start|>system
|
| 38 |
+
# Role
|
| 39 |
+
...
|
| 40 |
+
<tools>
|
| 41 |
+
[工具定义...]
|
| 42 |
+
</tools><|im_end|>
|
| 43 |
+
<|im_start|>user
|
| 44 |
+
In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.<|im_end|>
|
| 45 |
+
<|im_start|>assistant
|
| 46 |
+
[生成function_call 1]
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
**关键点:**
|
| 50 |
+
- 第一次调用,没有历史信息
|
| 51 |
+
- system包含tools
|
| 52 |
+
- 当前query通过format_user格式化,**没有前缀**(直接使用原始内容)
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
### 第2次调用:生成第2个Function Call(第一个turn的第二个function_call)
|
| 57 |
+
|
| 58 |
+
**处理的消息序列:**
|
| 59 |
+
- messages[0]: Role.USER (query 1)
|
| 60 |
+
- messages[1]: Role.FUNCTION (function_call 1)
|
| 61 |
+
- messages[2]: Role.OBSERVATION (observation 1)
|
| 62 |
+
- messages[3]: Role.FUNCTION (function_call 2) ← **要生成的目标**
|
| 63 |
+
|
| 64 |
+
**输入内容:**
|
| 65 |
+
```
|
| 66 |
+
<|im_start|>system
|
| 67 |
+
# Role
|
| 68 |
+
...
|
| 69 |
+
<chat_history>
|
| 70 |
+
User query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.
|
| 71 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 72 |
+
</chat_history>
|
| 73 |
+
|
| 74 |
+
<tools>
|
| 75 |
+
[工具定义...]
|
| 76 |
+
</tools><|im_end|>
|
| 77 |
+
<|im_start|>tool_response
|
| 78 |
+
[observation 1的内容]
|
| 79 |
+
<|im_end|>
|
| 80 |
+
<|im_start|>assistant
|
| 81 |
+
[生成function_call 2]
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
**关键点:**
|
| 85 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 86 |
+
- 历史信息包含:User query + Tool call + Tool response(不包含Assistant reply,因为下一个是FUNCTION)
|
| 87 |
+
- system包含tools(在<chat_history>之后)
|
| 88 |
+
- 当前observation在<tool_response>标签内
|
| 89 |
+
- **注意**:处理OBSERVATION消息时,不添加user消息,直接生成FUNCTION
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
### 第3次调用:生成第1个Answer(第一个turn)
|
| 94 |
+
|
| 95 |
+
**处理的消息序列:**
|
| 96 |
+
- messages[0]: Role.USER (query 1)
|
| 97 |
+
- messages[1]: Role.FUNCTION (function_call 1)
|
| 98 |
+
- messages[2]: Role.OBSERVATION (observation 1)
|
| 99 |
+
- messages[3]: Role.FUNCTION (function_call 2)
|
| 100 |
+
- messages[4]: Role.OBSERVATION (observation 2)
|
| 101 |
+
- messages[5]: Role.ASSISTANT (answer 1) ← **要生成的目标**
|
| 102 |
+
|
| 103 |
+
**输入内容:**
|
| 104 |
+
```
|
| 105 |
+
<|im_start|>system
|
| 106 |
+
# Role
|
| 107 |
+
...
|
| 108 |
+
<chat_history>
|
| 109 |
+
User query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.
|
| 110 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 111 |
+
Tool response: [observation 1的内容]
|
| 112 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 113 |
+
Tool response: [observation 2的内容]
|
| 114 |
+
</chat_history><|im_end|>
|
| 115 |
+
<|im_start|>tool_response
|
| 116 |
+
[observation 2的内容]
|
| 117 |
+
<|im_end|>
|
| 118 |
+
<|im_start|>assistant
|
| 119 |
+
[生成answer 1]
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
**关键点:**
|
| 123 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 124 |
+
- 历史信息包含:User query + Tool call + Tool response(answer和tool call都要放到对话历史中)
|
| 125 |
+
- system不包含tools
|
| 126 |
+
- 当前observation在<tool_response>标签内
|
| 127 |
+
- **注意**:处理OBSERVATION消息时,不添加user消息,直接生成ASSISTANT
|
| 128 |
+
|
| 129 |
+
---
|
| 130 |
+
|
| 131 |
+
### 第4次调用:生成第3个Function Call(Turn 2)
|
| 132 |
+
|
| 133 |
+
**处理的消息序列:**
|
| 134 |
+
- messages[0]: Role.USER (query 1)
|
| 135 |
+
- messages[1]: Role.FUNCTION (function_call 1)
|
| 136 |
+
- messages[2]: Role.OBSERVATION (observation 1)
|
| 137 |
+
- messages[3]: Role.FUNCTION (function_call 2)
|
| 138 |
+
- messages[4]: Role.OBSERVATION (observation 2)
|
| 139 |
+
- messages[5]: Role.ASSISTANT (answer 1)
|
| 140 |
+
- messages[6]: Role.USER (query 2)
|
| 141 |
+
- messages[7]: Role.FUNCTION (function_call 3) ← **要生成的目标**
|
| 142 |
+
|
| 143 |
+
**输入内容:**
|
| 144 |
+
```
|
| 145 |
+
<|im_start|>system
|
| 146 |
+
# Role
|
| 147 |
+
...
|
| 148 |
+
<chat_history>
|
| 149 |
+
User query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.
|
| 150 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 151 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 152 |
+
Assistant reply: In the past month, a total of 130 negative feedbacks...
|
| 153 |
+
</chat_history>
|
| 154 |
+
|
| 155 |
+
<tools>
|
| 156 |
+
[工具定义...]
|
| 157 |
+
</tools><|im_end|>
|
| 158 |
+
<|im_start|>assistant
|
| 159 |
+
[生成function_call 3]
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
**关键点:**
|
| 163 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 164 |
+
- 历史信息包含:User query + Tool call + Assistant reply(生成tool call时,不把observation放在chat_history中)
|
| 165 |
+
- system包含tools(在<chat_history>之后)
|
| 166 |
+
- observation消息包含第二个observation(不在chat_history中)
|
| 167 |
+
- user消息为空(因为chat_history中已经包含了当前query)
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
### 第5次调用:生成第2个Answer(Turn 2)
|
| 172 |
+
|
| 173 |
+
**处理的消息序列:**
|
| 174 |
+
- messages[0]: Role.USER (query 1)
|
| 175 |
+
- messages[1]: Role.FUNCTION (function_call 1)
|
| 176 |
+
- messages[2]: Role.OBSERVATION (observation 1)
|
| 177 |
+
- messages[3]: Role.FUNCTION (function_call 2)
|
| 178 |
+
- messages[4]: Role.OBSERVATION (observation 2)
|
| 179 |
+
- messages[5]: Role.ASSISTANT (answer 1)
|
| 180 |
+
- messages[6]: Role.USER (query 2)
|
| 181 |
+
- messages[7]: Role.FUNCTION (function_call 3)
|
| 182 |
+
- messages[8]: Role.OBSERVATION (observation 3)
|
| 183 |
+
- messages[9]: Role.ASSISTANT (answer 2) ← **要生成的目标**
|
| 184 |
+
|
| 185 |
+
**输入内容:**
|
| 186 |
+
```
|
| 187 |
+
<|im_start|>system
|
| 188 |
+
# Role
|
| 189 |
+
...
|
| 190 |
+
<chat_history>
|
| 191 |
+
User query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.
|
| 192 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 193 |
+
Tool response: [observation 1的内容]
|
| 194 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 195 |
+
Tool response: [observation 2的内容]
|
| 196 |
+
Assistant reply: In the past month, a total of 130 negative feedbacks...
|
| 197 |
+
User query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.
|
| 198 |
+
Tool call: {"name": "analyze_customer_feedback", "arguments": {...}}
|
| 199 |
+
Tool response: [observation 3的内容]
|
| 200 |
+
</chat_history><|im_end|>
|
| 201 |
+
<|im_start|>tool_response
|
| 202 |
+
[observation 3的内容]
|
| 203 |
+
<|im_end|>
|
| 204 |
+
<|im_start|>assistant
|
| 205 |
+
[生成answer 2]
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
**关键点:**
|
| 209 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 210 |
+
- 历史信息包含:所有User query + Tool call + Tool response + Assistant reply(answer和tool call都要放到对话历史中)
|
| 211 |
+
- system不包含tools
|
| 212 |
+
- 当前observation在<tool_response>标签内
|
| 213 |
+
- **注意**:处理OBSERVATION消息时,不添加user消息,直接生成ASSISTANT
|
| 214 |
+
|
| 215 |
+
---
|
| 216 |
+
|
| 217 |
+
## 推理时的LLM调用(5次)
|
| 218 |
+
|
| 219 |
+
**注意**:这个样本中第一个turn有2个function_call(重复的),所以推理时会调用5次LLM。
|
| 220 |
+
|
| 221 |
+
### 第1次调用:生成第1个Function Call
|
| 222 |
+
|
| 223 |
+
**调用函数:** `build_messages_for_function_call(conversations, call_idx=0, ...)`
|
| 224 |
+
|
| 225 |
+
**输入messages:**
|
| 226 |
+
```python
|
| 227 |
+
[
|
| 228 |
+
{
|
| 229 |
+
"role": "system",
|
| 230 |
+
"content": "# Role\n...\n\n<tools>\n[工具定义...]\n</tools>"
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"role": "user",
|
| 234 |
+
"content": "In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically."
|
| 235 |
+
}
|
| 236 |
+
]
|
| 237 |
+
```
|
| 238 |
+
|
| 239 |
+
**关键点:**
|
| 240 |
+
- 第一次调用,没有历史信息
|
| 241 |
+
- system包含tools
|
| 242 |
+
- user消息包含当前query(**没有前缀**)
|
| 243 |
+
|
| 244 |
+
---
|
| 245 |
+
|
| 246 |
+
### 第2次调用:生成第2个Function Call(第一个turn的第二个function_call)
|
| 247 |
+
|
| 248 |
+
**调用函数:** `build_messages_for_function_call(conversations, call_idx=1, generated_calls=[function_call 1], generated_answers=[], ...)`
|
| 249 |
+
|
| 250 |
+
**输入messages:**
|
| 251 |
+
```python
|
| 252 |
+
[
|
| 253 |
+
{
|
| 254 |
+
"role": "system",
|
| 255 |
+
"content": "# Role\n...\n\n<chat_history>\nUser query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.\nTool call: [generated_calls[0],即function_call 1]\n</chat_history>\n\n<tools>\n[工具定义...]\n</tools>"
|
| 256 |
+
},
|
| 257 |
+
{
|
| 258 |
+
"role": "observation",
|
| 259 |
+
"content": "<tool_response>\n[observation 1的内容]\n</tool_response>"
|
| 260 |
+
},
|
| 261 |
+
]
|
| 262 |
+
```
|
| 263 |
+
|
| 264 |
+
**关键点:**
|
| 265 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 266 |
+
- 历史信息包含:User query + Tool call(生成tool call时,不把observation放在chat_history中)
|
| 267 |
+
- 使用已生成的function_call(动态变化的LLM结果)
|
| 268 |
+
- system包含tools(在<chat_history>之后)
|
| 269 |
+
- observation消息包含第一个observation(不在chat_history中)
|
| 270 |
+
- **注意**:chat_history中已经包含了当前query,所以user消息为空(不添加user消息)
|
| 271 |
+
|
| 272 |
+
---
|
| 273 |
+
|
| 274 |
+
### 第3次调用:生成第1个Answer(第一个turn)
|
| 275 |
+
|
| 276 |
+
**调用函数:** `build_messages_for_answer(conversations, answer_idx=0, generated_calls=[function_call 1, function_call 2], generated_answers=[], ...)`
|
| 277 |
+
|
| 278 |
+
**输入messages:**
|
| 279 |
+
```python
|
| 280 |
+
[
|
| 281 |
+
{
|
| 282 |
+
"role": "system",
|
| 283 |
+
"content": "# Role\n...\n\n<chat_history>\nUser query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.\nTool call: [generated_calls[0],即function_call 1]\nTool response: [observation 1的内容]\nTool call: [generated_calls[1],即function_call 2]\nTool response: [observation 2的内容]\n</chat_history>"
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"role": "observation",
|
| 287 |
+
"content": "<tool_response>\n[observation 2的内容]\n</tool_response>"
|
| 288 |
+
},
|
| 289 |
+
]
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
**关键点:**
|
| 293 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 294 |
+
- 历史信息包含:User query + Tool call + Tool response(answer和tool call都要放到对话历史中)
|
| 295 |
+
- system不包含tools
|
| 296 |
+
- 当前observation在observation消息的<tool_response>标签内
|
| 297 |
+
- **注意**:chat_history中已经包含了当前query,所以user消息为空(不添加user消息)
|
| 298 |
+
|
| 299 |
+
---
|
| 300 |
+
|
| 301 |
+
### 第4次调用:生成第3个Function Call(Turn 2)
|
| 302 |
+
|
| 303 |
+
**调用函数:** `build_messages_for_function_call(conversations, call_idx=2, generated_calls=[function_call 1, function_call 2], generated_answers=[answer 1], ...)`
|
| 304 |
+
|
| 305 |
+
**输入messages:**
|
| 306 |
+
```python
|
| 307 |
+
[
|
| 308 |
+
{
|
| 309 |
+
"role": "system",
|
| 310 |
+
"content": "# Role\n...\n\n<chat_history>\nUser query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.\nTool call: [generated_calls[0],即function_call 1]\nTool call: [generated_calls[1],即function_call 2]\nAssistant reply: [generated_answers[0],即answer 1]\n</chat_history>\n\n<tools>\n[工具定义...]\n</tools>"
|
| 311 |
+
},
|
| 312 |
+
{
|
| 313 |
+
"role": "observation",
|
| 314 |
+
"content": "<tool_response>\n[observation 3的内容]\n</tool_response>"
|
| 315 |
+
},
|
| 316 |
+
]
|
| 317 |
+
```
|
| 318 |
+
|
| 319 |
+
**关键点:**
|
| 320 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 321 |
+
- 历史信息包含:User query + Tool call + Assistant reply(生成tool call时,不把observation放在chat_history中)
|
| 322 |
+
- 使用已生成的function_call和answer(动态变化的LLM结果)
|
| 323 |
+
- system包含tools(在<chat_history>之后)
|
| 324 |
+
- observation消息包含第三个observation(不在chat_history中)
|
| 325 |
+
- user消息为空(因为chat_history中已经包含了当前query)
|
| 326 |
+
|
| 327 |
+
---
|
| 328 |
+
|
| 329 |
+
### 第5次调用:生成第2个Answer(Turn 2)
|
| 330 |
+
|
| 331 |
+
**调用函数:** `build_messages_for_answer(conversations, answer_idx=1, generated_calls=[function_call 1, function_call 2, function_call 3], generated_answers=[answer 1], ...)`
|
| 332 |
+
|
| 333 |
+
**输入messages:**
|
| 334 |
+
```python
|
| 335 |
+
[
|
| 336 |
+
{
|
| 337 |
+
"role": "system",
|
| 338 |
+
"content": "# Role\n...\n\n<chat_history>\nUser query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.\nTool call: [generated_calls[0],即function_call 1]\nTool response: [observation 1的内容]\nTool call: [generated_calls[1],即function_call 2]\nTool response: [observation 2的内容]\nAssistant reply: [generated_answers[0],即answer 1]\nUser query: In the past month, have you received a lot of feedback about poor service attitude? I want to see which scenic spots the problem is specifically.\nTool call: [generated_calls[2],即function_call 3]\nTool response: [observation 3的内容]\n</chat_history>"
|
| 339 |
+
},
|
| 340 |
+
{
|
| 341 |
+
"role": "observation",
|
| 342 |
+
"content": "<tool_response>\n[observation 3的内容]\n</tool_response>"
|
| 343 |
+
},
|
| 344 |
+
]
|
| 345 |
+
```
|
| 346 |
+
|
| 347 |
+
**关键点:**
|
| 348 |
+
- 历史信息在system消息中(在<chat_history>标签内)
|
| 349 |
+
- 历史信息包含:所有User query + Tool call + Tool response + Assistant reply(answer和tool call都要放到对话历史中)
|
| 350 |
+
- 使用已生成的function_call和answer(动态变化的LLM结果)
|
| 351 |
+
- system不包含tools
|
| 352 |
+
- 当前observation在observation消息的<tool_response>标签内
|
| 353 |
+
- **注意**:chat_history中已经包含了当前query,所以user消息为空(不添加user消息)
|
| 354 |
+
|
| 355 |
+
---
|
| 356 |
+
|
| 357 |
+
## 关键差异总结
|
| 358 |
+
|
| 359 |
+
### 1. 历史信息的位置
|
| 360 |
+
- **训练时生成Function Call**:历史信息在system消息中(在<chat_history>标签内)
|
| 361 |
+
- **训练时生成Answer**:历史信息在system消息中(在<chat_history>标签内)
|
| 362 |
+
- **推理时生成Function Call**:历史信息在system消息中(在<chat_history>标签内)
|
| 363 |
+
- **推理时生成Answer**:历史信息在system消息中(在<chat_history>标签内)
|
| 364 |
+
|
| 365 |
+
### 2. 历史信息的格式
|
| 366 |
+
- **训练时**:使用`User query:`, `Tool call:`, `Tool response:`, `Assistant reply:`前缀
|
| 367 |
+
- **推理时**:使用相同的前缀格式
|
| 368 |
+
- **重要**:生成answer时不包含Tool call,生成tool call时才包含Tool call
|
| 369 |
+
|
| 370 |
+
### 3. Tools的包含
|
| 371 |
+
- **生成Function Call时**:训练和推理都包含tools
|
| 372 |
+
- **生成Answer时**:训练和推理都不包含tools
|
| 373 |
+
|
| 374 |
+
### 4. 当前消息的格式
|
| 375 |
+
- **训练时生成Function Call**:当前query通过format_user格式化,**没有前缀**(直接使用原始内容)
|
| 376 |
+
- **训练时生成Answer**:当前observation在observation消息的<tool_response>标签内
|
| 377 |
+
- **推理时生成Function Call**:当前query在user消息中,**没有前缀**(直接使用原始内容)
|
| 378 |
+
- **推理时生成Answer**:当前observation在observation消息的<tool_response>标签内
|
| 379 |
+
|
| 380 |
+
### 5. 动态内容的使用
|
| 381 |
+
- **训练时**:使用训练数据中的固定内容
|
| 382 |
+
- **推理时**:使用已生成的function_call和answer(动态变化的LLM结果)
|
| 383 |
+
|
| 384 |
+
---
|
| 385 |
+
|
| 386 |
+
## 一致性检查
|
| 387 |
+
|
| 388 |
+
✅ **格式一致性**:
|
| 389 |
+
- 历史信息都使用`<chat_history>`标签包装
|
| 390 |
+
- 历史信息都使用相同的前缀格式
|
| 391 |
+
- Tools的包含/排除逻辑一致
|
| 392 |
+
|
| 393 |
+
✅ **位置一致性**:
|
| 394 |
+
- 生成Function Call时,历史信息都在system消息中(在<chat_history>标签内)
|
| 395 |
+
- 生成Answer时,历史信息都在system消息中(在<chat_history>标签内)
|
| 396 |
+
|
| 397 |
+
✅ **格式一致性**:
|
| 398 |
+
- 当前query都没有前缀(直接使用原始内容)
|
| 399 |
+
- 历史信息中的query保留"User query:"前缀(在<chat_history>标签内)
|
| 400 |
+
|
| 401 |
+
✅ **格式一致性**:
|
| 402 |
+
- 训练和推理的格式完全一致(历史信息在system中,当前query没有前缀)
|
| 403 |
+
|
| 404 |
+
---
|
| 405 |
+
|
| 406 |
+
## 结论
|
| 407 |
+
|
| 408 |
+
训练代码和推理代码的输入格式**完全一致**:
|
| 409 |
+
1. ✅ 历史信息都在system消息中(在<chat_history>标签内)
|
| 410 |
+
2. ✅ 当前query都没有前缀(直接使用原始内容)
|
| 411 |
+
3. ✅ 历史信息中的query保留"User query:"前缀(在<chat_history>标签内)
|
| 412 |
+
4. ✅ Tools的包含/排除逻辑一致(生成Function Call时包含,生成Answer时不包含)
|
| 413 |
+
|
| 414 |
+
这些修改确保了训练和推理的格式完全一致,有助于模型更好地学习和应用。
|
| 415 |
+
|
data/dataset/12_15/GT_dataset.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a5197fd920b966ccae749906565e788fbb199494d78db00d25e14d86c7863555
|
| 3 |
+
size 5732191453
|