feat(sc): add the teacher top-k forward for distillation on SingleController - #3843
feat(sc): add the teacher top-k forward for distillation on SingleController#3843tianyi-zhang-02 wants to merge 1 commit into
Conversation
e29ded9 to
36323f5
Compare
…troller
Distillation is the last algorithm with a rollout loop that SingleController
cannot run. Its teacher is a Policy, not a separate model class, so the
SingleController side needs no new driver -- only the missing top-k
entrypoint on the two layers every other forward already has:
- TQWorkerMixin.get_topk_logits_presharded: per-rank fetch -> forward ->
write-back. Unlike its siblings it writes back two tensors, and both
carry a third axis ([B, S, k]); the write-back validates only the batch
dimension, so that axis passes through unchanged.
- TQPolicy.get_topk_logits_from_meta: the 1-hop dispatch, reusing
LP_SEED_FIELDS because a teacher forward needs exactly what a logprob
forward needs.
Nothing calls these yet -- wiring the teacher into the train pump is a
follow-up. Splitting it out keeps this piece independently testable.
Signed-off-by: Tianyi Zhang <zhangtianyi975@gmail.com>
Signed-off-by: Tianyi Zhang <123608656+tianyi-zhang-02@users.noreply.github.com>
36323f5 to
7444636
Compare
|
#3768 landed while this was open, so worth saying up front how the two relate — they both put a teacher on SingleController and they are not the same thing. #3768 (MOPD): several teachers, each on its own reserved nodes ( This stack: one frozen teacher, sharing the training GPUs as a second worker group and offloaded between forwards. Its top-k logits feed So: different signal, different resource model, different objective. Both entrypoints now sit next to each other in Rebased onto #3768. One real fix fell out of it: its new validation reads The one thing I would like a steer on: #3768 established |
|
Duplicate flag, found while sweeping the open PRs. @pthombre's #2580 ("feat(distillation): add TransferQueue support for On-Policy Distillation") already adds That PR is much larger (it also adds the write-back dispatcher, payload sizing and transport metrics), has been open since 2026-05-27, last touched 2026-06-26, and is CONFLICTING against I've asked there whether it's being picked back up. If it is, I'll close this — no reason to have two. Flagging it here so a reviewer doesn't find the collision cold. |
What does this PR do ?
Adds the teacher top-k forward to the SingleController data path, so distillation can eventually run there. Nothing calls it yet.
Issues
Groundwork toward distillation on SingleController. No issue to close.
Usage
Before your PR is "Ready for review"
Pre checks:
Docs unchanged on purpose. There is no user-facing knob yet.
Additional Information
After #3773, distillation is the last algorithm with a rollout loop that SingleController can't run.
It turns out to need very little. The distillation teacher is a
Policy, not a separate model class like the PPO critic, so there's no new driver to write —TQPolicyalready is the teacher. All that was missing is the top-k entrypoint on the two layers every other forward already has:TQWorkerMixin.get_topk_logits_presharded— per-rank fetch → forward → write-back.TQPolicy.get_topk_logits_from_meta— the 1-hop dispatch. It reusesLP_SEED_FIELDS, since a teacher forward needs exactly what a logprob forward needs: the student's tokens and their masks. The teacher only adds its own scoring of them.One thing is different from the sibling entrypoints.
get_topk_logitsreturns two tensors, not one, and both are[B, S, k]. Every other*_preshardedmethod writes back a single[B, S]._write_back_result_fieldonly validates the batch dimension, so the extra axis passes through fine — butlm_policy.pyalready carries a comment aboutfrom_batchesflattening[B,S,k]into[B,S*k], so that axis clearly has a history of getting lost. There's a test pinning it.I split this out from the wiring so it's testable on its own. The follow-up adds the teacher stage to the train pump and the config validation.
Tests:
tests/unit/models/policy/test_tq_teacher_topk.py, same shape astest_tq_value.py— both columns written, the k axis survives, non-leader twins stay quiet, batch-dim mismatch raises. I mutation-tested them: dropping the indices write-back and pointing both writes at the same field each fail.Not colliding with #3584 / #3608 — those are on the
teacher_worker_grouppath and don't touch these files. :)