Skip to main content

What this is

The cookbook’s training.recipes.distillation_loop trains one student from its own rollouts while frozen teacher deployments score those same responses. Use it when you want recipe-managed trainer provisioning, student sampling, teacher scoring, checkpointing, and cleanup for distillation experiments.

Modes

sampled_reverse_kl is the default. The student samples on policy, the teacher scores the sampled tokens, and the recipe trains on the dense per-token gap:
For topk_forward_kl, set distill_mode=DistillMode.TOPK_FORWARD_KL and sdft_top_k.

Current limits and logprobs

The distillation recipe depends on the public inference logprobs response: top_k and top_logprobs are different knobs: top_k changes sampling; top_logprobs only controls how many alternatives are returned in the response.

Minimal example

If teacher_model is a base model resource, the recipe creates a frozen teacher deployment for scoring. If it is already an inference model or deployment resource, the recipe uses it directly.

Multi-teacher runs

Set multi_teacher=MultiTeacherConfig(...) when you have more than one teacher. With sampled_reverse_kl, multi-teacher OPD is routed: each dataset row is scored by exactly one teacher selected by the configured route key, defaulting to teacher. With topk_forward_kl, every configured teacher can score the sampled response and the recipe blends sparse top-K probability mass using TeacherConfig.blend_weight.

Dataset contract

Rows are JSONL objects. The only required field is messages, the student-visible OpenAI-style chat prompt. Optional fields: Student and teacher token IDs must use a compatible tokenizer and vocabulary. Prefer teachers from the same model family, and set TeacherConfig.tokenizer_model when you want the recipe to validate teacher tokenizers against DeployConfig.tokenizer_model.

Examples

The cookbook includes distillation examples under training/examples/distillation: Run from the cookbook repository:

Next steps