feat: TOP-D algorithm (trust region policy distillation)#2966
Draft
hallerite wants to merge 1 commit into
Draft
Conversation
Implements Trust Region Policy Distillation (arXiv:2607.04751) as a new algorithm type "topd": on-policy distillation through a proximal teacher. The teacher prefill-scores each sample at arrival (opd's path), then group finalization compiles the bounded per-token reward log(alpha*rho + 1-alpha) into token-level advantages (length-normalized future return, group z-normalization) consumed by the standard rl loss — whose importance ratio and trust region provide the paper's internal trust region iterations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Trust Region Policy Distillation (TOP-D, arXiv:2607.04751) as a new algorithm type
topd.What the paper does
Standard OPD's per-token reward is the log-ratio
log(π_teacher/π_student)on student-sampled tokens — unbounded below, so a token the teacher rejects sends the reward to −∞ and destabilizes training (worst when the capacity gap is large). TOP-D distills toward a proximal teacher, the probability-space interpolationα·π_teacher + (1−α)·π_student, which never needs materializing: the reward reduces algebraically tor̃ = log(α·ρ + 1−α), floored atlog(1−α). Credit is token-level: return = immediate reward + mean of future rewards (length-normalized, Eq. 8), z-normalized across the group's tokens, optimized with an importance-ratio trust region against the behavior policy.How it maps onto prime-rl
The paper's "internal trust region iterations" already exist here — the
rlloss is importance-ratio corrected against sampling logprobs with trust-region masking, and async training decouples behavior from target. So unlikeopd(teacher logprobs shipped to the trainer for theref_klloss),topdcompiles entirely orchestrator-side into an ordinary per-token advantage stream:score_rollout— own-context prefill under the frozenteacher(identical to opd's path)score_group— bounded rewards vialogaddexp(overflow-safe) → length-normalized future returns per sample → token-level group z-normalization → per-token advantage stream;ref_logprobsare consumed and cleared, never shippedaction_loss_type = "rl"— advantage-based filters apply (a zero-spread group degrades to all-zero advantages, like a uniform GRPO group)Changes
src/prime_rl/orchestrator/algo/topd.py—TOPDAlgorithm(new)packages/prime-rl-configs/.../algorithm.py—TOPDAlgoConfigin the discriminated unionalgo/__init__.py— registry + exportsdocs/algorithms.md,skills/configs/SKILL.md— kept in synctests/unit/orchestrator/test_algorithms.py— vetted-defaults row, frozen-teacher validation generalized to opd/topd, and a numeric test asserting hand-computed advantages for a two-rollout groupTesting
uv run pytest tests/unit/orchestrator/test_algorithms.py— 28 passed. Not yet smoke-tested against a live teacher endpoint; the teacher I/O path is line-for-line opd's existing path.🤖 Generated with Claude Code