Offline knowledge distillation
EngineSurogate EngineDistillation trains a small student model to match a larger teacher’s output
distributions. qwen3-kd.yaml captures the top-64 Qwen3-1.7B teacher
distributions and trains a Qwen3-0.6B LoRA student against
ce_weight * CE + kd_weight * tau² * KL. Teacher and student share a tokenizer.
Run from the repository root:
surogate distill-capture examples/distillation/qwen3-kd.yamlsurogate sft examples/distillation/qwen3-kd.yamlCapture tokenizes the data and writes .kd sidecars next to the token shards in
outputs/distillation/qwen3-kd, and training reads the same shards. Keep the
tokenizer, packing, sequence length and data unchanged between capture and training,
and capture again when any of them changes. The teacher is loaded only during capture.
ce_weight defaults to 1 - kd_weight; set kd_weight: 1.0 and ce_weight: 0.0
for pure KL supervision.
Remote teacher
Section titled “Remote teacher”To score with a served teacher, serve prompt logprobs from a separate vLLM environment, then run capture from the Surogate environment. Native Surogate serving doesn’t implement this scoring API.
vllm serve Qwen/Qwen3-1.7B --max-logprobs 64surogate distill-capture examples/distillation/qwen3-kd.yaml --api-base http://localhost:8000/v1surogate sft examples/distillation/qwen3-kd.yamlSet distillation.teacher_model to the served model name. To keep the remote settings
in a copy of the config, add them inside the existing distillation block:
teacher_api_base: http://localhost:8000/v1teacher_api_key_var: VLLM_API_KEYteacher_api_concurrency: 8teacher_api_timeout: 1200The server must return at least top_k prompt candidates. Export VLLM_API_KEY if
the server needs it. This API is separate from the on-policy teacher endpoint.
Different tokenizers
Section titled “Different tokenizers”When teacher and student use different tokenizers, install the optional mergekit
dependency in a suitable environment, then transplant the teacher vocabulary onto the
student:
surogate transplant-tokenizer --student Qwen/Qwen3-0.6B --teacher meta-llama/Llama-3.2-1B \ --output ./outputs/distillation/transplantedThis teacher needs Hugging Face access. Copy qwen3-kd.yaml, set
model: ./outputs/distillation/transplanted, set
distillation.teacher_model: meta-llama/Llama-3.2-1B, and choose a new output directory
such as ./outputs/distillation/cross-tokenizer. Run capture and SFT on that copy.
Merge the trained adapter before you restore the original tokenizer:
surogate merge --base-model ./outputs/distillation/transplanted \ --checkpoint-dir ./outputs/distillation/cross-tokenizer \ --output ./outputs/distillation/cross-tokenizer-mergedsurogate transplant-tokenizer --restore ./outputs/distillation/transplanted/transplant_manifest.json \ --student ./outputs/distillation/cross-tokenizer-merged --output ./outputs/distillation/restoredFollow with a short healing SFT on the restored model, with freshly tokenized data.
Next: the distillation guide covers the constraints, how to read the temperature, and how the transplant behaves.