Repository navigation
feat(rollout): complete managed PD disaggregation - #433
Conversation
Start the managed P2C router with the complete set of ready prefill and decode workers, validate and adopt their registrations, and remove stale worker generations before recovery. Bound owner disposal and unregister operations so startup failures and shutdown release owned resources. Apply prefill bootstrap deadlines before TP/CP status consensus in the SGLang patch. Preserve existing target behavior and add regressions for registration, rollback, recovery, cleanup, and full-history Agentic input. Add an eight-GPU 2P2D TP2 Mini SWE Agent entrypoint and English/Chinese guides, retaining the original non-PD entrypoint unchanged. Validation: 364 framework regressions, 8 backend deadline tests, 6 Mini SWE server tests, full documentation build, and all-file pre-commit checks. Single-node H20 runs cover three-round Mini SWE training for regular, consistent-hashing PD, and P2C PD; controlled P/D process failures cover stale-registration removal, replacement generation, and resource cleanup.
Replace Mini SWE setup, launch, and experiment-specific instructions with workload-independent PD configuration, resource sizing, request flow, routing limits, and troubleshooting. Keep the English and Chinese guides aligned and correct the example README link description to reflect the guide's general scope. Validation: full pre-commit checks, docs build, bilingual example and rendered-link checks, and browser inspection through the dev preview.
Remove duplicate startup rollback parameters, combine agentic request coverage, and parameterize registration timeout retries while preserving distinct failure semantics and session lifecycle assertions. Validation: pre-commit --all-files passes; router registration tests pass (55 cases). PD startup tests skip without Ray/SGLang, and agentic test collection is blocked by missing Ray. Multi-node GPU integration is not run because the local environment lacks the required hardware.
|
Thanks for contributing to Relax, @yuanlehome! 感谢你为 Relax 做出贡献! 📚 Contribution guide / 贡献指南Describe the problem, your changes, and how you validated them. Keep each PR focused and run 请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 🛠️ CI commands / CI 指令
Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access. 在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。 🔎 Merge requirements / 合入条件GitHub:✅ 满足合入条件
|
Nyanpasu 审查看板审查状态: 💬 已完成 · 有补充意见 审查版本: 991ad82 目标分支: main 针对 991ad82(fix(rollout): make failed PD recovery retryable)完成 28 文件增量审查。此前两个 P2 发现经核实解决并在行内线程回复验证证据:恢复路径在替换批次 init 失败时退役整批替换引擎并复位槽位、rank 0 恢复异常经 broadcast_object_list 传给全部 rank 统一失败;启动主链路四个接线缺口(托管启动调用、标志转发、Controller dispose、init 抛错)经删除型突变实验确认已全部被测试检出。增量部分未发现新问题。最终结论 COMMENT:保留一个待作者确认问题(scale_out 对托管 PD 组的代码层保护)与一条拆分建议(4 个与 PD 无关的测试基建重构)。
审查发现待处理
已解决或已取代
提交范围 · 接收 28 · 建议移出 0 · 待确认 0接收 28 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。
精简审查与验证依据
生产代码的必要性与替代方案
测试的必要性与替代方案
Powered by Nyanpasu with glm-5.3-flash max, please check the suggestions carefully.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
🟡 Changes recommended
Router registration can become permanently stuck after HTTP errors, and the published router port is not actually reserved.
2 open findings
What changed in this PR
Completes managed prefill/decode disaggregation, including router lifecycle, worker recovery, shutdown handling, documentation, and an 8-GPU example.
Changes:
- Adds managed static PD router startup, registration, recovery, and rollback.
- Bounds monitor and engine shutdown operations.
- Adds PD tests, documentation, SGLang patching, and Mini SWE Agent configuration.
| File | Description |
|---|---|
relax/distributed/ray/rollout.py |
Implements managed PD router lifecycle and recovery. |
relax/backends/sglang/sglang_engine.py |
Adds static worker adoption and registration handling. |
relax/core/controller.py |
Disposes rollout owners before teardown. |
relax/utils/health_monitor.py |
Adds bounded monitor shutdown. |
tests/distributed/ray/test_pd_router_startup.py |
Tests PD startup, recovery, and cleanup. |
tests/backends/sglang/test_router_registration.py |
Tests PD router registration behavior. |
tests/core/test_pd_disposal.py |
Tests controller disposal ordering and timeouts. |
tests/utils/test_health_monitor.py |
Tests bounded monitor shutdown. |
tests/test_agentic_rollout.py |
Expands routing and history regression coverage. |
docker/patch/sglang/v0.5.17.patch |
Makes bootstrap timeout handling rank-consistent. |
examples/mini_swe_agent/run_mini_swe_agent_pd.sh |
Adds an 8-GPU PD training launcher. |
examples/mini_swe_agent/pd-2p2d-tp2.yaml |
Defines the 2P2D TP2 topology. |
examples/mini_swe_agent/README.md |
Documents the PD example. |
docs/en/guide/pd-disaggregation.md |
Adds the English PD guide. |
docs/zh/guide/pd-disaggregation.md |
Adds the Chinese PD guide. |
docs/.vitepress/config.mts |
Adds both guides to navigation. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Bind the verified first-model router to SessionShards and admission before rollout can start. Wait for every owner within the startup rollback boundary instead of publishing an unbound port during engine initialization. Retry definitively rejected worker registrations while reconciling ambiguous responses, and update the partial-startup cleanup fixture. Exercise installed K3, MXFP4, and Megatron checkpoint hooks directly instead of reapplying or reconstructing deployment patches in tests. Retain patch artifact checks for components outside the default CI image. Validation: 98 targeted tests passed; 5 skipped for missing Megatron/CUDA. Twelve isolated routing and lifecycle checks and all pre-commit hooks passed. Full Ray and multi-GPU validation require the CI environment.
rai-studio-bot
left a comment
There was a problem hiding this comment.
💬 审查完成(COMMENT)
已按当前头部 98cc7e3 完成审查(基准 main,merge-base dce533b)。托管 PD 分离的整体设计方向是成立的:引擎先于 router 启动、校验完整健康注册表后才对外发布、engine 侧绑定避免重复注册、router 清理归属实际持有它的 RolloutManager。两个 P2 问题已行内留言:
- 恢复路径在"必需注册失败"后槽位卡死且不可重试(
relax/backends/sglang/sglang_engine.py); - 托管启动主链路删除后测试仍全绿,接线未被测试锚定(
tests/distributed/ray/test_pd_router_startup.py)。
另有两条非行级事项:
- 非行级:跨文件行为确认 —— 弹性扩容(scale_out)会复用
engine_groups[0]作为模板并经动态注册加入引擎。PR 描述已注明"PD 池暂不支持运行时动态扩容",建议确认 scale_out/scale_in 对托管 PD 组(power_of_two 静态启动)在代码层已禁用或受保护,避免模板组被扩容后经动态注册进入静态启动的 router。 - 非行级:无关改动打包 ——
tests/backends/sglang/source_utils.py、test_kimi_k3_weight_reload.py、test_mxfp4_weight_reload.py、tests/backends/megatron/test_sync_checkpoint_staging.py是与 PD 目标无关的测试基建重构(共享 source-path helper 替代各文件内 isolated patch),已验证本地通过;拆分到独立 PR 会更干净。
发现明细与提交范围准入见审查看板。
| if getattr(self, "_require_router_registration", False) and self.node_rank == 0 and not registered: | ||
| raise RuntimeError("Required PD router registration failed") |
There was a problem hiding this comment.
start_engines 在引擎 init 完成前就把 actor 句柄存入 rollout_engines(relax/distributed/ray/rollout.py:680),而 recover() 只把 engine is None 的槽位视为待重建(relax/distributed/ray/rollout.py:884)。若替换引擎走到这里的必需注册失败(例如 router 短暂不可达导致 60s 就绪等待超时后在此抛出),该槽位会停留在一个"进程健康但未注册"的引擎上,后续 recover() 不会再重试,也不会清理这个半可用 actor。
后果在故障容忍路径被放大:rank 0 调用 recover_rollout_engines 是未包裹的 ray.get(relax/backends/megatron/actor.py:2871),init 异常会直接判死本轮 update_weights,其余 rank 随后卡在 barrier(actor.py:2873)。
建议:recover() 对句柄已存在但 ray.get 探测失败的槽位,先 shutdown/kill 该 actor 并把槽位复位为 None,让下一轮 recover() 重建(与托管 PD "旧注册确认移除后才复用端点" 的既有顺序兼容)。
There was a problem hiding this comment.
已核实 991ad82 从两侧修复,确认解决:
- 恢复侧:
recover()在替换批次 init 失败时对整批替换引擎执行 shutdown(10s 超时后仍 kill)、注销 DCS 与 router 并把槽位复位为None,num_new_engines归零后重抛(relax/distributed/ray/rollout.py:997);下一轮recover()重新走预清理,而remove_dead_router_worker对"注册表零匹配"返回True(幂等),重试可收敛。test_pd_recovery_rolls_back_failed_replacements_and_retries覆盖 shutdown 超时仍 kill、存留引擎不受影响、二次恢复成功且按代清理旧注册。 - 训练侧:
update_weights把 rank 0 的恢复异常经broadcast_object_list(显式process_group)传给全部 rank 后统一抛出Rollout engine recovery failed(relax/backends/megatron/actor.py:2870),原先「rank 0 判死、其余 rank 卡 barrier」的放大路径消除;test_update_weights_shares_rollout_recovery_result_before_weight_sync覆盖成功/失败与双 rank(本机缺 megatron.core 优雅跳过,逻辑经审读核实)。
|
|
||
| publish = Mock(side_effect=RuntimeError("startup failed") if fail_at == "publication" else None) | ||
| monkeypatch.setitem(sys.modules, "relax.agentic.rollout", SimpleNamespace(bind_agentic_router=publish)) | ||
| monkeypatch.setattr(rollout_module, "_start_rollout_servers_impl", start) |
There was a problem hiding this comment.
本文件第 235 行对 _start_rollout_servers_impl 打桩,托管启动主链路没有真实入口覆盖。变更实验(在 98cc7e3 上逐项做删除/改写后跑相关套件):
- 从
_start_rollout_servers_impl删除_start_managed_pd_router调用与端点记录 → 90 passed(基线 121) require_router_registration=defer_router改为False→ 86 passedController.shutdown删除_dispose_rollout_manager()→ 27 passed- 删除引擎 init 的必需注册 raise → 86 passed
即托管启动调用、skip/require_router_registration 标志转发、model 0 端点记录与就绪后 bind_agentic_router 发布这些接线被删除,现有断言仍会通过(#388 的同类问题)。
建议:补一条经真实 _start_rollout_servers_impl(mock 引擎组与 router 启动函数)的用例,断言 defer_router 时托管启动被调用、两个标志随 defer_router 转发、端点写入 args 且发布后才绑定 agentic;另补 Controller.shutdown 触发 dispose、init 注册失败抛 RuntimeError 的断言。
There was a problem hiding this comment.
已核实,确认解决。在 991ad82 上重跑删除型突变实验(此前在 98cc7e3 上同样的突变测试仍全绿):
- 删除
_start_rollout_servers_impl内托管启动调用与端点记录 →test_start_rollout_servers_initializes_models_before_publishing_router[True]失败; require_router_registration=defer_router改为False→ 同一用例失败(skip/require_router_registration断言);Controller.shutdown删除_dispose_rollout_manager()→test_controller_shutdown_disposes_rollout_owner失败;- 删除 init 必需注册 raise →
test_pd_init_requires_successful_router_registration[False]失败。
四个接线缺口(托管启动调用、标志转发、Controller dispose、init 抛错)现在都有真实入口锚定,本发现按已解决处理。
| def hooks(kimi_source): | ||
| ns = {"torch": torch, "ReplicatedLinear": object, "RMSNorm": object} | ||
| _function(ast.parse(_source_path("srt/layers/attn_residual.py").read_text()), "get_cw", ns) | ||
| _function(ast.parse(sglang_source_path("srt/layers/attn_residual.py").read_text()), "get_cw", ns) |
There was a problem hiding this comment.
话说这里用法是不是还是有点畸形?是不是应该有办法直接 import 它?
独立问题,我后面统一看看这些单测吧,感觉之前 Agent 为了过 CI 搞了一堆 hack
Retire replacement engines when initialization fails while preserving their metadata for router cleanup on the next recovery attempt. Broadcast the recovery result across Megatron ranks before entering weight sync. Exercise the real startup, engine initialization, and shutdown entry points with external I/O mocked. Cover required registration flags, publication ordering, partial multi-node recovery cleanup, and all-rank failure handling.
rai-studio-bot
left a comment
There was a problem hiding this comment.
💬 审查完成(COMMENT)
已按当前头部 991ad82 完成增量审查(基准 main,merge-base dce533b)。此前两个 P2 发现均已核实解决并在对应行内线程回复了验证证据:
- 恢复槽位卡死 ——
recover()现在在替换批次 init 失败时退役整批替换引擎(shutdown/注销/kill 并复位槽位)并重抛,下一轮重试;rank 0 的恢复异常经broadcast_object_list传给全部 rank 统一失败,消除 barrier 挂起。 - 启动主链路未被测试锚定 —— 新增经真实
_start_rollout_servers_impl的接线用例与 init 抛错/Controller dispose 用例;在 991ad82 上重跑四个删除型突变均被现有套件检出(此前全部漏检)。
增量部分(recover() 回滚、broadcast_object_list 传播、相应测试)未发现新问题。一个此前提出、尚未回应的问题保留:弹性扩容(scale_out)以 engine_groups[0] 为模板并经动态注册加入引擎,请确认对托管 PD 组(power_of_two 静态启动)在代码层已禁用或受保护(PR 描述已注明"PD 池暂不支持运行时动态扩容");另建议将与 PD 无关的测试基建重构(tests/backends/sglang/source_utils.py 等 4 个文件)拆分独立 PR。
发现明细与提交范围准入见审查看板。
…rence Resolve conflicts with upstream redai-studio#433 (managed PD), redai-studio#437 (native image OPD), redai-studio#439 (rollout utility extraction), redai-studio#361 (multinode scale-out) and the placement factory relocation, porting their intent onto InferenceManager. - Managed static PD: start_servers defers the Router until P/D engines are ready and seeds it with them; replacements still join after weight sync. - Recovery broadcasts rank-0 failures before weight sync; pool monitors stop within one shared 5s budget; Controller bounds shutdown_all to 35s. - Teacher engines get SGLANG_MM_AVOID_RETOKENIZE in config_adapters; the removed RELAX_OPD_PREEXPANDED_PATCH reference is dropped. - Drop RolloutManager/TeacherManager-only code and tests; adapt new upstream tests to EngineGroupSpec/InferenceModelSpec and the inference manager.
…rence Resolve conflicts with upstream redai-studio#433 (managed PD), redai-studio#437 (native image OPD), redai-studio#439 (rollout utility extraction), redai-studio#361 (multinode scale-out) and the placement factory relocation, porting their intent onto InferenceManager. - Managed static PD: start_servers defers the Router until P/D engines are ready and seeds it with them; replacements still join after weight sync. - Recovery broadcasts rank-0 failures before weight sync; pool monitors stop within one shared 5s budget; Controller bounds shutdown_all to 35s. - Teacher engines get SGLANG_MM_AVOID_RETOKENIZE in config_adapters; the removed RELAX_OPD_PREEXPANDED_PATCH reference is dropped. - Drop RolloutManager/TeacherManager-only code and tests; adapt new upstream tests to EngineGroupSpec/InferenceModelSpec and the inference manager.

What
补齐 SGLang Prefill–Decode(PD)分离在 decode 使用
power_of_two时的托管启动、故障恢复和资源清理流程。Router 使用已经就绪的 P/D engines 初始化,注册状态确认后才对后续 rollout 流程发布。Why
托管 PD 启动需要协调 engine 就绪、router 初始化和 worker 注册,避免以空 worker 集启动
power_of_two路由。恢复过程中还需要区分注册响应丢失与连接失败,并在复用端点前确认旧 worker 已移除,避免重复注册或误删其他代的 worker。关闭及全局重启时,router 子进程需要由实际持有它的 RolloutManager 释放;bootstrap 超时也应参与已有 rank 共识,避免各 rank 对同一请求作出不同的出队决定。
How
托管静态启动路径要求原生 SGLang engines、至少 1 个 prefill 和 2 个 decode engines、
dp_size=1,且不启用 DP-aware routing。Decode 使用consistent_hashing时仍走动态 worker 注册路径;PD 池暂不支持运行时动态扩容。Testing
回归用例覆盖静态注册校验、注册重试、身份安全清理、启动回滚、释放超时和顺序,以及 Agentic 请求历史与生命周期字段。合并了重复测试,同时保留不同故障场景的断言。
pre-commit run --all-filespassespytest tests/)Type of Change