Fix(opd): keep teacher weights across sleep/wake in colocate - #287
Open
ZiyiTsang wants to merge 2 commits into
Open
Fix(opd): keep teacher weights across sleep/wake in colocate#287ZiyiTsang wants to merge 2 commits into
ZiyiTsang wants to merge 2 commits into
Conversation
# 🐛 Bug Fix ## Preserve colocate managed teacher weights across memory-saver sleep/wake - Managed OPD/SDPO teacher enables enable_memory_saver in colocate mode but did not enable enable_weights_cpu_backup; every release/resume cycle re-allocates its weight pages uninitialized, so the teacher serves a uniform distribution (all logprobs = -ln(vocab_size)) - Default enable_weights_cpu_backup=True when memory saver is on; explicit --teacher-sglang-enable-weights-cpu-backup still overrides; dedicated-PG teachers are unaffected
Contributor
|
感谢交互
|
# 🐛 Bug Fix ## Default --sglang-enable-weights-cpu-backup on for OPD - Add maybe_enable_sglang_weights_cpu_backup: when --use-opd and offload_rollout resolves True, default the student rollout SGLang engines to enable_weights_cpu_backup so sleep/wake cannot leave weight pages uninitialized (same failure mode as the teacher-side fix) - Call it in slime_validate_args right after offload_rollout is fully resolved, so colocate runs (incl. managed-teacher split bundles) get it automatically while hybrid / debug_rollout_only / non-offloaded dedicated rollout are left untouched; an explicit flag or per-engine --sglang-config override still wins --- # 🔩 Chore ## Drop redundant flags from OPD launch scripts - Remove manually-added --sglang-enable-weights-cpu-backup from the 9 OPD example scripts (vision_opd / mopd / math_opd / agentic webshop+alfworld); the GRPO baseline scripts keep theirs since they do not pass --use-opd --- # ✅ Tests ## Cover maybe_enable_sglang_weights_cpu_backup - Enables when use_opd + offload_rollout - No-op without OPD or without offload - Idempotent when explicitly set
ZiyiTsang
force-pushed
the
fix/opd-teacher-weights-cpu-backup
branch
from
August 27, 2026 15:35
79bce70 to
c859c3b
Compare
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.
问题
本PR为实现PR#237发现并修复的bug。欢迎交流~
colocate 模式下 managed OPD/SDPO teacher 开启了
enable_memory_saver但未开启enable_weights_cpu_backup。teacher 与 actor 共享 GPU,每个训练 step 都经历release_memory_occupation/resume_memory_occupation;无 CPU backup 时 resume重新分配的权重页不恢复内容,teacher 自第一次 wake 起输出均匀分布——所有 token 的
logprob 恒等于
-ln(vocab_size)。蒸馏信号因此完全失效,且方向系统性错误:尖峰 student 对均匀 teacher 的 JSD loss
初始即达理论上界(实测 step-0
train/loss = 0.688 ≈ ln 2),随后把 student 推向均匀分布(entropy_loss 0.41 → 3.56),表现为多语言乱码、EOS 概率消失、回复全部
截断、eval accuracy 崩到 0、loss 伪收敛到 1e-4 量级。
触发条件
同时满足以下四项即触发(对应 Relax-managed teacher 的 colocate 形态):
--use-opd --opd-type=sglang,且 teacher 走 Relax 托管路径:设置了--teacher-hf-checkpoint(单 teacher)或--opd-teacher-routes(MOPD),并且
--resource含teacher条目;--colocate(非--hybrid),且--resource同时含actor与rollout——即
is_managed_opd_teacher_colocate为真,teacher 与 actor 共享 placement group;--offload-rollout(colocate 默认开启)使teacher 与 actor 锁步 offload/onload,每个 step 经历
release_memory_occupation→resume_memory_occupation。此时build_teacher_overrides(colocate_sync=True)把enable_memory_saver置 True;--teacher-sglang-enable-weights-cpu-backup(sglang 默认关闭)。不触发的形态:独立 PG 的 teacher(
enable_memory_saver=False)、外部--opd-teacher-url自建 teacher(不经build_teacher_overrides)、非 OPD 训练。命中时所有 colocate OPD/OPSD/SDPO 配置在第一个训练步后 teacher 即失效,
蒸馏信号系统性错误且无任何报错。
修复
setdefault:显式--teacher-sglang-enable-weights-cpu-backup仍可覆盖enable_memory_saver为 False,guard 不触发)build_teacher_overrides唯一调用方是relax/distributed/ray/teacher_manager.py的TeacherManager,仅 OPD/OPSD/SDPO 路径创建release/resume 各一次拷贝
sglang_engine.py)已使用同一 flag,本 PR 把 managed teacher 对齐验证
确定性复现(Qwen3-0.6B +
--enable-memory-saver,同 venv sglang 0.5.12.post1):一次 release→resume 后全部 logprob =
-11.9312 = -ln(151936);开启enable_weights_cpu_backup后 3 个 sleep/wake 循环 logprob 逐位不变(max|Δ|=0)。真实训练(SciKnowEval Biology, Qwen3-8B, 4×H100 colocate)前后对比(wandb):
sdpo-sciknoweval-biology-2026-08-20-02:59:55sdpo-sciknoweval-biology-2026-08-21-06:45:37修复前 step-0
train/loss = 0.688 ≈ ln 2即 JSD 理论上界,说明 student 与(均匀化)teacher 分布几乎不相交;随后 loss 单调降到 1e-4 是 student 被均匀化的
伪收敛。修复后 loss 一开始就落在 ~0.03 以下(真实 hint-only JSD 量级),eval
accuracy 从 0.35 一路升到 0.51,rollout accuracy 最高 0.77,全程无崩塌。