Skip to content

feat(sglang): upgrade to 0.5.21 and support PD+R3 - #495

Merged
yuanlehome merged 4 commits into
redai-studio:mainfrom
yuanlehome:upgrade/sglang-0.5.21-rework
Oct 28, 2026
Merged

yuanlehome merged 4 commits into
redai-studio:mainfrom
yuanlehome:upgrade/sglang-0.5.21-rework

Conversation

@yuanlehome

@yuanlehome yuanlehome commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

  • CUDA 13 配方升级到官方 SGLang 0.5.21,迁移完整 Relax patch;CUDA 12 保持 0.5.17。
  • 补齐 PD + R3:prefill 路由采集、decode 合并、CPU HiCache/retraction、多轮 Session 和 router 兼容性。

Why

基于上游 0.5.20 重新迁移,保留 OPD、Qwen/Kimi、权重热更新能力,并参考 Miles 补齐 PD+R3。替代 #459。

How

  • 固定源码版本、重建 Rust tree core,适配权重更新与 Blackwell 注意力;P 端真实路由覆盖 D 端占位前缀,保留已接受 token 的路由。
  • 审查修复:按各引擎最终拓扑选择 multimodal transport,仅单节点默认 CUDA IPC,保留显式配置;deterministic BF16 reduce-scatter 使用 FP32 累加,保留输出 dtype/buffer。
  • 单测整理:删除冗余参数组合,按权重更新、路由、引擎参数及 patch 兼容性归并,净减少 5 个文件;合并未丢失保留用例。

Testing

  • pre-commit run --all-files passes
  • Tests pass (pytest tests/) — 未跑全仓库,专项结果见下。
  • New tests added (if applicable)
  • Documentation updated (if applicable)

最新验证对应 6cd6c9c:SGLang 0.5.21 / PyTorch 2.13.0+cu130 / CUDA 13.0 / Blackwell SM103(compute capability 10.3)。

  • 合并后 CPU 回归 343 passed / 7 skipped;这 7 项已在 GPU 上全部通过,相关代码未变,沿用结果;合计覆盖 350 项,无剩余跳过。
  • GPU 覆盖 NCCL/CUDA Graph、BF16 reduction、Qwen 权重重载、进程组重载,以及 FA2/FA4 前反向和 CP 后端选择。
  • 完整 patch 干净应用到官方 0.5.21,89 个受影响 Python 文件编译通过。

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • CI/CD or build changes

Screenshots / Logs

升级阶段单机 8 GPU、各 5 轮端到端结果;本次审查修复后未重跑:

场景 样本数 平均训推 diff 平均 assistant 输出 tokens raw_reward
Qwen3.5 regular + R3 1280 0.0086975 1564.1305 0.315625
Qwen3.5 PD + R3 1280 0.0087124 1562.5563 0.3140625
Mini-SWE PD + R3 + CPU HiCache 80 0.0090159 7910.7 0.3375

Qwen 对照使用 router 后续修正前的成功请求路径;Mini-SWE 最后一轮验证最新 router。验收看上述指标,不要求 logprob 严格一致。使用隔离运行时,未重建完整 Docker 镜像,未覆盖多节点及其他 GPU 架构。

@yuanlehome
yuanlehome requested a review from a team October 27, 2026 13:25
Copilot AI balanced review requested due to automatic review settings October 27, 2026 13:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@rai-studio-bot

rai-studio-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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 pre-commit run --all-files before submitting.

请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 pre-commit run --all-files。

English contribution guide · 中文贡献指南

🛠️ CI commands / CI 指令
Command / 指令 Usage / 用途
/rerun Retry failed CI / 重跑失败的 CI
/rerun <target> Rerun a workflow or check / 重跑指定 workflow 或检查
/cancel <workflow> Cancel an entire workflow / 取消整个 workflow
/help Show commands and targets / 查看指令和 target
/review Request a code review / 请求代码 review

Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access.

在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。

CI usage and targets · CI 用法与 target

🔎 Merge requirements / 合入条件

GitHub:⏳ 合入条件未满足

Requirement / 条件 Status / 状态
审批人数 ⏳ 0/1 · 至少 1 位有仓库 write 或更高权限的人 Approve
团队审批(relax-block-reviewers) ⏳ 0/1 · 可联系:Aurelius84, Yangruipis, SigureMo, NINGBENZHE
CI ✅ 已通过

yuanlehome

This comment was marked as outdated.

@rai-studio-bot

rai-studio-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: 41e67c5

目标分支: main

已完成41e67c5在新main基线上的复查,未发现新增可行动问题。37文件中36个内容未变,PR增删代码与已审版本仅一条Docker注释不同;补查了镜像依赖/manifest、TE/Kimi补丁、ABI及GDN FP32衔接。结论基于源码与依赖契约,本轮未执行测试、镜像构建或GPU/PD/多节点验收。

审查阶段进度范围与结果
常规审查 ✅ 已完成 37文件全部接收;最终delta、基线交集、环境/参数及GDN FP32流到native loader已核对,未变范围复用5eb固定证据。
深度审查 ✅ 已完成 已专项核对新main的依赖约束、补丁后manifest生成/消费、TE与独立FA4、固定Bridge的Kimi packed接口及Rust ABI守卫;未发现可支持的新组合缺陷。未执行完整补丁重放、镜像构建或实际硬件验收。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 High severity 按有效引擎拓扑选择 transport 默认值,避免跨节点启动失败 ✅ 已解决 —
F2 Medium severity 确定性 reduce_scatterv 分支遗漏 BF16 的 FP32 累加 ✅ 已解决 —
F3 Medium severity 新增图像测试调用 SGLang0.5.17 不存在的 processor API ✅ 已解决 —
F4 High severity 共享 router 强制要求 P 路由,但保留的 0.5.17 未补齐返回 ✅ 已解决 共享 router 与 SGLang0.5.17 的配套使用约定
F5 Medium severity 新增 transport/确定性归约测试依赖 0.5.17 不具备的接口 ✅ 已解决 —

改进建议(非阻塞)

拆分

💡 1 个拆分方案

固定37文件/10937行仍建议四层,仅B依赖A;完整6779行.21版本补丁留在A,避免拆散迁移。main已含的Energon/MSC、Qwen算子/兼容性记录和checkpoint修复不计为本PR增量。此建议非阻塞。

箭头表示前置部分 → 后续部分;目标分支为 main。

flowchart LR
    target["目标分支"]
A["PR A"]
target --> A
B["PR B"]
A --> B
C["PR C"]
target --> C
D["PR D"]
target --> D
Loading
部分PR 主题内容与范围验证
A SGLang .21 运行时迁移与构建 保留完整 v0.5.21.patch 及内嵌测试,纳入 tree-core 构建/ABI 安装、两个 Dockerfile 除 C/D 接线外的增量(含 NIXL/OpenTelemetry)、三个校验脚本、blackwell-runtime.md、routing_replay_patch.py 与 sglang_engine.py 的 transport 默认值。其余清单测试增量均随 A,含 KimiK3 热更新、MoE/Qwen/OPD、capture/migration、进程组和组件 fixture 清理;混合文件 test_sglang_engine.py 只带 argparse/transport 用例,test_disaggregation_timeout_consensus.py 先带两个 .21 timeout/PP 共识用例及所需 helpers,排除 B/C/D 所列测试。 按固定e00930c核验完整.21补丁、Rust/Torch/Python ABI和CUDA12/13镜像,覆盖迁移、R3、BF16/graph、热更新及Gloo/NCCL重载;组件fixture需保留严格detach断言。6cd/8ef的作者专项或镜像报告不替代新base各层验收,本轮未执行测试/构建。
B PD 路由与多轮 Session 纳入 router patch 本次增量、Session service/state、Mini-SWE PD 配置,以及 .17 patch 新增的22行 P/D 完成前 collector;保持 P 真值覆盖 D 占位前缀、已接受路由和 token 行数契约,.21 对应底层实现继续完整留在 A。随附 test_pd_routing_replay_router.py、test_agentic_rollout.py 的新增用例、test_sglang_engine.py 两个 PD 用例及 timeout 文件最后两个跨 .17/.21 collector 用例,复用 A 已落地 helpers。 建议在 .17/.21 分别核验 P/D 首 token 停止前采集、真实 router 的 JSON/SSE/错误与连接回收,以及 Session 部分恢复、多轮和分支路由。再验证 PD+R3、CPU HiCache/retraction 的 Mini-SWE 端到端行为,并补充实际需要的多节点场景。
C TE Blackwell 注意力选择 成对纳入新的 41 行 TE selector patch、原 CP patch 末尾 6 行重叠 selector 删除、cu13 Docker 安装接线和 test_blackwell_flash_attention.py。保留 base 已有 CP padding 主体,固定 TE 2.18.0 已在 base,无需依赖 A。 建议在固定 TE 源码按镜像顺序检查两份 patch,并在 SM103 验证 head72 的 FA2、head256 的 FA4 前反向及数值参考,以及 CP 继续选择原生 FA2。
D Kimi packed Bridge 兼容 纳入 kimi-packed-sequence-api.patch、cu13 Docker 的 COPY/apply/rm 三处接线、kimi-k2.6.sh 的 NLAYERS 默认值及 test_kimi_packed_sequence_compat.py。沿用 base 的 Bridge 固定版本;SGLang KimiK3 热更新及其测试属于 A。 建议验证固定 Bridge 的 preprocess API、TP2/CP2 sequence-first contiguous 布局及 forward mask 返回契约。测试现有 .21 marker 是环境门槛,可用独立 .21 测试环境单独验证 D,保持无 A 代码依赖。
如何按依赖提交(stack)

作者为yuanlehome(MEMBER),head为其fork。本轮权限接口返回403,当前上游write未能复核;不依据成员身份或fork推断权限。

先按表重组混合提交,每部分携带对应测试和文档;逐层验证,并核对顶层最终树与原 PR 一致。独立部分各自向目标分支开普通 PR;只将有依赖的线性链组成 stack,分叉或多前置依赖按图分别安排提交。

有上游写权限: 将各层分支放在上游仓库,在已按依赖拆好的一条分支链上注册并提交(替换目标分支与分支名):

gh stack init --base <target> <layer-1> <layer-2>
gh stack view
gh stack submit

下层更新后用 gh stack rebase 调整上层,或用 gh stack sync 同步整条链。上述命令管理已拆好的分支,不会自动拆开混合提交。参见 gh-stack 使用说明。

Fork 贡献者: 分支保留在 fork,先将底层向上游目标分支提交;上层暂留本地,或在 fork 内以其前置分支为 base 开 draft PR。底层合入后,只将上层独有提交 rebase 到更新后的上游目标分支,再提交下一层;若底层被 squash,注意排除其旧提交。

Fork 内 PR 只用于增量审阅;上游 PR 的 base 不能指向 fork 独有分支。多个累计 PR 同时指向上游目标分支会包含重复差异。GitHub 原生 stack 要求所有分支位于同一仓库。

相关 PR

💡 实现与合入建议

新main仍未覆盖MOPD canonical配置/说明与公共fixture清理;#495继续替代已关闭#459,#347仅重叠fixture修复,均无生产合入前置依赖。

https://github.com/redai-studio/Relax/pull/459 · 5d271167b7bdb4974db92998bdff6cbecfbe38bc · 目标分支 main

https://github.com/redai-studio/Relax/pull/347 · 62ae8c1f2ae6f1e35a40b15f61ce35f4bf4f70f5 · 目标分支 main

实现取舍: 保留#495基于当前0.5.20的迁移、PD真路由/JSON/SSE、HiCache/retraction、Session lineage、最终拓扑transport和确定性BF16修复。#459的共同升级不能替代这些新增行为;#347只重叠fixture/constructor清理,#495现有写法可独立交付,无需为统一外层try/finally改写。

当前 PR 调整: 可选择性移植#459三份MOPD脚本的SGLANG_ENABLE_LOGPROB_CHUNK、SGLANG_LOGPROB_CHUNK_SIZE=8192及RELAX_PROPAGATE_ENV_VARS,并更新OPD说明,按#495已合并的.21主patch和CUDA12/latest→.17布局改写。.17/.20也支持canonical名称;.21忽略旧名仅使显式8192失效,默认仍true/2048,不据此认定chunking关闭或8192性能更好。保留两处fixture清理及ImageSFT的严格单次detach断言。

合入顺序: 不合入或重新开启已关闭未合并#459。canonical配置可独立先行或随#495交付,再rebase去重;升级可聚焦先落、PD/R3后续rebase,或完整组合验收后整体交付。#347仍open/unmerged,任一先合后另一方rebase删除已覆盖的fixture清理,保留各自其余功能;共享测试不构成等待或关闭另一PR的理由。

依据与验证范围: 三方实时head/base/merge-base及需求已复核,新main尚未包含这两项尾差。MOPD参考:https://github.com/redai-studio/Relax/blob/5d271167b7bdb4974db92998bdff6cbecfbe38bc/examples/on_policy_distillation/mopd/run-mopd-qwen35-9b-8xgpu-colocate.sh#L34-L38 ;.21默认值:https://github.com/sgl-project/sglang/blob/e00930c5489053f26d86b179cee0d087f846acbb/python/sglang/srt/environ.py#L1327-L1328 。fixture对照:https://github.com/redai-studio/Relax/blob/41e67c5ee921ae2922bfda5662ef223199c87741/tests/components/test_component_background_loop.py#L14-L34 与 https://github.com/redai-studio/Relax/blob/62ae8c1f2ae6f1e35a40b15f61ce35f4bf4f70f5/tests/components/test_component_background_loop.py#L14-L37 。协调分析只读,未运行测试或构建;作者历史结果不证明当前组合的运行时验收。

提交范围 · 接收 37 · 建议移出 0 · 待确认 0

接收 37 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。

文件结论仓库维护必要性依据替代去向或方案
docker/Dockerfile
docker/Dockerfile.cu13
docker/blackwell-runtime.md
docker/patch/megatron/kimi-packed-sequence-api.patch
docker/patch/sglang-router/v0.3.2-9daabcd-pd-dp-aware.patch
docker/patch/sglang/v0.5.17.patch
docker/patch/sglang/v0.5.21.patch
docker/patch/transformer_engine/2.18.0-blackwell-fa4-head-dim.patch
docker/patch/transformer_engine/2.18.0-cp-padding-no-host-sync.patch
docker/scripts/build_sglang_tree_core.py
docker/scripts/check_gpu_imports.py
docker/scripts/validate_blackwell.py
docker/scripts/validate_unified_runtime.py
接收 既有训练镜像、依赖补丁与构建/验证入口;本轮包含镜像稳定性修正和0.5.17配套修复。 PR#495的CUDA13迁移、CUDA12保留及PD+R3兼容目标。 在原有Dockerfile、版本补丁和构建脚本位置维护,删除项随其原归属核对。
relax/agentic/session/service.py
relax/agentic/session/state.py
relax/backends/sglang/routing_replay_patch.py
relax/backends/sglang/sglang_engine.py
接收 既有Session/R3和引擎构参的生产调用路径。 PR目标及此前已核对的Session、rollout/GenRM契约。 沿用所属模块,不新增独立实现层。
tests/backends/megatron/test_blackwell_flash_attention.py
tests/backends/megatron/test_kimi_packed_sequence_compat.py
tests/backends/sglang/test_disaggregation_timeout_consensus.py
tests/backends/sglang/test_dp_moe_reduce_scatter.py
tests/backends/sglang/test_kimi_k3_weight_reload.py
tests/backends/sglang/test_moe_weight_reload.py
tests/backends/sglang/test_opd_per_position.py
tests/backends/sglang/test_opd_request_validation.py
tests/backends/sglang/test_pd_routing_replay_router.py
tests/backends/sglang/test_qwen38_dummy_weight_loading.py
tests/backends/sglang/test_qwen38_memory_lifecycle.py
tests/backends/sglang/test_reduce_scatterv_gpu.py
tests/backends/sglang/test_relax_patch_migration.py
tests/backends/sglang/test_routing_replay_capture.py
tests/backends/sglang/test_sglang_engine.py
tests/test_agentic_rollout.py
tests/utils/test_reloadable_process_group.py
tests/components/test_component_background_loop.py
接收 迁移及双版本兼容模块回归,并包含组件fixture的客户端生命周期隔离修复。 PR迁移契约及8ef固定CI的共享析构mock干扰;当前提交仅增量修复fixture清理。 保留在所属测试目录,按实际生产边界判断有效性。
examples/mini_swe_agent/pd-2p2d-tp2.yaml
接收 现有Mini-SWE的PD配置。 PR的PD+R3使用场景。 沿用现有示例位置。
scripts/models/kimi-k2.6.sh
接收 既有Kimi模型启动配置。 PR的Kimi训练兼容目标。 沿用scripts/models入口。
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要修改

已确认一处会阻止现有跨节点配方启动的回归,建议修复后再合入。版本迁移与 PD 路由的其余检查仍在进行,本次意见不代表剩余范围已完成审查。

审查面板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

Comment thread relax/backends/sglang/arguments.py Resolved
yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充审查意见

运行时检查补充了两处精度与测试兼容性问题,详见行级意见。已发布的跨节点启动问题仍未解决;共享 router 对 CUDA12 的兼容性正在做最后的独立核实。

审查面板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

Comment thread docker/patch/sglang/v0.5.21.patch Resolved
torch.zeros(1, dtype=torch.long),
)
monkeypatch.setattr(base_processor.envs.SGLANG_MM_AVOID_RETOKENIZE, "get", lambda: avoid_retokenize)
result = await processor._process_mm_data_uncached(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium severity P2 · 按 API 能力适配新增图像测试

保留的 CUDA12 镜像仍使用 SGLang 0.5.17,但该版本的 QwenVLImageProcessor 只有 process_mm_data_async,没有这里调用的 _process_mm_data_uncached;其基类与 0.5.17 补丁也未提供此方法。该新增测试没有版本/能力限制,因此在受支持的 0.5.17 环境中会抛出 AttributeError,无法验证图像 token 保留行为。

请按 API 能力适配入口,或只对依赖新 API 的新增测试加限定,同时保留原有 0.5.17 OPD 回归;不要把整个测试文件跳过。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查 6cd6c9c:此处由 16 个参数组合缩为 2 个,但仍直接调用 _process_mm_data_uncached,没有新增 API/版本保护。保留的 0.5.17 源码和补丁仍无该方法,因此原来的 AttributeError 路径未消除,本项保持未解决。请仅适配或限定这个依赖新 API 的用例,保留其它 0.5.17 OPD 回归。

@rai-studio-bot rai-studio-bot Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查 8ef631b:测试现在按 API 能力选择新版 _process_mm_data_uncached 或 0.5.17 的 process_mm_data_async,并显式设置 fixture 的 use_cuda_ipc=False;原有 sampled IDs 和 mRoPE 断言仍保留。已对照固定 0.5.17 方法及调用路径,原入口缺失问题已修复,本项代码问题已解决。此结论为源码核对,未宣称本轮完整测试通过。

yuanlehome

This comment was marked as outdated.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要修改

目标提交的常规与深度审查已完成,兼容性回归仍需修复后再合入;新增的 CUDA12/router 问题已附行级说明。验证基于固定版本源码及一次 CPU/Gloo 精度边界实验,未执行完整 Docker 构建或多节点 GPU 验证。

审查面板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

+ }
+ let total_rows = prefix_rows.checked_add(completion)
+ .ok_or_else(|| "PD routing replay token count overflow".to_string())?.saturating_sub(1);
+ let mut p = routes(prefix)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High severity P1 · 为保留的 0.5.17 补齐 P 端路由返回

这个新要求也会随共享 router 进入 CUDA12 镜像,但该镜像仍使用未改动的 0.5.17 补丁。该版本的成功 P 端交接路径 在释放 KV 前没有调用 _maybe_collect_routed_experts,因而响应不含 routed_experts。对应收集调用目前只补进了 v0.5.21.patch。

所以 CUDA12 上正常成功的 PD+R3 /generate 也会在这里被拒绝:非流式返回 502 invalid_routing_replay,流式则在最终合并时产生响应体错误。旧 router 容忍缺少 P routes,本次新增的是确定的可用性回归。请给保留的 0.5.17 同步补齐 P 端 producer,并加入版本组合覆盖;不要以 D 端 prompt 占位行作为回退结果。以上结论来自固定版本的生产/消费路径,尚未做 GPU PD 实测。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查 6cd6c9c:共享 router、CUDA12 Dockerfile 和 v0.5.17.patch 与上一轮提交均未变化;当前 router 仍强制读取 P 端 routes,保留的 0.5.17 成功交接路径仍未补齐该字段。因此原来的 CUDA12 PD+R3 拒绝路径仍可到达,此次 transport/BF16 修正没有覆盖它。请为 0.5.17 配套补齐 P 端收集,并验证该版本组合;此项保持未解决。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查 8ef631b:0.5.17 现在在成功 P 交接时、完成标记和 KV 释放前采集路由。已核对捕获 finalize 的先后关系、N-start 行数及正常/skip-tokenizer 序列化,P 元数据满足共享 router 的严格要求;D 首 token 结束也在释放前采集。原来的缺字段拒绝路径已修复,本项代码问题已解决。

验证基于固定版本源码和相关补丁重建;未执行真实 CUDA12 PD 请求,作者本轮 Decode warmup 验收也尚未完成。

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as outdated.

yuanlehome

This comment was marked as off-topic.

@yuanlehome yuanlehome left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按文件汇总本次改动:16 个非测试文件各保留一条说明;原来的零散行内说明已统一整理。

Comment thread docker/Dockerfile.cu13

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

  • CUDA 13 基础运行时和安装校验升级到 SGLang 0.5.21,并固定对应源码 commit、应用新版 Relax patch;CUDA 12 配方不在本文件中升级。
  • 新增 Rust tree core 构建阶段,用匹配的 Torch ABI 编译 HiCache 扩展,再在最终镜像核对并安装,禁止运行时 JIT 另选产物。
  • 纳入 Kimi packed-sequence API 与 Blackwell attention 补丁,保留既有 Megatron patch 栈及依赖组合。
  • 拒绝复用旧版本 train 镜像,防止只升级 Python 包却混入旧 CUDA 扩展。默认基础镜像仍是 tag,需要可重复构建时由 BASE_IMAGE 指定 digest。

@yuanlehome yuanlehome Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

同步 CUDA 13 支持矩阵中的 SGLang 版本为 0.5.21,并修正文档对基础镜像 digest 的描述:当前默认使用 tag,可重复构建需显式指定不可变 digest。保留 Hopper、优化 TP4 配方等尚未完成硬件验收的边界,避免将本次单机验证推广到其他运行环境。

最新验证(6cd6c9c):SGLang 0.5.21 / PyTorch 2.13.0+cu130 / CUDA 13.0 / Blackwell SM103;合并后 CPU 343 passed / 7 skipped,这 7 项已在 GPU 上通过且相关代码未变,沿用结果,合计覆盖 350 项。完整 pre-commit 通过;未重建完整 Docker 镜像,本次审查修复后未重跑端到端训练。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

适配当前 Megatron Bridge 的 preprocess_packed_seqs:移除失效参数,从新返回值中取 embeddings,并转为 Kimi 后续模块需要的 sequence-first contiguous 布局。目的是同时解决 API 签名变化和 TP/CP packed 输入布局兼容,而不只是让函数调用不报错。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

  • 在原有 DP-aware 路由基础上修正 bootstrap host,握手使用物理地址,保留 DP 虚拟 worker 身份。
  • 新增统一的 PD+R3 合并模块:P 返回完整 prompt 路由,替换 D 的 prompt 占位区,再追加 D 的生成后缀;校验 token 计数、增量起点、batch 对应和 base64/int32 形状,并处理首 token 结束等边界。
  • JSON 与 SSE 共用合并规则。SSE 按事件缓冲,支持 UTF-8/CRLF 跨 chunk、保留其他事件字段,并检测缺失终态路由或截断。
  • 优先保留 P 原始错误,等待两侧本次请求收尾后再允许重试;补充 RID/room 日志,PD 空闲连接提前到 4 秒淘汰,避免复用服务端已关闭的连接。

本次端到端验证覆盖 0.5.21 组合;共享 Router 与保留的 0.5.17 P 端路由返回之间的兼容问题,仍见现有待处理审查意见。

@yuanlehome yuanlehome Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

这是从上游 0.5.20 基线迁移到官方 0.5.21 的完整 Relax 补丁,主要包括:

  • 原生 API 迁移:适配 runtime context、调度配置、state capture 和权重更新入口,保留 legacy 接口、OPD、LoRA 及既有模型能力。
  • CPU HiCache:迁移 chunked/deferred backup、受保护 checkpoint、暂停期间异步收尾及 Python/Rust tree core 接口,保持备份、命中与释放顺序。
  • PD+R3:P 在 KV 释放前采集路由,D 支持首 token 结束;路由随 host cache、换槽位和 retraction 保存/恢复,释放时失效,无路由的存储层前缀重算;超时走原生多 rank 共识。
  • 权重热更新:适配 native begin/end 与旧 quantization 协议,支持 BF16、INT4、MXFP4 及 Qwen/Kimi 派生参数刷新,尽量保持 Parameter、存储地址和 loader 属性,避免 CUDA Graph 读取旧数据。
  • 计算与多模态兼容:迁移融合 MoE 路由捕获、DP/graph 布局、图像 sampled IDs 与 OPD 逐位置查询。6cd6c9c 已补齐确定性 reduce_scatterv 的 BF16 → FP32 累加,输出保留原 dtype 和调用方 buffer/alias 身份。

回归:四进程 CPU/Gloo 相消用例,以及 CUDA 13 / Blackwell SM103 上四 GPU NCCL/CUDA Graph 确定性分支均通过;对应审查意见已 resolve。完整 patch 干净应用到官方 0.5.21,89 个受影响 Python 文件编译通过。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

  • 将合法的空路由编码与缺失字段区分开,零行结果也进入统一解码/形状处理。
  • 生成结果按累计 token 数合并 R3:保留已接受 token 的历史路由,只追加本次新增后缀;开启 R3 且接受了新 token 却缺路由时明确报错。

这样部分 abort/resume 不会覆盖旧路由,也不会把不完整的 replay 数据静默交给训练。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

新增统一的 merge_routed_experts,检查 [token, layer, topk] 形状与累计行数,保留旧前缀并复制数据,避免共享数组被后续修改。SessionForest 写入响应时沿选中的 parent lineage 继承路由,再接本轮后缀,使多轮对话、工具观察和 fork 不会混入兄弟分支的专家选择。

@yuanlehome yuanlehome Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

6cd6c9c 已撤销 parser 级别的 cuda_ipc 默认值。默认选择移到 sglang_engine.py 的 policy/GenRM 参数构造中,在最终拓扑和覆盖配置生效后处理:仅单节点默认 CUDA IPC,跨节点保留 SGLang 原生自动选择;显式 CLI/YAML 值及 per-engine None 保持优先。

回归:真实 CLI + SGLang 0.5.21 原生 transport 校验 11 个场景全部通过,覆盖 regular/P/D、GenRM、单/多节点及显式覆盖;对应审查意见已 resolve。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

按能力检测选择 R3 capture 实现:存在 TopkCaptureOutput 时沿用 SGLang 原生 tensor 快照、异步拷贝和 host-cache finalize 生命周期,避免旧 monkey patch 覆盖新版实现;缺少该 API 的旧版本继续使用原有兼容路径。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件改动总结

将固定 NLAYERS=61 改为可由环境变量覆盖,默认仍保持完整模型的 61 层。缩层 checkpoint 可直接传入实际层数,避免为验证反复修改公共模型脚本;单独的两层 INT4 实验启动脚本未进入 PR。

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要修改

已完成 6cd6c9c 的增量复查:transport 与确定性 BF16 修复已确认,保留的 CUDA12/shared-router 配套问题仍需修复;新增测试的双版本兼容性意见已附行级说明。测试整理保留了部分独立数值及存储校验,但缩减了异常和拓扑矩阵;本轮基于固定源码核对,未独立重跑 GPU、多节点或完整镜像验证。

审查面板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

def test_transport_respects_engine_topology_and_native_validation(
request, monkeypatch, engine, worker, gpus, engine_gpus, cli, overrides, expected
):
from sglang.srt.arg_groups import serving_hook

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium severity P2 · 为新增回归处理保留的 0.5.17 接口

这里无条件导入 arg_groups.serving_hook,而 CUDA12 保留的 0.5.17 源码 没有该模块,私有补丁也未补入;因此 11 个 transport 参数项会在检查构参前失败。同轮新增的 test_deterministic_bf16_reduce_scatterv_uses_fp32_accumulation 也无条件提取 0.5.17 不存在的 _deterministic_reduce_scatterv。当前 Unit Tests 工作流 默认构建 CUDA12 Dockerfile,确实会选择这个版本;0.5.21 专项通过不能覆盖此组合。

请让 transport 回归分别调用 0.5.17 的 ServerArgs._handle_multimodal_feature_transport 和 0.5.21 的 hook,保留两版的构参校验;仅对新确定性 helper 专属用例加 API 限定。这里报告的是源码确定的测试兼容缺陷,当前运行中的 CI 尚无失败结论。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查 8ef631b:transport 回归已分别调用 0.5.17 的原生 ServerArgs 校验和 0.5.21 hook,保留真实 CLI/构参与显式错误校验;确定性归约仅在缺少该 helper 时跳过专属用例,普通归约矩阵仍保留,GPU 路径先做普通 NCCL/graph 检查,再判断是否测试确定性分支。本轮未运行这些用例。原来的旧版接口缺失问题已修复,本项按源码核对为已解决;当前 CI 的新失败另在面板分析,不能把旧 6cd 结果当作本次验证。

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查通过

已完成 8ef631b 的增量复查,已报告的代码问题均已修复,未发现新增可行动问题。结论基于固定源码、补丁组合及既有证据;本轮未独立执行完整镜像构建、真实 PD 或多节点 GPU 验证,作者本轮 PD Decode warmup 验收也尚未完成。

审查面板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查通过

已核对 5eb8d13 的 fixture 和构造实例清理,原有行为断言均保留;生产代码与 8ef631b 相同,复用已完成的固定审查证据,未发现新增可行动问题。本轮未运行本地测试;完整镜像、真实 PD 及多节点 GPU 未独立验收。

审查面板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

Upgrade the CUDA 13 runtime and migrate Relax's SGLang patches while
preserving CPU HiCache, disaggregated serving, and weight reload support.
Include the Kimi, Blackwell, and packed-sequence compatibility fixes.

Capture and merge prefill/decode routing replay across CPU cache reuse
and multi-turn sessions. Handle PD error propagation and align router
idle connections with the SGLang keepalive timeout.

Add migration regressions and update the PD launch configuration.

Validation:
- pre-commit run --all-files --show-diff-on-failure passed.
- Regression suite: 835 passed, 33 skipped, including 23 compiled Rust
  HTTP cases.
- Five-round end-to-end runs completed for regular R3, PD+R3, and
  Mini SWE PD+R3 with CPU HiCache; compare train/inference diff, mean
  output length, and raw_reward.
Resolve multimodal transport after per-engine topology and overrides,
using CUDA IPC only by default for single-node engines. Accumulate
deterministic BF16 reduce-scatter in FP32 while preserving output buffers.

Trim redundant upgrade regressions and consolidate related weight reload,
routing capture, engine argument, and patch compatibility tests into five
fewer files without dropping the retained test cases.

Validation: full pre-commit passed; 343 CPU cases passed after consolidation.
The seven unchanged GPU cases previously passed on Blackwell with CUDA 13
and SGLang 0.5.21. The patch applies cleanly to official v0.5.21.
Build FlashAttention and Transformer Engine extensions against the image's
Torch ABI, remove an overlapping TE patch, and align NIXL and OpenTelemetry
dependencies in the CUDA 13 image.

Collect PD routes before releasing request slots on SGLang 0.5.17 and adapt
the existing regression suite to both supported SGLang versions.

Validation: both images built on H800; CUDA 13 native regressions passed
349 tests (3 skipped), and CUDA 12 passed 304 tests (48 skipped). TE, FA2,
and Apex GPU forward/backward or optimizer checks passed in both images.
H800 multi-GPU checks used NCCL_NVLS_ENABLE=0 at launch only. Five CUDA 13
ordinary-generation checks passed; PD image validation remains incomplete
at Decode warmup and is not counted as a passing result.
Explicitly detach background-loop test components before monkeypatch
restores the process-global TransferQueue lifecycle function. Also release
the additional instances created by the constructor test in a finally block.
This prevents delayed garbage collection from counting unrelated detach
calls in the ImageSFT teardown test; its strict once-only assertion stays.

Validation: controlled delayed GC reproduces the old failure (13 detach
calls), while the fixed focused suite passes all 46 tests. All 124 component
tests pass under both normal and delayed GC. No production code changes.
Full pre-commit checks pass.
@yuanlehome
yuanlehome force-pushed the upgrade/sglang-0.5.21-rework branch from 5eb8d13 to 41e67c5 Compare October 28, 2026 13:27

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查通过

已完成 41e67c5 与新 main 基线的组合复查,未发现新增可行动问题。未变范围复用 5eb8d13 的固定源码证据,并补查依赖约束、runtime manifest、TE/Kimi 补丁及 ABI 校验。本轮未执行测试、镜像构建或 GPU/PD/多节点验收,结论限于源码与依赖契约。

审查面板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@yuanlehome
yuanlehome merged commit ea3f0ce into redai-studio:main Oct 28, 2026
13 checks passed
Vivicai1005 added a commit to Vivicai1005/Relax that referenced this pull request Nov 2, 2026
Single-node engines now default mm_feature_transport to cuda_ipc (redai-studio#495), but
SGLang rejects that transport on ROCm ("--mm-feature-transport=cuda_ipc requires
NVIDIA CUDA"), so every SGLang engine failed to start on AMD GPUs.

## 🐛 Bug Fix

- Skip the cuda_ipc default for policy and GenRM engines when running on ROCm,
  leaving SGLang's automatic transport selection; CUDA behavior is unchanged

## ✅ Tests

- Pin is_rocm=False for the existing CUDA transport cases so they do not depend
  on the host GPU
- Add a ROCm case for policy and GenRM engines expecting the auto policy
SigureMo added a commit that referenced this pull request Nov 4, 2026
## What

The ROCm image (gfx950/gfx942), the en/zh ROCm guide plus the
docker/README.md section, and the cuda_ipc fix for a ROCm regression on
main since #495.

## How

- Image: how it matches Dockerfile.cu13 (SGLang patch, Rust tree core,
router, Megatron patches including #488's), plus the prebuilt wheels,
the requirements handling and the runtime environment variables.
- SGLang patch: the one remaining fix, linked to
sgl-project/sglang#44266, with a note that it can be dropped once Relax
upgrades past that.
 - Transport fix: how the cuda_ipc default is skipped on ROCm.

## Testing

- End-to-end colocated GRPO on 8× MI350X (`gfx950` image):

  | Task | Rollouts | Result | `mismatch_kl` |
  | --- | --- | --- | --- |
| Qwen3-4B DAPO-Math (`run-qwen3-4B-8xgpu.sh`) | 3 | Succeeded; weight
update 3.9 s, step ≈ 159 s | 6.2e-4 – 1.0e-3 |
| Qwen3-VL-4B Open-R1 (`run-qwen3-vl-4B-8xgpu.sh`) | 3 | Succeeded;
reward 0.36 → 0.52, weight update 4.3 s | 6.7e-4 – 7.2e-4 |
| Qwen3-Omni-30B-A3B AVQA (16-GPU recipe on one node, EP 4) | 450 |
Held-out AVQA accuracy 0.750 → 0.884; reward 0.81 → 0.95 (first/last 50
rollouts) | 3.0e-3 – 6.2e-3 |


- [x] `pre-commit run --all-files` passes
- [ ] Tests pass (`pytest tests/`)
- [x] New tests added (if applicable)
- [x] Documentation updated (if applicable)

## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update
- [ ] Refactoring (no functional changes)
- [ ] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

<!-- If applicable, add screenshots or log output to help explain the
changes. -->

---------

Co-authored-by: Nyakku Shigure <[email protected]>
Co-authored-by: Codex <[email protected]>
@yuanlehome
yuanlehome deleted the upgrade/sglang-0.5.21-rework branch November 12, 2026 14:20
@apex-mochen apex-mochen mentioned this pull request Nov 16, 2026
2 of 18 tasks
SigureMo added a commit that referenced this pull request Nov 30, 2026
#841)

## What

将 Relax 自编 SGLang Router 的上游 HTTP 连接池空闲超时统一为 4 秒,覆盖普通模式和 PD 模式。

Mini-SWE session supervisor 兼容未启用 `CONFIG_PROC_CHILDREN` 的 Linux 节点。

## Why

SGLang 的 HTTP worker 默认在连接空闲 5 秒后开始关闭。普通模式的 Router 此前允许连接在池里保留 50
秒。新请求如果恰好复用了正在关闭的连接,`/generate` 会收到连接重置,Router 将这次请求报为 `500
call_upstream_request_error`。

#495 已针对 PD 模式把空闲超时缩短到 4 秒。这次把相同的设置用于普通模式。

- [SGLang #20851](sgl-project/sglang#20851) 在
SGLang 0.5.9 上报告了同样的 5 秒 worker keep-alive 与 50 秒 SMG 连接池超时冲突。报告者随后建议由
Router 处理 reset,并关闭了 issue。
- 旧版 SGLang Model Gateway 后续通过
[#24329](sgl-project/sglang#24329) 增加了
`SMG_POOL_IDLE_TIMEOUT_SECS` 和对应的 `--pool-idle-timeout-secs` 参数,默认值为 50
秒。
- 官方新版 `sgl-router` 通过
[#44075](sgl-project/sglang#44075) 直接把连接池空闲超时设为
3 秒,让 Router 先于 worker 的 5 秒超时淘汰连接。

8 卡 H20 回归还遇到了独立的 Agent 启动故障。会话管理代码从 #628 起直接读取
`/proc/self/task/<pid>/children`。这个可选接口在调试节点的内核中未启用,supervisor 收到
`FileNotFoundError` 后在 `finally` 中向自己的 worker 发送 `SIGKILL`。worker 来不及写出
`release.worker.json`,外层因此反复报 `exit -9` 并丢弃样本。

## How

在现有 Router Rust 补丁中移除按路由模式区分超时的分支,直接给 `reqwest` 的 `pool_idle_timeout` 传入
4 秒。下次构建 Relax 镜像时,现有构建脚本会用这份补丁重编 `sglang-router` wheel。

Mini-SWE supervisor 用 `os.waitid(..., WNOWAIT)` 查看已退出的子进程,再用
`os.waitpid` 回收已收养的后代,并把主 worker 的退出状态留给 `Popen`。Supervisor 和 Agent
Server 共用子进程枚举逻辑。默认使用 `psutil.Process().children()`。遇到读取权限错误时,逐个用 psutil
核对子进程关系,跳过已退出或不可读的 PID。Supervisor 清理仍存活的后代后,继续以 `waitpid` 的 `ECHILD`
确认资源释放。Mini-SWE 独立虚拟环境的安装清单加入 `psutil`,已有环境也需补装。

## Testing

- [x] `pre-commit run --all-files` passes
- [ ] Tests pass (`pytest tests/`)
- [x] New tests added (if applicable)
- [x] Documentation updated (if applicable)

- 在锁定的 Router 源码 `9daabcd` 上通过 `git apply --check`,并核对应用后生成的 Rust 源码。
- `cu12`(Linux x86_64)镜像构建并推送成功,现有构建流程重新编译了 Router
wheel,并通过镜像内的原生模块导入检查。
- 在该 `cu12` 镜像中验证普通模式 Router 的真实连接复用行为。空闲 0.5 秒后复用原连接,空闲 4.5 秒后建立新连接。
- 原 supervisor 在关闭 `CONFIG_PROC_CHILDREN` 的节点复现 `FileNotFoundError →
SIGKILL → exit -9`。
- 权限回归用例只对一个无关 PID 注入读取错误。旧版 `ea756081` 复现
`psutil.AccessDenied`,`a6371406` 在 Linux H20 环境通过 14 个资源清理测试及 28 个 Agent
Server 测试。
- `ea756081` 用真实 Apptainer SIF 启动实例并执行命令。测试确认实例已停止、脱离 worker
进程组的子进程已回收,且 supervisor 返回 `resources_released=true`。
- 使用 `ea756081`、原 PR 的 cu12 镜像和 `psutil==7.2.2` 提交 8 卡 H20 的 CE 回归。加载
Qwen3.5-35B-A3B 真权重后,完成了 `rollout 0/20` 至 `rollout 3/20`。使用同一 Mini-SWE
脚本、模型、数据和 8 卡规模的两次旧跑次分别在第 2 和第 4 轮报
`call_upstream_request_error`。本次前四轮日志中 `Agent session failed`、`exit -9`
和 `call_upstream_request_error` 均为 0。验证范围为已完成的前四轮。

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Refactoring (no functional changes)
- [ ] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

故障抓包显示 worker 空闲约 5 秒后发出 `FIN`,Router 随后在同一个 TCP 连接上发送新请求,收到 `RST`。

Mini-SWE 原版 supervisor 的调试日志记录了读取可选 procfs 文件失败,并从 `finally` 向该会话的
worker 发送 `SIGKILL`。

<div align="right">
    <sup>This PR is co-authored with @codex (gpt-6.2-sol xhigh)</sup>
</div>

---------

Co-authored-by: Codex <[email protected]>
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.

4 participants