Quickstart: Supervised Fine-Tuning (SFT)
EngineSurogate EngineIn a few minutes you will fine-tune a small model with LoRA from a ready-made YAML config. Supervised fine-tuning (SFT) teaches a pretrained model from example conversations or instructions. Once the first run works, the hyperparameter advice below helps you tune your own.
1) Pick an example config
Section titled “1) Pick an example config”You’ll find example configs in examples/sft/.
For MiniCPM5 and Spark-X2.5 checkpoints, see the fine-tuning guide for examples and LoRA target names.
A good first choice:
examples/sft/qwen3/qwen3-lora-bf16.yaml
2) Run
Section titled “2) Run”surogate sft examples/sft/qwen3/qwen3-lora-bf16.yamlThe sft command takes the config path and a few optional flags. If you use uv and want to be sure you’re running inside the project environment:
uv run surogate sft examples/sft/qwen3/qwen3-lora-bf16.yaml3) Outputs
Section titled “3) Outputs”Checkpoints, logs and other artifacts are written under the config’s output_dir. Every key used in this page is described in the Configuration Reference.
4) Recommended Hyperparameters
Section titled “4) Recommended Hyperparameters”Dense Models (Standard Fine-Tuning)
Section titled “Dense Models (Standard Fine-Tuning)”Learning Rate:
- LoRA:
1e-4to5e-4(typically2e-4) - Full fine-tuning:
5e-6to2e-5(typically1e-5) - Warmup ratio:
0.03to0.1(3-10% of total steps)
Batch Size:
- Global batch size: 256K-1M tokens recommended
- LoRA: 256K-512K tokens (less memory intensive)
- Full fine-tuning: 512K-1M tokens
- Calculate:
per_device_train_batch_size × gradient_accumulation_steps × num_gpus × sequence_len
LoRA Configuration:
- Rank:
8,16, or32r=8: Fast, memory-efficient, good for simple adaptationsr=16: Balanced (recommended default)r=32: Higher capacity for complex tasks
- Alpha: Match rank (e.g.,
lora_alpha=16forlora_rank=16) - Target modules: All linear layers by default (Q, K, V, O, gate, up, down)
Regularization:
- Weight decay:
0.01to0.1(typically0.01for SFT) - Gradient clipping:
1.0
Precision Options:
- BF16 LoRA (default): Best accuracy
- FP8 QLoRA: 2x faster, minimal accuracy loss (Hopper+)
- FP4 QLoRA: 4x faster, slight accuracy tradeoff (Blackwell+)
- BnB QLoRA: Memory-efficient, works on all GPUs
Example Dense Model Config:
model: Qwen/Qwen3-0.6Boutput_dir: ./output
# Batch configuration (512K tokens global batch)per_device_train_batch_size: 2gradient_accumulation_steps: 8sequence_len: 2048gpus: 4
# Learning ratelearning_rate: 2e-4lr_scheduler_type: cosinewarmup_ratio: 0.05
# LoRAlora: truelora_rank: 16lora_alpha: 16
# Regularizationweight_decay: 0.01max_grad_norm: 1.0
# Precisionrecipe: bf16
# Parallelismzero_level: 25) Fine-Tuning Mixture-of-Experts (MoE) Models
Section titled “5) Fine-Tuning Mixture-of-Experts (MoE) Models”MoE models need different hyperparameters from dense models, especially upcycled MoE models (converted from dense checkpoints). The MoE guide covers MoE training in depth.
Recommended Settings for MoE
Section titled “Recommended Settings for MoE”Key Differences from Dense Models:
| Parameter | Dense Models | MoE Models | Reason |
|---|---|---|---|
| Learning rate | 2e-4 | 1e-5 | MoE routers are sensitive to aggressive LR |
| Warmup ratio | 0.05 | 0.15 | Longer warmup for router stability |
| Gradient clipping | 1.0 | 0.5 | Prevents routing instability |
| Weight decay | 0.01 | 0.01 | Regularizes router weights |
Learning Rate:
- Standard MoE:
1e-5to5e-5(start with1e-5) - Upcycled MoE:
1e-5(conservative, increase only if training is too slow) - Warmup ratio:
0.15(15% of total steps for router stability)
Batch Size:
- Global batch size: 256K-512K tokens (smaller than dense models)
- MoE models are more sample-efficient; smaller batches work well
LoRA Configuration:
- Rank:
16or32(same as dense models) - Alpha: Match rank
- Target modules: Apply to expert layers for maximum adaptation
Regularization:
- Weight decay:
0.01 - Gradient clipping:
0.5(tighter than dense models) - Auxiliary loss coefficient: Use default router aux loss settings
Monitoring MoE Training:
- Gradient norms: Should stay below
0.4during training- If norms exceed
0.5: reduce learning rate or increaserouter_aux_loss_coefin the model’sconfig.jsonfile - If norms spike above
0.8: training is likely diverging
- If norms exceed
- Router collapse symptoms:
- Sudden loss increases after initial decrease
- Gradient norm spikes
- Eval gap turning positive and growing
Example MoE Config:
model: path/to/moe_modelmodel_type: qwen3_moeoutput_dir: ./output
# Batch configuration (256K tokens global batch)per_device_train_batch_size: 1gradient_accumulation_steps: 8sequence_len: 2048gpus: 4
# Learning rate (conservative for MoE)learning_rate: 1e-5lr_scheduler_type: cosinewarmup_ratio: 0.15
# LoRAlora: truelora_rank: 16lora_alpha: 16
# Regularization (tighter for MoE)weight_decay: 0.01max_grad_norm: 0.5
# Precisionrecipe: bf16
# Parallelismzero_level: 2Upcycled MoE Models
Section titled “Upcycled MoE Models”If you upcycled a dense model to MoE with scripts/upcycle_moe.py, take extra care in the first phase of training.
Critical Guidelines:
-
Use conservative learning rates
- Start with
1e-5and increase only if training is too slow - Router weights are freshly initialized and require careful tuning
- Start with
-
Monitor gradient norms closely
- Target: Keep gradient norms below
0.4during training - Warning signs:
- Norms exceed
0.5: Reduce learning rate or increaserouter_aux_loss_coef - Norms spike above
0.8: Training is likely diverging, restart with lower LR
- Norms exceed
- Target: Keep gradient norms below
-
Watch for router collapse
- Symptoms include:
- Sudden loss increases after initial decrease
- Gradient norm spikes
- Eval gap turning positive and growing
- Solution: Reduce learning rate and increase warmup duration
- Symptoms include:
Training Data Requirements:
Based on the upcycling paper:
- Budget: ~150k supervised samples (sufficient for router training)
- Duration: 1 epoch recommended
- Hardware: Single GPU with 24GB+ VRAM is sufficient
- Focus: Training primarily adapts the router; expert weights inherit from dense model
Upcycled MoE Example Config:
model: path/to/upcycled_moe_modelmodel_type: qwen3_moeoutput_dir: ./output
# Very conservative settings for upcycled modelslearning_rate: 1e-5warmup_ratio: 0.2 # Extra-long warmup for routermax_grad_norm: 0.3 # Very tight clipping
lora: truelora_rank: 16lora_alpha: 16
# Small batch, single GPU is fineper_device_train_batch_size: 1gradient_accumulation_steps: 8sequence_len: 20486) Serve what you trained
Section titled “6) Serve what you trained”A LoRA run produces an adapter, but the engine serves whole models, so merge the adapter into the base first. To serve the
merged checkpoint quantized, produce a GGUF from it and point the server at that file (merge and quantize list their options):
surogate merge --base-model Qwen/Qwen3.5-0.8B --checkpoint-dir output/step_00000050 --output mergedsurogate quantize --model merged --output merged-Q4_K_M.gguf --type q4_k_msurogate serve merged-Q4_K_M.gguf --port 8080The quantization step uses llama.cpp, and it writes an ordinary GGUF file. To serve the merged checkpoint at full precision, skip it.
- For private Hugging Face models or datasets, pass
--hub_token. - To distill a larger teacher model into the student during SFT, add a
distillation:block and runsurogate distill-capturebeforesurogate sft. See the Knowledge Distillation guide.
See also
Section titled “See also”- Training modes: Pretraining vs Full Fine-Tuning vs LoRA: when to choose LoRA, QLoRA or full fine-tuning
- Serving models: serve and query the model you trained
- Quickstart: Pretraining
- Configuration: how a config file is put together
- Back to docs index