examples/README.md
We provide diverse examples about fine-tuning LLMs.
Make sure to execute these commands in the LLaMA-Factory directory.
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/qwen3_lora_sft.yaml
Advanced usage:
CUDA_VISIBLE_DEVICES=0,1 llamafactory-cli train examples/train_lora/qwen3_lora_sft.yaml \
learning_rate=1e-5 \
logging_steps=1
bash examples/train_lora/qwen3_lora_sft.sh
llamafactory-cli train examples/train_lora/qwen3_lora_pretrain.yaml
llamafactory-cli train examples/train_lora/qwen3_lora_sft.yaml
llamafactory-cli train examples/train_lora/qwen3vl_lora_sft.yaml
llamafactory-cli train examples/train_lora/qwen3_lora_dpo.yaml
llamafactory-cli train examples/train_lora/qwen3vl_lora_dpo.yaml
llamafactory-cli train examples/train_lora/qwen3_lora_reward.yaml
llamafactory-cli train examples/train_lora/qwen3_lora_kto.yaml
It is useful for large dataset, use tokenized_path in config to load the preprocessed dataset.
llamafactory-cli train examples/train_lora/qwen3_preprocess.yaml
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/qwen3_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/qwen3_lora_sft.yaml
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_lora/qwen3_lora_sft_ds3.yaml
USE_RAY=1 llamafactory-cli train examples/train_lora/qwen3_lora_sft_ray.yaml
llamafactory-cli train examples/train_qlora/qwen3_lora_sft_otfq.yaml
llamafactory-cli train examples/train_qlora/qwen3_lora_sft_bnb_npu.yaml
llamafactory-cli train examples/train_qlora/llama3_lora_sft_gptq.yaml
llamafactory-cli train examples/train_qlora/llama3_lora_sft_awq.yaml
llamafactory-cli train examples/train_qlora/llama3_lora_sft_aqlm.yaml
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/qwen3_full_sft.yaml
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_full/qwen3_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/qwen3_full_sft.yaml
To 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/qwen3_full_sft.yaml
FORCE_TORCHRUN=1 llamafactory-cli train examples/train_full/qwen3vl_full_sft.yaml
Note: DO NOT use quantized model or quantization_bit when merging LoRA adapters.
llamafactory-cli export examples/merge_lora/qwen3_lora_sft.yaml
llamafactory-cli export examples/merge_lora/qwen3_gptq.yaml
llamafactory-cli export examples/merge_lora/qwen3_full_sft.yaml
python scripts/vllm_infer.py --model_name_or_path Qwen/Qwen3-4B-Instruct-2507 --template qwen3_nothink --dataset alpaca_en_demo
python scripts/eval_bleu_rouge.py generated_predictions.jsonl
llamafactory-cli chat examples/inference/qwen3_lora_sft.yaml
llamafactory-cli webchat examples/inference/qwen3_lora_sft.yaml
llamafactory-cli api examples/inference/qwen3_lora_sft.yaml
llamafactory-cli train examples/extras/galore/llama3_full_sft.yaml
llamafactory-cli train examples/extras/apollo/llama3_full_sft.yaml
llamafactory-cli train examples/extras/badam/llama3_full_sft.yaml
llamafactory-cli train examples/extras/adam_mini/qwen2_full_sft.yaml
llamafactory-cli train examples/extras/muon/qwen2_full_sft.yaml
llamafactory-cli train examples/extras/loraplus/llama3_lora_sft.yaml
llamafactory-cli train examples/extras/pissa/llama3_lora_sft.yaml
llamafactory-cli train examples/extras/mod/llama3_full_sft.yaml
bash examples/extras/llama_pro/expand.sh
llamafactory-cli train examples/extras/llama_pro/llama3_freeze_sft.yaml
bash examples/extras/fsdp_qlora/train.sh
llamafactory-cli train examples/extras/oft/llama3_oft_sft.yaml
llamafactory-cli train examples/extras/qoft/llama3_oft_sft_bnb_npu.yaml