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__19 小时前
AI能源危机:人工智能发展与环境可持续性的矛盾与解决之道
人工智能·ai·chatgpt·aigc·llama
小技工丨1 天前
LLaMA-Factory:了解webUI参数
人工智能·llm·llama·llama-factory
AI360labs_atyun2 天前
谷歌前CEO TED演讲解析:AI 红利的三年窗口期与行业重构
人工智能·科技·ai·重构·llama·教育
KangkangLoveNLP3 天前
Llama:开源的急先锋
人工智能·深度学习·神经网络·算法·机器学习·自然语言处理·llama
小技工丨3 天前
LLaMA-Factory:环境准备
机器学习·大模型·llama·llama-factory
聚客AI3 天前
ChatGPT到Claude全适配:跨模型Prompt高级设计规范与迁移技巧
人工智能·机器学习·语言模型·自然语言处理·langchain·transformer·llama
LucianaiB5 天前
使用GpuGeek高效完成LLaMA大模型微调:实践与心得分享
ai·llama·ai自动化·gpugeek
为啥全要学6 天前
LLaMA-Factory 微调 Qwen2-7B-Instruct
llama·大模型微调·llamafactory
一把年纪学编程7 天前
dify 连接不上ollama An error occurred during credentials validation:
llama
陈奕昆8 天前
五、【LLaMA-Factory实战】模型部署与监控:从实验室到生产的全链路实践
开发语言·人工智能·python·llama·大模型微调