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
相关推荐
m0_603888714 天前
LLaMA-Adapter V2 Parameter-Efficient Visual Instruction Model
人工智能·深度学习·ai·llama·论文速览
三千院本院8 天前
LlaMA_Factory实战微调VL大模型
llama
爱分享的飘哥13 天前
第四十六章:AI的“瞬时记忆”与“高效聚焦”:llama.cpp的KV Cache与Attention机制
llama·llama.cpp·kv cache·attention优化·llm cpu推理·量化attention·gguf推理
psyq14 天前
LLaMA Factory 角色扮演模型微调实践记录
人工智能·llama
liliangcsdn22 天前
mac测试ollama llamaindex
数据仓库·人工智能·prompt·llama
茫茫人海一粒沙23 天前
使用 LLaMA 3 8B 微调一个 Reward Model:从入门到实践
llama
liliangcsdn24 天前
mac llama_index agent算术式子计算示例
人工智能·python·macos·llama
许愿与你永世安宁25 天前
RAG(检索增强生成)里的文档管理
数据库·人工智能·gpt·oracle·llama·rag
许愿与你永世安宁1 个月前
基于Llama的RAG 3种模型配置方法
人工智能·python·自然语言处理·json·github·llama·faiss
至善迎风1 个月前
本地部署 Kimi K2 全指南(llama.cpp、vLLM、Docker 三法)
docker·容器·llama·kimi