LLaMA-Factory使用命令

We provide diverse examples about fine-tuning LLMs.

Make sure to execute these commands in the LLaMA-Factory directory.

Table of Contents

  • [LoRA Fine-Tuning](#LoRA Fine-Tuning)
  • [QLoRA Fine-Tuning](#QLoRA Fine-Tuning)
  • [Full-Parameter Fine-Tuning](#Full-Parameter Fine-Tuning)
  • [Merging LoRA Adapters and Quantization](#Merging LoRA Adapters and Quantization)
  • [Inferring LoRA Fine-Tuned Models](#Inferring LoRA Fine-Tuned Models)
  • Extras

Use CUDA_VISIBLE_DEVICES (GPU) or ASCEND_RT_VISIBLE_DEVICES (NPU) to choose computing devices.

By default, LLaMA-Factory uses all visible computing devices.

Examples

LoRA Fine-Tuning

(Continuous) Pre-Training
bash 复制代码
llamafactory-cli train examples/train_lora/llama3_lora_pretrain.yaml
Supervised Fine-Tuning
bash 复制代码
llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
Multimodal Supervised Fine-Tuning
bash 复制代码
llamafactory-cli train examples/train_lora/llava1_5_lora_sft.yaml
llamafactory-cli train examples/train_lora/qwen2vl_lora_sft.yaml
DPO/ORPO/SimPO Training
bash 复制代码
llamafactory-cli train examples/train_lora/llama3_lora_dpo.yaml
Multimodal DPO/ORPO/SimPO Training
bash 复制代码
llamafactory-cli train examples/train_lora/qwen2vl_lora_dpo.yaml
Reward Modeling
bash 复制代码
llamafactory-cli train examples/train_lora/llama3_lora_reward.yaml
PPO Training
bash 复制代码
llamafactory-cli train examples/train_lora/llama3_lora_ppo.yaml
KTO Training
bash 复制代码
llamafactory-cli train examples/train_lora/llama3_lora_kto.yaml
Preprocess Dataset

It is useful for large dataset, use tokenized_path in config to load the preprocessed dataset.

bash 复制代码
llamafactory-cli train examples/train_lora/llama3_preprocess.yaml
Evaluating on MMLU/CMMLU/C-Eval Benchmarks
bash 复制代码
llamafactory-cli eval examples/train_lora/llama3_lora_eval.yaml
Supervised Fine-Tuning on Multiple Nodes
bash 复制代码
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=1 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
Supervised Fine-Tuning with DeepSpeed ZeRO-3 (Weight Sharding)
bash 复制代码
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_lora/llama3_lora_sft_ds3.yaml

QLoRA Fine-Tuning

Supervised Fine-Tuning with 4/8-bit Bitsandbytes/HQQ/EETQ Quantization (Recommended)
bash 复制代码
llamafactory-cli train examples/train_qlora/llama3_lora_sft_otfq.yaml
Supervised Fine-Tuning with 4/8-bit GPTQ Quantization
bash 复制代码
llamafactory-cli train examples/train_qlora/llama3_lora_sft_gptq.yaml
Supervised Fine-Tuning with 4-bit AWQ Quantization
bash 复制代码
llamafactory-cli train examples/train_qlora/llama3_lora_sft_awq.yaml
Supervised Fine-Tuning with 2-bit AQLM Quantization
bash 复制代码
llamafactory-cli train examples/train_qlora/llama3_lora_sft_aqlm.yaml

Full-Parameter Fine-Tuning

Supervised Fine-Tuning on Single Node
bash 复制代码
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/llama3_full_sft.yaml
Supervised Fine-Tuning on Multiple Nodes
bash 复制代码
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/llama3_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/llama3_full_sft.yaml
Multimodal Supervised Fine-Tuning
bash 复制代码
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/qwen2vl_full_sft.yaml

Merging LoRA Adapters and Quantization

Merge LoRA Adapters

Note: DO NOT use quantized model or quantization_bit when merging LoRA adapters.

bash 复制代码
llamafactory-cli export examples/merge_lora/llama3_lora_sft.yaml
Quantizing Model using AutoGPTQ
bash 复制代码
llamafactory-cli export examples/merge_lora/llama3_gptq.yaml

Inferring LoRA Fine-Tuned Models

Batch Generation using vLLM Tensor Parallel
复制代码
python scripts/vllm_infer.py --model_name_or_path path_to_merged_model --dataset alpaca_en_demo
Use CLI ChatBox
bash 复制代码
llamafactory-cli chat examples/inference/llama3_lora_sft.yaml
Use Web UI ChatBox
bash 复制代码
llamafactory-cli webchat examples/inference/llama3_lora_sft.yaml
Launch OpenAI-style API
bash 复制代码
llamafactory-cli api examples/inference/llama3_lora_sft.yaml

Extras

Full-Parameter Fine-Tuning using GaLore
bash 复制代码
llamafactory-cli train examples/extras/galore/llama3_full_sft.yaml
Full-Parameter Fine-Tuning using BAdam
bash 复制代码
llamafactory-cli train examples/extras/badam/llama3_full_sft.yaml
Full-Parameter Fine-Tuning using Adam-mini
bash 复制代码
llamafactory-cli train examples/extras/adam_mini/qwen2_full_sft.yaml
LoRA+ Fine-Tuning
bash 复制代码
llamafactory-cli train examples/extras/loraplus/llama3_lora_sft.yaml
PiSSA Fine-Tuning
bash 复制代码
llamafactory-cli train examples/extras/pissa/llama3_lora_sft.yaml
Mixture-of-Depths Fine-Tuning
bash 复制代码
llamafactory-cli train examples/extras/mod/llama3_full_sft.yaml
LLaMA-Pro Fine-Tuning
bash 复制代码
bash examples/extras/llama_pro/expand.sh
llamafactory-cli train examples/extras/llama_pro/llama3_freeze_sft.yaml
FSDP+QLoRA Fine-Tuning
bash 复制代码
bash examples/extras/fsdp_qlora/train.sh
Computing BLEU and ROUGE Scores
bash 复制代码
llamafactory-cli train examples/extras/nlg_eval/llama3_lora_predict.yaml
相关推荐
try2find2 天前
安装llama-cpp-python踩坑记
开发语言·python·llama
西西弗Sisyphus2 天前
LLaMA-Factory 单卡后训练微调Qwen3完整脚本
微调·llama·llama-factory·后训练
顾道长生'2 天前
(Arxiv-2024)自回归模型优于扩散:Llama用于可扩展的图像生成
计算机视觉·数据挖掘·llama·自回归模型·多模态生成与理解
Zhijun.li@Studio12 天前
【LLaMA-Factory 实战系列】二、WebUI 篇 - Qwen2.5-VL 多模态模型 LoRA 微调保姆级教程
人工智能·自然语言处理·llama·多模态大模型
1213412 天前
LLM:重构数字世界的“智能操作系统”
gpt·aigc·ai编程·llama·gpu算力
冷雨夜中漫步20 天前
Java中如何使用lambda表达式分类groupby
java·开发语言·windows·llama
扫地的小何尚22 天前
全新NVIDIA Llama Nemotron Nano视觉语言模型在OCR基准测试中准确率夺冠
c++·人工智能·语言模型·机器人·ocr·llama·gpu
CFAteam22 天前
DeepSeek AI功能演示:如何生成Verilog脚本
人工智能·ai·fpga开发·llama
Tadas-Gao24 天前
从碳基羊驼到硅基LLaMA:开源大模型家族的生物隐喻与技术进化全景
人工智能·机器学习·大模型·llm·llama
Run_Clover24 天前
llama-factory微调大模型环境配置避坑总结
llama