Support router-based multi-teacher (MOPD) distillation in DistillationTrainer
Feature request
DistillationTrainer currently supports teacher-student distillation with a single teacher. A useful extension would be router-based multi-teacher distillation, where each example is routed to one teacher based on a dataset column such as domain, task, or data_source.
This would support workflows where a single student is trained from multiple specialist teachers, for example:
- math examples -> math teacher
- code examples -> code teacher
- general instruction examples -> general teacher
A possible API could be:
DistillationConfig(
lmbda=1.0,
beta=1.0,
teacher_model_names_or_paths={
"math": "path-or-hub-id-to-math-teacher",
"code": "path-or-hub-id-to-code-teacher",
"general": "path-or-hub-id-to-general-teacher",
},
teacher_routing_column="domain",
)
Dataset example:
{
"messages": [...],
"domain": "math",
}
Initial scope could be limited to:
one example -> one route key -> one teacher
This would not require teacher aggregation, dynamic routing, teacher debate, or teacher updates. The main addition would be selecting the appropriate teacher per example before applying the existing distillation loss.
Relevant references:
- On-Policy Distillation: https://thinkingmachines.ai/blog/on-policy-distillation/
- MiMo-V2-Flash technical report, which introduces Multi-Teacher On-Policy Distillation: https://arxiv.org/abs/2601.02780
Motivation
This would make DistillationTrainer more useful for mixed-domain post-training setups where different teacher models are strong in different domains.
Today, users can distill from a single teacher, but if they have separate specialist teachers for math, code, reasoning, safety, or general instruction, there does not seem to be a simple way to route each example to the appropriate teacher within the same training run.
Router-based multi-teacher distillation would allow users to train one deployable student model from multiple specialist teachers while keeping the first version simple and close to the existing DistillationTrainer flow.
Your contribution
I would like to work on this and submit a PR if the maintainers are open to the feature.
I can start with a small scoped implementation that extends DistillationTrainer rather than adding a new trainer, preserves the existing single-teacher behavior, and adds routing from a dataset column to one configured teacher per example.
Hey @mohanpb, thanks for the thoughtful, well-scoped proposal — MOPD is a neat direction.
One thing to flag: DistillationTrainer lives under trl.experimental.distillation and is still maturing, and its teacher path assumes a single self.teacher_model throughout — deepspeed/accelerate prep, the optional vLLM teacher-server path, the student/teacher tokenizer-match guard, and a one-teacher-per-batch loss (see https://github.com/huggingface/trl/blob/ab99f1b045edeaf4770d1639433b7b7ff92ac1c3/trl/experimental/distillation/distillation_trainer.py#L471-L557). So router-based routing is more than the two config fields: it means loading N teachers (GPU memory), sub-batching the loss per route, N tokenizer checks / N teacher servers, and a new routing-column dataset contract we'd have to support long-term.
Since the paradigm is very new (MiMo-V2-Flash, Jan 2026) and this is the first request we've seen for it, we'd like to gauge demand before committing it to the trainer. If others want this, please :+1: here. Once validated, a small draft PR that keeps the current single-teacher default and adds opt-in routing behind it would be very welcome as a concrete starting point.
Thanks for the detailed context. That makes sense.
I agree this is more involved than just adding config fields, especially around teacher preparation, tokenizer validation, sub-batching by route, and the teacher server path.
For a first draft PR, I can keep the scope narrow and fully opt-in:
- preserve the current single-teacher path as the default
- support only router-based one-example-to-one-teacher behavior
- start with local teachers first if that is preferable
- add explicit validation for missing route keys / missing routing column
- avoid teacher aggregation, dynamic routing, teacher debate, or changes to the loss itself
I will keep an eye on demand here, and in parallel I can read through the current DistillationTrainer path to think through a minimal design that does not disturb existing behavior.
Hey! I wanted to mention that I have already been working on multi-teacher distillation for my thesis and have a working experimental implementation with unit and smoke-test coverage.
To be clear, it is implemented as a separate self-contained trainer under trl.experimental.multi_teacher_gkd, rather than as an extension of the existing DistillationTrainer. It currently assumes homogeneous teachers using the same tokenizer and token space as the student. Teachers are loaded locally and prepared individually with Accelerate/DeepSpeed; it does not yet support heterogeneous tokenizers, vLLM teacher servers, or route-based sub-batching.
The prototype supports domain routing through dataset metadata, as well as uniform, static-weighted, confidence-weighted, min_ce, and avg_ce aggregation. I have kept the work separated into branches so that a draft PR can be scoped specifically to domain routing rather than including all the thesis experiments.
My thesis deadline is October 7, after which I planned to clean up the implementation and open a draft PR. However, I could open a smaller draft earlier if that would help establish the implementation and get feedback on whether a separate experimental trainer is an acceptable direction.
@albertvillanova, would this be useful as a concrete starting point? @mohanpb, I’m also happy to coordinate so that we avoid duplicating work and can align the implementations.
Hi @diogomsmiranda, I'm currently working on the MOPD implementation following the move of DistillationTrainer from trl.experimental to trl.trainers.
I'm working on a PR (https://github.com/huggingface/trl/pull/7215) (currently a draft) with the feature, and I'd love you to take a look to see if there's something you've used for your thesis that's missing.
Hey @cmpatino I'll definitely take a look! I'll write my comments on the PR discussion then.
PS: I thought we were waiting on @albertvillanova's confirmation before working on the PR, did I miss something?
Great! Thank you.
About the wait, we recently upgraded the trainer from experimental to stable and have noticed an increase in MOPD in recent model releases. That's why we want to work on including this functionality in the trainer.