LLaMA-Factory大模型微调

一.LoRA 微调

(增量)预训练

llamafactory-cli train examples/train_lora/qwen3_lora_pretrain.yaml

指令监督微调

llamafactory-cli train examples/train_lora/qwen3_lora_sft.yaml

多模态指令监督微调

llamafactory-cli train examples/train_lora/qwen3vl_lora_sft.yaml

DPO/ORPO/SimPO 训练

llamafactory-cli train examples/train_lora/qwen3_lora_dpo.yaml

多模态 DPO/ORPO/SimPO 训练

llamafactory-cli train examples/train_lora/qwen3vl_lora_dpo.yaml

奖励模型训练

llamafactory-cli train examples/train_lora/qwen3_lora_reward.yaml

KTO 训练

llamafactory-cli train examples/train_lora/qwen3_lora_kto.yaml

预处理数据集

对于大数据集有帮助,在配置中使用 tokenized_path 以加载预处理后的数据集。

llamafactory-cli train examples/train_lora/qwen3_preprocess.yaml

多机指令监督微调

FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/qwen3_lora_sft.yaml

FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=1 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/qwen3_lora_sft.yaml

支持弹性和容错的多机指令监督微调

要启动一个支持弹性节点和容错的多机指令微调,在每个节点上执行以下命令。弹性节点数量范围为 MIN_NNODES:MAX_NNODES,每个节点最多允许因为错误重启 MAX_RESTARTS 次。RDZV_ID 应设置为一个唯一的作业 ID(由参与该作业的所有节点共享)。更多新可以参考官方文档 torchrun

FORCE_TORCHRUN=1 MIN_NNODES=1 MAX_NNODES=3 MAX_RESTARTS=3 RDZV_ID=llamafactory MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/qwen3_full_sft.yaml

使用 DeepSpeed ZeRO-3 平均分配显存

FORCE_TORCHRUN=1 llamafactory-cli train examples/train_lora/qwen3_lora_sft_ds3.yaml

使用 Ray 在 4 张 GPU 上微调

USE_RAY=1 llamafactory-cli train examples/train_lora/qwen3_lora_sft_ray.yaml

二.QLoRA 微调

基于 4/8 比特 Bitsandbytes/HQQ/EETQ 量化进行指令监督微调(推荐)

llamafactory-cli train examples/train_qlora/qwen3_lora_sft_otfq.yaml

在 NPU 上基于 4 比特 Bitsandbytes 量化进行指令监督微调

llamafactory-cli train examples/train_qlora/qwen3_lora_sft_bnb_npu.yaml

基于 4/8 比特 GPTQ 量化进行指令监督微调

llamafactory-cli train examples/train_qlora/llama3_lora_sft_gptq.yaml

基于 4 比特 AWQ 量化进行指令监督微调

llamafactory-cli train examples/train_qlora/llama3_lora_sft_awq.yaml

基于 2 比特 AQLM 量化进行指令监督微调

llamafactory-cli train examples/train_qlora/llama3_lora_sft_aqlm.yaml

三.全参数微调

在单机上进行指令监督微调

FORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/qwen3_full_sft.yaml

在多机上进行指令监督微调

FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/qwen3_full_sft.yaml

FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=1 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/qwen3_full_sft.yaml

多模态指令监督微调

FORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/qwen3vl_full_sft.yaml

四、合并 LoRA 适配器与模型量化

合并 LoRA 适配器

注:请勿使用量化后的模型或 quantization_bit 参数来合并 LoRA 适配器。

llamafactory-cli export examples/merge_lora/qwen3_lora_sft.yaml

使用 AutoGPTQ 量化模型

llamafactory-cli export examples/merge_lora/qwen3_gptq.yaml

保存 Ollama 配置文件

llamafactory-cli export examples/merge_lora/qwen3_full_sft.yaml

五、推理 LoRA 模型

使用 vLLM 多卡推理评估

python scripts/vllm_infer.py --model_name_or_path Qwen/Qwen3-4B-Instruct-2507 --template qwen3_nothink --dataset alpaca_en_demo

python scripts/eval_bleu_rouge.py generated_predictions.jsonl

使用命令行对话框

llamafactory-cli chat examples/inference/qwen3_lora_sft.yaml

使用浏览器对话框

llamafactory-cli webchat examples/inference/qwen3_lora_sft.yaml

启动 OpenAI 风格 API

llamafactory-cli api examples/inference/qwen3_lora_sft.yaml

相关推荐
zhangfeng113316 分钟前
计算机视觉vc 3D 希尔伯特曲线 基础介绍,人工智能
人工智能·计算机视觉·3d
没事别瞎琢磨20 分钟前
十一、审计与 Run Session——每一步操作都被记录
人工智能·node.js
没事别瞎琢磨20 分钟前
十六、AgentSandbox——把所有模块串起来的编排类
人工智能·node.js
George37523 分钟前
当 Loop Engineering 成为行业共识,我发现自己的开源项目已经实践了 3 个月
人工智能
没事别瞎琢磨25 分钟前
十二、网络代理与白名单规则引擎
人工智能·node.js
马士兵教育28 分钟前
Java还有前景吗?Java+AI大模型学习路线及项目?
java·人工智能·python·学习·机器学习
没事别瞎琢磨29 分钟前
十四、Git Worktree 隔离执行
人工智能·node.js
安全指北针36 分钟前
大模型时代,谁在领跑中国AI安全赛道?中国AI安全产品市场分析
人工智能
KaMeidebaby1 小时前
卡梅德生物技术快报|纯化重组蛋白实操详解
人工智能·python·tcp/ip·算法·机器学习
Cloud_Shy6181 小时前
解读《Effective Python 3rd Edition》:从练气到老魔(第五章 Item 30 - 32)
开发语言·人工智能·笔记·python·学习方法