Training features
EngineSurogate EngineEach config here shows one training feature on a small model, ready to run. They are
complete configs: from the repository root, run
surogate sft examples/training/<file>.yaml. All use Qwen3-0.6B and the same
instruction dataset as the basic BF16 LoRA example.
Swap in your own dataset and step budget. Each config writes to its own output
directory and starts a fresh run by default.
| Config | Feature | Resources |
|---|---|---|
| full-finetune.yaml | Update all parameters; FP32 master weights/gradients, AdamW, cosine schedule | One GPU; more memory than LoRA |
| multi-gpu.yaml | Four-GPU data parallelism, ZeRO-3, FP8 persistent quants in host RAM, offloaded gradients/optimizer, communication overlap | Four FP8-capable GPUs and host RAM |
| cpu-offload.yaml | Full fine-tuning with CPU weights/gradients/optimizer and saved activation offload | One GPU plus host RAM; GPU computes forward/backward |
| long-context.yaml | 8K context, tiled MLP, recomputation, activation offload, chunked LM head and attention backward | One GPU and host RAM |
| adaptive.yaml | Automatic LR reduction, early stopping, epoch/token-budget adjustment, WSD schedule and local metrics | One GPU; epoch-derived step budget |
| continue-adapter.yaml | Import an existing trainable PEFT adapter | Run the basic BF16 LoRA recipe first |
| runtime-lora.yaml | Attention-only adapter for native runtime serving | One GPU; then use serving examples |
For LoRA, online QLoRA and prequantized bases, use the
model recipes. BF16 runs on the widest
range of hardware; FP8 needs compatible hardware and NVFP4 compute needs Blackwell.
How the base is stored and what precision computes are separate settings: qlora_bnb,
qlora_fp8, and qlora_fp4 pick online base quantization, and recipe picks compute.
Don’t enable online QLoRA flags on a checkpoint that is already quantized.
Multiple GPUs and large models
Section titled “Multiple GPUs and large models”One Surogate process drives all the GPUs, so don’t wrap the examples in torchrun
(see multi-GPU training).
CUDA_VISIBLE_DEVICES=0,1,2,3 surogate sft examples/training/multi-gpu.yamlsurogate sft examples/sft/qwen3/qwen3-lora-bf16-ray.yamlsurogate sft examples/sft/qwen35/qwen36-text-lora-fp8-pp.yamlThe Ray config needs a running cluster with two nodes and four GPUs per node. Every
node needs the same checkout and environment, and must be able to reach the data and
model paths; see multi-node setup. Its
ray_address: auto connects to the existing cluster.
The dispatch pipeline config is a separate four-GPU LoRA workflow for a 27B model.
offload_master streams the frozen base from pinned host RAM. It can’t be combined
with ZeRO sharding, expert parallelism, cpu_training, or residual offload. The
scheduler picks the stages for you; see dispatch-PP.
For MoE expert parallelism and routing, use the Qwen3.5/3.6 MoE or Laguna recipes.
They show ep_size, load balancing, BF16 expert adapters, and router losses
(see the MoE guide). ep_size must divide both the GPU
and the expert count. train_router: true also updates the router during LoRA
training; use the model’s supported recipe and watch the routing metrics. The Qwen3
MoE BnB example shows expert offload and selective dequantization.
For chunked sequences, the Laguna recipe
and Qwen3.6 MoE recipe set
sequence_chunks: 8. The chunk count must divide sequence_len, the batch size must
be one, and LoRA dropout must be zero. Tiled MLP (long_context) is a separate
way to save memory on dense models; see long context.
Continue an adapter, stack an adapter, or resume a run
Section titled “Continue an adapter, stack an adapter, or resume a run”surogate sft examples/sft/qwen3/qwen3-lora-bf16.yamlsurogate sft examples/training/continue-adapter.yamlThe second command imports the first run’s PEFT adapter and starts with a fresh
optimizer. The adapter’s rank, alpha and targets must match. To stack a new adapter,
copy continue-adapter.yaml, set adapter_init_mode: merge, and give it a new
output_dir. That merges the parent into an unquantized base and trains a new
adapter on top; prequantized bases can’t use this merge initialization.
To resume optimizer state and step count, set resume_from_checkpoint: true
in the original config and rerun it with the same output directory and training
budget. It picks up the latest step_XXXXXXXX checkpoint. save_steps sets how
often checkpoints are saved and save_total_limit how many are kept. A run that
already reached its step budget has nothing left to do; raise the budget to extend it.
SFT writes its final adapter straight into output_dir (next to
adapter_config.json); full fine-tuning writes the model there.
merge_adapter: true also writes merged model weights into that directory.
The reverse-text example shows automatic
merging and split prompt/completion message columns. The
serving guide shows an
explicit merge into a separate directory, followed by GGUF quantization.
Data, validation, and monitoring
Section titled “Data, validation, and monitoring”surogate tokenize examples/datasets/mixed.yaml --debugsurogate sft examples/datasets/mixed.yamlsurogate sft examples/training/adaptive.yamlThe dataset example covers local instruction/chat data,
column mapping, dataset mixing and held-out validation. The standard model recipes use
packing and keep the default 10% validation split. Use loss_scale: all for
raw-text next-token training; see pretraining.
Adaptive training writes local metrics to outputs/training/adaptive/metrics.jsonl.
Its max_steps: -1 lets the epoch and token-budget logic choose the step count.
To report to other services, install and configure the integration, then add these
fields to a copy of the config:
report_to: [surogate, wandb, aim]wandb_project: surogate-exampleswandb_name: qwen3-adaptiveaim_experiment: surogate-examplesaim_repo: ./outputs/aimLog in to W&B first and install aim if needed. The built-in JSON training log
and training_plot.png work without either service. To watch local metrics in the
live dashboard:
SUROGATE_METRICS_PATH=./outputs/training/adaptive/metrics.jsonl surogate jackalopeFor timing or memory diagnostics, add debug_time_breakdown: true or
debug_memory_breakdown: true to a copy (see debugging).
For a short smoke run, copy any base config and set max_steps: 3, eval_steps: 0,
save_steps: 0, and a fresh output_dir. To measure what recomputation costs on a
model that fits, compare recompute: true and false; QLoRA forces recomputation on.
Dedicated benchmark and one-step YAML duplicates are kept out of the public example
library.
Next: the config reference lists every option these examples use, and memory helps when a run doesn’t fit.