Supervised Fine-tuning

Command Line

You can fine-tune using the parameters in examples/train_lora/qwen3_lora_sft.yaml with the following command:

llamafactory-cli train examples/train_lora/qwen3_lora_sft.yaml

You can also update the YAML parameters by appending them:

llamafactory-cli train examples/train_lora/qwen3_lora_sft.yaml \
    learning_rate=1e-5 \
    logging_steps=1

Note

By default, LLaMA-Factory uses all visible computing devices. You can specify which devices to use via CUDA_VISIBLE_DEVICES or ASCEND_RT_VISIBLE_DEVICES if needed.

examples/train_lora/qwen3_lora_sft.yaml provides a configuration example for fine-tuning. This configuration specifies model parameters, fine-tuning method parameters, dataset parameters, evaluation parameters, etc. You need to configure them according to your own needs.

### examples/train_lora/qwen3_lora_sft.yaml
model_name_or_path: Qwen/Qwen3-4B-Instruct-2507
trust_remote_code: true

stage: sft
do_train: true
finetuning_type: lora
lora_rank: 8
lora_target: all

dataset: identity,alpaca_en_demo
template: qwen3_nothink
cutoff_len: 2048
max_samples: 1000
preprocessing_num_workers: 16
dataloader_num_workers: 4

output_dir: saves/qwen3-4b/lora/sft
logging_steps: 10
save_steps: 500
plot_loss: true
overwrite_output_dir: true
save_only_model: false
report_to: none

per_device_train_batch_size: 1
gradient_accumulation_steps: 8
learning_rate: 1.0e-4
num_train_epochs: 3.0
lr_scheduler_type: cosine
warmup_ratio: 0.1
bf16: true
ddp_timeout: 180000000
resume_from_checkpoint: null

# eval_dataset: alpaca_en_demo
# val_size: 0.1
# per_device_eval_batch_size: 1
# eval_strategy: steps
# eval_steps: 500

Note

The model model_name_or_path and dataset dataset must exist and correspond to the template.

Important Training Parameters

Name

Description

model_name_or_path

Model name or path

stage

Training stage. Options: rm(reward modeling), pt(pretrain), sft(Supervised Fine-Tuning), PPO, DPO, KTO, ORPO

do_train

true for training, false for evaluation

finetuning_type

Fine-tuning method. Options: freeze, lora, full

lora_target

Target modules for LoRA method. Default: all.

dataset

Dataset(s) to use. Use “,” to separate multiple datasets

template

Dataset template. Ensure the dataset template corresponds to the model.

output_dir

Output path

logging_steps

Logging interval in steps

save_steps

Model checkpoint saving interval

overwrite_output_dir

Whether to allow overwriting the output directory

per_device_train_batch_size

Training batch size per device

gradient_accumulation_steps

Number of gradient accumulation steps

max_grad_norm

Gradient clipping threshold

learning_rate

Learning rate

lr_scheduler_type

Learning rate schedule. Options: linear, cosine, polynomial, constant, etc.

num_train_epochs

Number of training epochs

bf16

Whether to use bf16 format

warmup_ratio

Learning rate warmup ratio

warmup_steps

Learning rate warmup steps

push_to_hub

Whether to push the model to Huggingface