We provide diverse examples about fine-tuning LLMs.
Make sure to execute these commands in the LLaMA-Factory directory.
- LoRA Fine-Tuning
- QLoRA Fine-Tuning
- Full-Parameter Fine-Tuning
- Merging LoRA Adapters and Quantization
- 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.
Basic usage:
llamafactory-cli train examples/train_lora/llama3_lora_sft.yamlAdvanced usage:
CUDA_VISIBLE_DEVICES=0,1 llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml \
learning_rate=1e-5 \
logging_steps=1bash examples/train_lora/llama3_lora_sft.shllamafactory-cli train examples/train_lora/llama3_lora_pretrain.yamlllamafactory-cli train examples/train_lora/llama3_lora_sft.yamlllamafactory-cli train examples/train_lora/qwen2_5vl_lora_sft.yamlllamafactory-cli train examples/train_lora/llama3_lora_dpo.yamlllamafactory-cli train examples/train_lora/qwen2_5vl_lora_dpo.yamlllamafactory-cli train examples/train_lora/llama3_lora_reward.yamlllamafactory-cli train examples/train_lora/llama3_lora_ppo.yamlllamafactory-cli train examples/train_lora/llama3_lora_kto.yamlIt is useful for large dataset, use tokenized_path in config to load the preprocessed dataset.
llamafactory-cli train examples/train_lora/llama3_preprocess.yamlllamafactory-cli eval examples/train_lora/llama3_lora_eval.yamlFORCE_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.yamlFORCE_TORCHRUN=1 llamafactory-cli train examples/train_lora/llama3_lora_sft_ds3.yamlUSE_RAY=1 llamafactory-cli train examples/train_lora/llama3_lora_sft_ray.yamlllamafactory-cli train examples/train_qlora/llama3_lora_sft_otfq.yamlllamafactory-cli train examples/train_qlora/llama3_lora_sft_bnb_npu.yamlllamafactory-cli train examples/train_qlora/llama3_lora_sft_gptq.yamlllamafactory-cli train examples/train_qlora/llama3_lora_sft_awq.yamlllamafactory-cli train examples/train_qlora/llama3_lora_sft_aqlm.yamlFORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/llama3_full_sft.yamlFORCE_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.yamlTo launch an elastic job with MAX_RESTARTS failures retries, run the following on at least MIN_NNODES nodes and at most MAX_NNODES nodes. RDZV_ID should be set as a unique job id (shared by all nodes participating in the job). See also torchrun.
FORCE_TORCHRUN=1 MIN_NNODES=1 MAX_NNODES=3 MAX_RESTARTS=3 RDZV_ID=llamafactory MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/llama3_full_sft.yamlFORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/qwen2_5vl_full_sft.yamlNote: DO NOT use quantized model or quantization_bit when merging LoRA adapters.
llamafactory-cli export examples/merge_lora/llama3_lora_sft.yamlllamafactory-cli export examples/merge_lora/llama3_gptq.yamlllamafactory-cli export examples/merge_lora/llama3_full_sft.yamlpython scripts/vllm_infer.py --model_name_or_path meta-llama/Meta-Llama-3-8B-Instruct --template llama3 --dataset alpaca_en_demo
python scripts/eval_bleu_rouge.py generated_predictions.jsonl
llamafactory-cli chat examples/inference/llama3_lora_sft.yamlllamafactory-cli webchat examples/inference/llama3_lora_sft.yamlllamafactory-cli api examples/inference/llama3_lora_sft.yamlllamafactory-cli train examples/extras/galore/llama3_full_sft.yamlllamafactory-cli train examples/extras/apollo/llama3_full_sft.yamlllamafactory-cli train examples/extras/badam/llama3_full_sft.yamlllamafactory-cli train examples/extras/adam_mini/qwen2_full_sft.yamlllamafactory-cli train examples/extras/muon/qwen2_full_sft.yamlllamafactory-cli train examples/extras/loraplus/llama3_lora_sft.yamlllamafactory-cli train examples/extras/pissa/llama3_lora_sft.yamlllamafactory-cli train examples/extras/mod/llama3_full_sft.yamlbash examples/extras/llama_pro/expand.sh
llamafactory-cli train examples/extras/llama_pro/llama3_freeze_sft.yamlbash examples/extras/fsdp_qlora/train.sh