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
相关推荐
Tadas-Gao2 天前
从碳基羊驼到硅基LLaMA:开源大模型家族的生物隐喻与技术进化全景
人工智能·机器学习·大模型·llm·llama
Run_Clover2 天前
llama-factory微调大模型环境配置避坑总结
llama
ss2733 天前
Llama 4开源项目多维分析研究
llama
深科文库3 天前
构建 MCP 服务器:第 2 部分 — 使用资源模板扩展资源
人工智能·chatgpt·llama
晨尘光7 天前
在Windows下编译出llama_cpp_python的DLL后,在虚拟环境中使用方法
python·llama
风筝超冷9 天前
LLaMA-Factory - 批量推理(inference)的脚本
llama
bluebonnet2710 天前
【agent开发】部署LLM(一)
python·llama
阿牛大牛中11 天前
LLaDa——基于 Diffusion 的大语言模型 打平 LLama 3
人工智能·语言模型·llama
Lilith的AI学习日记11 天前
【AI面试秘籍】| 第25期:RAG的关键痛点及解决方案深度解析
人工智能·深度学习·机器学习·chatgpt·aigc·llama
LChuck14 天前
【大模型微调】魔搭社区GPU进行LLaMA-Factory微调大模型自我认知
人工智能·语言模型·自然语言处理·nlp·llama·魔搭社区·modelscope