llama-factory

LLaMA-Factory 模型微调

补充说明

LLaMA-Factory 提供统一的微调 CLI 和 WebUI,支持 LoRA、QLoRA、全参数微调、DPO 和多种开源模型。适合快速做领域适配和指令微调。

常用示例

安装:

git clone https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e ".[torch,metrics]"

启动 WebUI:

llamafactory-cli webui

LoRA 微调:

llamafactory-cli train examples/train_lora/qwen2_lora_sft.yaml

导出合并模型:

llamafactory-cli export examples/merge_lora/qwen2_lora_sft.yaml

推理:

llamafactory-cli chat examples/inference/qwen2_lora_sft.yaml

常用参数:

model_name_or_path: Qwen/Qwen2.5-7B-Instruct
stage: sft
finetuning_type: lora
lora_rank: 8
per_device_train_batch_size: 2
gradient_accumulation_steps: 8
learning_rate: 1.0e-4
num_train_epochs: 3

易错点与排错