trainer

Training

Configuration

The training hyperparameters and their gotchas

All training parameters live in config.yamlruntime_info.input.training. The block generates the LLaMA-Factory YAML from these values at runtime. This page documents the fields that matter most and the gotchas behind them.

Core fields

FieldMeaning
stageTraining stage (sft)
finetuning_typefull for full fine-tuning
deepspeedDeepSpeed config path (ds_z3_config.json = ZeRO-3)
templateChat template (see below)
cutoff_lenMax sequence length (tokens)
rope_scalingRoPE scaling method (see below)
max_samplesUpper bound applied by LLaMA-Factory after loading
output_dirRun name / checkpoint directory
per_device_train_batch_sizeBatch size per GPU
gradient_accumulation_stepsGradient accumulation steps
learning_rateLearning rate
num_train_epochsNumber of epochs
lr_scheduler_typeLR schedule (e.g. cosine)
warmup_ratioWarmup fraction of total steps
save_strategyCheckpoint schedule: steps, epoch, or no
save_stepsCheckpoint interval when save_strategy: steps
save_only_modelSave only model weights, without resumable optimizer state

The effective global batch size is per_device_train_batch_size × gradient_accumulation_steps × n_gpus.

Template

Match the template family to the model: Qwen3 uses qwen3 / qwen3_nothink; Qwen3.5 uses qwen3_5 / qwen3_5_nothink. Select a thinking-capable variant only when the dataset intentionally preserves reasoning content. The active Qwen3.5 profile uses qwen3_5. See Scaffolds.

Long context

Enable a model-supported RoPE scaling method such as yarn when cutoff_len exceeds the base model's native context window (max_position_embeddings or the documented context length). There is no universal 32K threshold: compare the requested cutoff with the selected model's own limit.

The checked-in Qwen3.5 profile uses rope_scaling: null: its native context already covers the configured 128K cutoff, and this architecture ignores the older top-level RoPE scaling option.

Checkpointing

  • save_only_model: true skips saving optimizer state — it saves disk but prevents resuming.
  • save_strategy: steps uses save_steps; epoch saves at epoch boundaries.
  • resume_from_checkpoint: null — set it to a checkpoint directory path to resume.
  • A non-empty output_dir is rejected by default. Destructive replacement requires both overwrite_output_dir: true and the explicit runtime acknowledgement SFT_ALLOW_OVERWRITE_OUTPUT=1.
  • A relative output_dir writes to artifacts/model/<basename>; an absolute path is honored as-is by both training and the dashboard.

Performance toggles

FieldEffect
bf16: truebf16 mixed-precision training
enable_liger_kernel: trueLiger fused kernels
use_unsloth_gc: trueUnsloth gradient checkpointing
flash_attn: fa2FlashAttention-2, built against the installed PyTorch

Experiment tracking

experiment.wandb_mode controls reporting: disabled generates report_to: none; offline logs locally without an API key; online requires WANDB_API_KEY in the private runtime environment.

Tunable parameters

The hyperparameters worth tuning between runs (all under runtime_info.input.training / .conversion):

ParameterRange / meaning
learning_rate1e-5 to 1e-3
num_train_epochsNumber of epochs
per_device_train_batch_sizeBatch size per GPU
gradient_accumulation_stepsGradient accumulation steps
max_instancesHarbor conversion cap or ready-made-source num_samples

Common failure modes

SymptomFix
Single-GPU run on an 8-GPU nodeEnsure FORCE_TORCHRUN=1 (set by train.sh) and n_gpus_per_node is correct
Dataset key points to an old LF filenameLet train.sh update the mapping, or pick a new conversion.data_name
Requested cutoff_len exceeds the model's native context windowEnable a RoPE scaling method supported by that model, such as yarn
Non-empty output directory rejectedRename output_dir; only intentional destructive replacement should set both overwrite controls
WandB online mode without an API keyExport WANDB_API_KEY, or switch to offline/disabled

On this page