Skip to content

feat(opd): [Task.39] EOPD cross-architecture distillation (arXiv:2603.07079) - #274

Open
buaacoder wants to merge 6 commits into
redai-studio:mainfrom
buaacoder:feat/eopd-loss
Open

feat(opd): [Task.39] EOPD cross-architecture distillation (arXiv:2603.07079)#274
buaacoder wants to merge 6 commits into
redai-studio:mainfrom
buaacoder:feat/eopd-loss

Conversation

@buaacoder

Copy link
Copy Markdown

Summary

Implement Entropy-aware On-Policy Distillation (EOPD) from arXiv:2603.07079 for cross-architecture teacher→student setups in Relax.

  • Entropy-gated FKL loss: Scale forward KL per-token loss by teacher entropy (high-entropy tokens get higher weight), via --opd-teacher-advantage flag
  • SGLang entropy patch: Monkey-patch LogitsProcessor to compute and return per-token entropy during teacher prefill
  • Batch student prefill: Colocate-mode batch student prefill for OPD rollout efficiency
  • EOS token replacement: --opd-eos-replace replaces student EOS tokens with teacher-generated continuations before teacher prefill
  • Teacher advantage modes: loss (multiply FKL by entropy mask) and additive (add entropy-weighted FKL to pg loss)

Experiment Results (Qwen3-8B → Qwen3-0.6B-Base, MATH-500 mean@8)

Method Relax Best (30ep) Paper (3ep, lr=3e-6 cosine)
EOPD 52.75% (ep25) 52.02%
OPD 54.07% (ep27) 50.09%
GRPO 56.47% (ep26) 51.83%

Note: Our experiments use lr=1e-6 constant schedule (paper uses 3e-6 cosine), so absolute numbers and method ordering differ. See Issue #244 for detailed analysis.

Changed Files

  • relax/backends/megatron/loss.py — EOPD FKL loss scaling with teacher_advantage
  • relax/backends/sglang/sglang_engine.py — Entropy patch integration in scheduler subprocess
  • relax/core/controller.py — OPD colocate GPU allocation
  • relax/engine/rollout/on_policy_distillation.py — Teacher entropy/EOS replace/teacher_log_probs handling
  • relax/engine/rollout/sglang_rollout.py — Batch student prefill for colocate OPD
  • relax/utils/opd/opd_main_worker.py — Legacy topk parsing, entropy_from_topk
  • relax/utils/opd/opd_sglang_entropy_patch.py — SGLang LogitsProcessor entropy monkey-patch
  • relax/utils/opd/opd_utils.py — Teacher advantage computation, EOS replace, validation
  • relax/utils/utils.py — OPD colocate dp_size computation

Tests

  • tests/engine/rollout/test_on_policy_distillation_eos_replace.py — EOS replacement unit tests
  • tests/integration/test_eopd_smoke.py — End-to-end EOPD FKL loss + gradient smoke test
  • tests/utils/test_eopd_reference_parity.py — Element-wise parity vs reference FKL formulas
  • tests/utils/test_opd_teacher_advantage.py — Teacher advantage computation tests

Related

🤖 Generated with Claude Code

buaacoder and others added 3 commits August 14, 2026 12:36
Implement EOPD from arXiv:2603.07079 — entropy-gated forward KL loss
that supplements standard OPD reverse KL at high-entropy teacher tokens.

Key changes:
- Add `--use-eopd`, `--eopd-entropy-threshold`, `--eopd-fkl-coef` CLI args
- Implement `compute_eopd_fkl_loss()` with entropy mask gating
- Plumb `teacher_entropy` through megatron forward and transfer pipeline
- Fix megatron OPD path: compute teacher top-K log-probs during rollout,
  map `teacher_topk_*` → `opd_topk_*` in actor, add megatron batch keys
- Add 10 unit tests (loss function + argument validation)
- Add smoke test script

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Enable EOPD (entropy-gated forward KL) for --opd-type=sglang by computing
per-token teacher entropy server-side and wiring it through the OPD data
pipeline. This allows cross-architecture distillation (e.g. Qwen3-8B →
Qwen3-0.6B) where the teacher has genuine high-entropy tokens.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…y-gated FKL loss

Implement Entropy-aware On-Policy Distillation (EOPD) from arXiv:2603.07079
for cross-architecture teacher-student setups (e.g. Qwen3-8B → Qwen3-0.6B-Base).

Key changes:
- Add entropy-gated forward KL loss scaling via teacher_advantage in Megatron loss
- Add SGLang entropy monkey-patch for teacher prefill entropy extraction
- Add batch student prefill for colocate OPD rollout
- Add EOS token replacement (--opd-eos-replace) for teacher prefill alignment
- Add teacher advantage computation (--opd-teacher-advantage) with loss/additive modes
- Add OPD colocate GPU allocation in controller and utils

Tested with Qwen3-8B teacher → Qwen3-0.6B-Base student on MATH-500.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
buaacoder and others added 3 commits August 14, 2026 13:24
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_eopd_requires_loss_mode: test both-nonzero case (invalid) instead
  of advantage-mode case (valid)
- test_eopd_loss.py: apply ruff formatting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@buaacoder buaacoder changed the title feat(opd): EOPD cross-architecture distillation (arXiv:2603.07079) feat(opd): [Task.39] EOPD cross-architecture distillation (arXiv:2603.07079) Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【Task.39】EOPD 论文复现进展:Qwen3-8B→0.6B 跨架构在线蒸馏

1 participant