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
template 与模型不匹配,对话格式错误。CUDA_VISIBLE_DEVICES 和 DeepSpeed 配置。