Distillation2026

SDFT

Self-Distillation Enables Continual Learning Idan Shenfeld, Mehul Damani, Jonas Hübotter, and Pulkit Agrawal arXiv

SDFT helps a model learn to answer on its own by using a version of itself that sees a worked example as its teacher.

Why it mattered

A worked example can help a model solve a task while it is in the prompt. SDFT turns that temporary advantage into training feedback. The student tries the task unaided, and a teacher version of the model reads the demonstration before scoring each step of the attempt.

Core insight

At each prefix of the student’s answer, compare what the student would write next with what its better-informed teacher would write. The paper usually updates the teacher with an exponential moving average of the student’s weights. Its experiments favored forward KL.

The SDK’s SelfDistiller can use the trainer’s initial weights as a fixed teacher. The example below uses that variant with reverse KL and supplies a reference answer only when the teacher scores the student.

When to use

Use SDFT when you have demonstrations, the model already improves with an example in its prompt, and you want it to perform the skill unaided.

Step-by-step walkthrough

  1. 01

    Pair each prompt with its demonstration

    Use single-turn conversations from No Robots. Keep the assistant’s reference response for the teacher and send only the user’s request to the student.

    rows = load_dataset("HuggingFaceH4/no_robots", split="train[:128]")
  2. 02

    Give the teacher the reference answer

    SelfDistiller looks up the reference for each prompt when it scores the student’s answer. The teacher uses the trainer’s initial weights throughout this example.

    distiller = SelfDistiller(trainer, hint_fn=hints.__getitem__, teacher_weights="initial", mode="reverse_kl")
  3. 03

    Train on the student’s attempts

    Sample a fresh answer to each prompt. The reverse-KL update reinforces tokens that the teacher found more likely and downweights tokens that surprised it.

    result = distiller.step(batch, sample={"max_tokens": 256}, optim=optimizer)
  4. 04

    Export the student

    Save the trained model and evaluate it on held-out prompts without demonstrations. Compare with its starting performance on both the new skill and the tasks you want to retain.

    print(trainer.export(name="sdft-continual").result().ref)

Implementation

train.py
from datasets import load_dataset
from grad import Grad, SelfDistiller, optim

rows = load_dataset("HuggingFaceH4/no_robots", split="train[:128]")
hints = {}
for row in rows:
    messages = row["messages"]
    if [m["role"] for m in messages] == ["user", "assistant"]:
        hints[messages[0]["content"]] = "Reference answer: " + messages[1]["content"]
prompts = list(hints)

client = Grad()
with client.trainers.create(
    model="qwen/qwen3-8b", name="sdft-continual", max_cost_usd=5.0
) as trainer:
    trainer.wait_ready()
    distiller = SelfDistiller(
        trainer, hint_fn=hints.__getitem__, teacher_weights="initial", mode="reverse_kl"
    )
    optimizer = optim.AdamW(lr="auto", objective="distill")
    for start in range(0, len(prompts), 8):
        batch = prompts[start : start + 8]
        result = distiller.step(batch, sample={"max_tokens": 256}, optim=optimizer)
        print(result.optim_step.step, result.metrics["distill_kl_reverse"])

    print(trainer.export(name="sdft-continual").result().ref)

Benchmarks

Reported results from the original paper compared against its baseline.

Strict accuracyKnowledge acquisition · Qwen2.5-7B-Instruct · Table 1
+9 pts
SFT80%
SDFT89%
Accuracy on out-of-distribution questionsKnowledge acquisition · Qwen2.5-7B-Instruct · Table 1
+18 pts
SFT80%
SDFT98%

Models & datasets

ModelDurationEst. cost
Qwen3 8Bqwen/qwen3-8b
Depends on response length$5 run cap
DatasetSourceSize
No RobotsHugging FaceSingle-turn demonstrations from 128 training records

Practical gotchas

  • Check that seeing a demonstration actually improves the starting model on your task. A teacher that ignores the example gives the student little extra supervision.
  • Keep the demonstration out of the student’s prompt during both training and evaluation.
  • Track performance on earlier tasks as well as the new one. The retention gains in the paper depended on the model and task.

grad primitives