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
相关推荐
Him__12 小时前
Meta 发布 Llama 4,新一代旗舰 AI 模型
人工智能·ai·llama
black^sugar12 小时前
LLaMA-Factory从安装到微调全流程
llama
zenRRan13 小时前
各种角度全面聊聊Llama 4~
llama
小草cys13 小时前
llama.cpp 和 vLLM 的详细对比分析
大模型·llama·vllm·deepseek
shelly聊AI14 小时前
Meta上新Llama 4,到底行不行?
人工智能·llama
kebijuelun1 天前
Meta 最新发布的 Llama 4:多模态开源大模型全面解析
人工智能·语言模型·aigc·llama
大模型真好玩1 天前
点名DeepSeek?一文解析”最强大模型“Llama-4到底是王者归来 还是 困兽犹斗?
人工智能·llama·deepseek
三月七(爱看动漫的程序员)2 天前
LLM面试题八
数据库·gpt·算法·langchain·prompt·启发式算法·llama
智享AI2 天前
使用 LLaMA-Factory 微调 llama3 模型(二)
llama
新加坡内哥谈技术2 天前
Llama 4 家族:原生多模态 AI 创新新时代的开启
人工智能·深度学习·语言模型·自然语言处理·自动化·llama