Repository navigation
feat(rollout): enable CPU HiCache for regular and PD rollouts - #442
Conversation
Add an eight-GPU 2P2D TP2 Mini SWE entry point with CPU and file-backed SSD cache configurations, per-prefill-engine storage directories, and English and Chinese guides. Port native Full KV/Mamba cache lifecycle fixes for asynchronous IO, cancellation, paused completion polling, TP-consistent restoration, and deferred chunked checkpoints. Isolate file caches across weight epochs and engine incarnations, and fail closed after partial weight updates. Preserve the original Mini SWE and pure PD launchers. Add regression coverage and validate real rollout/train/update cycles, tier restoration, storage faults, eviction, weight invalidation, and engine recovery.
Describe cache tiers, backend selection, DP isolation, capacity planning, and weight invalidation in the bilingual feature guides. Move Mini SWE launch commands and model-specific settings into the example README. Remove fixed max_total_tokens values from both cache configurations so SGLang derives GPU pool capacity from its memory budget unless explicitly overridden for a controlled run.
Remove the file-backed L3 implementation, directory management, SSD recipe, and storage-specific tests. Retain the Full KV/Mamba CPU checkpoint and paused transfer-completion fixes. Make the Mini SWE CPU-cache recipe default to regular engines with optional PD deployment, and document cache placement separately from engine topology. Add a 1P1D attention-DP2/TP2/EP4 recipe and the paired R3-router patch for physical endpoints, independent P/D ranks, and bootstrap ownership. Preserve legacy native DP-rank compatibility and document the isolated router build. Validate all three layouts through three Mini SWE RL cycles, actual P/D session affinity, per-rank CPU restores and flushes, native and framework regressions, CUDA graph checks, patch reconstruction, and bilingual docs.
Prevent destination-dependent BF16 cancellation in fixed-size DP reduce-scatter. Convert the reduced slice back before attention-TP all-gather, preserving output dtype and symmetric-memory allocation. Keep FP16/FP32 and variable-size collective paths unchanged. Add regressions for rank-dependent cancellation, collective dtypes, and empty owners. Validate real four-GPU collectives and CUDA graphs, eager and graph service A/B/B/A performance, CPU reloads, and three mini-swe RL cycles with DP2/TP2/EP4 1P1D dp-aware routing. No model checkpoints are saved and all eight GPU occupy workers are restored.
Compile the pinned R3 and PD DP-aware router in a separate stage for both CUDA Dockerfiles. Share the wheel builder, lock Cargo dependencies, record build provenance, and replace inherited router wheels after requirements. Remove four embedded unit-test additions from the SGLang patch while preserving its runtime changes byte for byte. Validated the actual wheel build and import, router protocols, 26 Docker Makefile regressions, all pre-commit checks, and 4 x 72 GPU measurement waves comparing 2P2D with 1P1D attention-DP2 on 8 H20 GPUs. The stripped SGLang patch reproduces 63 previously validated runtime files. A full Docker image build was unavailable because the remote has no daemon.
|
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 审查看板审查状态: 💬 已完成 · 有补充意见 审查版本: e073fb4 目标分支: main 审查范围更新至 head e073fb4(fix(sglang): use FP32 for variable DP reductions)。P2 已由范围豁免升级为实际修复:FP32 提升落在共用 GroupCoordinator.reduce_scatterv(pynccl varlen 分支,无 fallback 分支),5 个调用方全部汇入、生产调用均显式传 sizes;独立复核选定 5 项 CPU 用例通过(收集数 124 与作者声明一致),阴性对照在未打补丁 v0.5.17 基线精确失败于 dtype 断言。四卡 NCCL/CUDA graph 与性能数据按作者报告记录(本地无 GPU,PR 正文已列明测量方法与限制)。状态:无 P1;P2 已解决(实际修复);4 项 P3 维持开放(F2/F3 作者已确认范围,F5/F7 为文档与契约加固建议)。CI(新 head)当前无失败实例。
审查发现待处理
已解决或已取代
提交范围 · 接收 20 · 建议移出 0 · 待确认 0接收 20 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。
精简审查与验证依据
生产代码的必要性与替代方案
测试的必要性与替代方案
Powered by Nyanpasu with glm-5.3-flash max, please check the suggestions carefully.
|
There was a problem hiding this comment.
🔵 Needs a closer look
Distributed cache and collective changes need human review, image-build validation, and GPU integration testing unavailable in this source-only environment.
0 open findings
What changed in this PR
Adds CPU-backed SGLang caching recipes to Relax’s Mini SWE workflow, supporting regular and prefill/decode deployments.
Changes:
- Adds cache configurations, a launcher, bilingual documentation, and regression tests.
- Patches cache completion handling, deferred checkpoint backups, and BF16 reduction precision.
- Builds and installs a patched router supporting independent prefill/decode rank selection.
| File | Description |
|---|---|
| tests/examples/test_mini_swe_hicache.py | Tests launcher selection and cache recipes. |
| tests/backends/sglang/test_dp_moe_reduce_scatter.py | Tests reduction precision and buffer behavior. |
| tests/backends/sglang/test_cpu_hicache_args.py | Tests topology-specific cache arguments. |
| examples/mini_swe_agent/run_mini_swe_agent_hicache.sh | Adds cache deployment launcher. |
| examples/mini_swe_agent/README.md | Documents cache recipes and launch commands. |
| examples/mini_swe_agent/pd-hicache-cpu-2p2d-tp2.yaml | Configures TP2 prefill-side caching. |
| examples/mini_swe_agent/pd-hicache-cpu-1p1d-dp2-tp2-ep4.yaml | Configures attention-DP2 prefill-side caching. |
| examples/mini_swe_agent/hicache-cpu-4x-tp2.yaml | Configures four regular cache-enabled engines. |
| docs/zh/guide/hierarchical-cache.md | Adds Chinese CPU cache guide. |
| docs/en/guide/hierarchical-cache.md | Adds English CPU cache guide. |
| docs/.vitepress/config.mts | Links both cache guides. |
| docker/scripts/build_sglang_router.sh | Builds a pinned, patched router wheel. |
| docker/patch/sglang/v0.5.17.patch | Updates cache lifecycle, routing compatibility, and reduction precision. |
| docker/patch/sglang-router/v0.3.2-9daabcd-pd-dp-aware.patch | Separates physical endpoints from per-rank routing. |
| docker/patch/sglang-router/README.md | Documents router builds and verification. |
| docker/Dockerfile.cu13 | Builds and installs the patched router. |
| docker/Dockerfile | Builds and installs the patched router. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
rai-studio-bot
left a comment
There was a problem hiding this comment.
审查结论
本 PR 通过仓库既有的 sglang 镜像补丁 + 镜像内构建路由器机制交付全部生产行为,净 diff 不含 relax/ 生产代码改动(中间提交引入又回退的 SSD/file-cache 实现无残留引用)。三个 scoped 深查(HiCache 补丁、BF16 DP 归约、路由构建管线)均已完成并经交叉复核:无 P1 阻塞问题,构建管线经端到端实测通过。以下 1 项 P2、6 项 P3,均已附行内评论。
发现
- P2(
v0.5.17.patch,dp_attention.py节):可变长度reduce_scatterv的 DP MoE combine 仍按 bf16 累加——与本提交修复的抵消机制同类,TP=DP=EP 拓扑(如 TP4/DP4/EP4)经本镜像可达;建议扩展 fp32 提升或记录豁免依据。 - P3:暂停轮询无节流,长时间权重更新暂停期间以无上界速率自旋 gloo 集合通信。
- P3:暂停泵覆盖不对称——disagg decode 暂停分支(
enable_decode_hicache模式)与 flexkv-only 配置未纳入,同样的flush_cache拒绝停顿在这些路径仍会发生。 - P3:
data_parallel_rank→routed_dp_rank迁移随内嵌测试剥离失去唯一覆盖,建议补一个 relax 侧小用例。 - P3:
ROUTER_SOURCE_ARCHIVE离线构建覆盖未写入 README。 - P3:BF16 测试的 mock 只校验 dtype,不校验被归约缓冲的内容/形状契约,错误缓冲区类回归可通过。
- P3:
test_cpu_hicache_args.py未固定"未知 override 键直接传入"的契约。
已验证的关键声明
- 补丁剥离声明成立:821aa7e4 对补丁的净变更为"仅新增 HiCache/DP-aware hunk、删除 4 个内嵌测试段",运行时节逐字节不变(两种独立方法核验:逐文件 ± 内容多重集比较 + 同画布重建 diff,0 删除行);被删测试从未被 Relax CI 执行。
- 路由构建管线实测通过:归档 SHA256 与 pin 一致;
cargo check --locked通过;构建脚本端到端产出0.3.2+slime.dpawarewheel,通过 Dockerfile 的验证断言;源码构建的.so依赖系统libssl.so.3,由同一TRAIN_IMAGE基座满足,镜像内 import 验证使任何缺失成为响亮的构建失败;无后续层会重装覆盖补丁 wheel。 - DP-aware 接线链完整:
sglang_enable_dp_attention→router_dp_aware→ 路由经get_server_info发现 dp_size,与 relax 现有注册负载兼容;PD 路径发出的routed_dp_rank/disagg_prefill_dp_rank与 io_struct 别名迁移对齐,迁移在任何消费前完成,DeprecationWarning不会刷日志。 - 文档与配方:中英文档声明与 pristine sglang 0.5.17 比对成立(
hicache_size覆盖 ratio、Mamba 池按 DP 分摊等);示例启动脚本的--sglang-configlast-wins 组合与示例测试断言一致。 - BF16 修复本体正确:两个可达调用点均兼容(形状、输出对象同一性、对称内存注册与 pristine 一致),fp32 累加确实消除 bf16 逐对加法抵消(CPU 数值验证:256+1−256+0.5 → bf16 得 0.5,fp32 得 1.5),fp16/fp32 路径行为不变;上游 main 无等价修复。
- CI 兼容:unittest 工作流构建含
docker/patch/**的镜像后再装 requirements.txt,已打补丁的 sglang/路由 wheel 按 PEP 440 满足 pin,新测试在 CI 中解析到补丁源码、为绿。
验证方式与限制
- 本地仅运行个别选定用例:
tests/backends/sglang/test_cpu_hicache_args.py(9 通过);BF16 测试 3 个节点对补丁源通过、对 pristine 源失败(证实其能捕获回归)。 - 多节点 GPU 集成路径未运行(需多节点 GPU 硬件);NCCL 归约内部顺序、暂停/flush 实机序列、Rust 测试执行(仅编译验证)等结论来自源码级核验,已在相应评论中注明。
| self._validate_inputs() | ||
| self._determine_batch_size() | ||
| if self.session_id is not None and self.session_params is not None: | ||
| diff --git a/python/sglang/srt/layers/dp_attention.py b/python/sglang/srt/layers/dp_attention.py |
There was a problem hiding this comment.
[P2] 同类 BF16 归约路径未覆盖:可变长度 reduce_scatterv 仍按 bf16 累加
本节修复了定长路径 dp_reduce_scatter_tensor 的 bf16 抵消问题,但补丁后镜像内还存在同一失败类别的可变长度路径:
srt/layers/communicator.py:1367-1372与srt/layers/moe/token_dispatcher/standard.py的combine()在should_use_dp_reduce_scatterv()(moe/utils.py:449-464,纯拓扑门控:tp_size == attn_dp_size == moe_ep_size且attn_dp_size > 1)成立时,用get_tp_group().reduce_scatterv(...)在 bf16 上完成专家部分和归约,替代 MoE 后置 all-reduce。它经 pyncclncclReduce链在输入 dtype(bf16)上累加,与本提交所修复的"destination 依赖的 bf16 抵消"机制相同。
失败场景:使用本镜像、开启 DP attention 且 TP=DP=EP 的拓扑(例如 TP4/DP4/EP4),MoE combine 在各 NCCL root 上按 bf16 累加符号相反的专家部分和,产生与本节所修定长路径同类、随目标 rank 变化的隐状态误差。PR 自身的 DP2/TP2/EP4 配方不受影响(4≠2,门控不成立),且该行为源自上游、非本 PR 引入——但提交标题声称修复"BF16 DP MoE reductions",而这条路径正是 DP MoE 归约,提交信息只写"Keep ... variable-size collective paths unchanged",未说明豁免依据。
建议:要么将同一 fp32 提升扩展到 reduce_scatterv(fp32 输入 + 散射分片回转 bf16,即本节修复在非等分分支的模式),要么在提交/PR 说明中记录可变长度路径豁免的理由。
There was a problem hiding this comment.
已在 PR 描述的 Validation scope 中记录可变长度 reduce_scatterv 路径保留上游行为的依据,与本审查核实的拓扑门控一致(直接 MoE 路径要求全局 TP = attention DP = EP,本 PR 各配方均不满足),并明确声明并非修复所有 BF16 DP 归约——该 P2 的第二项建议(记录豁免依据)已满足,标记为解决。剩余选项(将 fp32 提升扩展到 reduce_scatterv,需独立的拓扑/空 owner/CUDA graph 验证)留待后续有该拓扑需求时再评估。
There was a problem hiding this comment.
已在 e073fb4 实际修复此路径,并更新 PR 的 Validation scope,取代此前的范围豁免。
修复位于共用的 GroupCoordinator.reduce_scatterv:BF16 输入和归约临时输出都提升为 FP32,归约后写回调用者原输出。这样 communicator.py、standard MoE combine 和 DP attention 的可变长度调用共用同一修复;FP16/FP32 保持原 collective dtype。SGLang patch 仅包含运行代码,回归测试放在 Relax 的 tests/backends/sglang/。
验证结果:
- 219 项相关 CPU 测试通过,其中归约测试 124 项;移除提升、只提升输入、遗漏 copy-back、错误跳过空 owner 的反向变体均被测试拦截。
- 真实四卡 NCCL/CUDA graph 测试通过,拓扑 TP = attention DP = EP = 4,且
should_use_dp_reduce_scatterv()为真。覆盖 36 组 dtype/分片/缓冲区组合:不等长分片、两个空 owner 位置、全空输入、等分回退,以及自动分配/给定/别名输出;每个 rank 校验 eager 和三次更换输入后的图重放。 - 真实 NCCL 抵消对照
256 + 1 - 256 + 0.5 = 1.5:修复前非空 owner 的最大绝对误差分别为 0.5、1.5、1.0,修复后在全部测量尺寸上均为 0。 - 最终代码的
pre-commit run --all-files全部通过。
也补测了性能代价:4 × H20、PyTorch 2.11.0+cu129 / NCCL 2.28.9,BF16 [N,2048]、分片 [0,N/8,3N/8,N/2],预热后按 A/B/B/A 顺序,每阶段 20 × 10 次操作;取每个样本四 rank 的最大 CUDA-event 耗时,再取两阶段合并中位数。
| N | Eager μs/op:原始 → 修复 | CUDA graph μs/op:原始 → 修复 |
|---|---|---|
| 8 | 43.90 → 69.84 (+59.1%) | 13.93 → 19.50 (+40.0%) |
| 64 | 44.91 → 71.99 (+60.3%) | 14.47 → 21.32 (+47.4%) |
| 256 | 44.20 → 71.88 (+62.6%) | 18.27 → 30.16 (+65.1%) |
图模式每次归约增加 5.57–11.89 μs,包含转换、FP32 通信和写回。这是单机热缓冲微基准,不能换算成整模型吞吐损失;未运行 TP4/DP4/EP4 整模型训练、多节点或 symmetric-memory 验证。PR 描述已保留历史端到端性能数据,并单独列出本次测量方法、范围和数据校验值。
There was a problem hiding this comment.
已独立复核,该 P2 确认已实际修复,修复点选择正确:
- 源码级核验:修复位于共用的
GroupCoordinator.reduce_scatterv(parallel_state.py,pynccl varlen 分支,该函数无其他 fallback 分支),5 个调用点(deepseek_v4.py:1918、dp_attention.py:834/959、communicator.py:1368、token_dispatcher/standard.py:255)全部汇入,且生产调用均显式传sizes;pynccl varlen 路径按 sizes 对 FP32 输入/输出逐 chunkncclReduce,dtype 两侧一致、元素数不变,FP16/FP32 原样直通。 - 补丁后源码选定用例 5 项通过:BF16 空 owner + 别名输出写回、BF16 等分回退 + provided 输出 identity、FP16 全空输入保持原 collective dtype、DP attention 变长 combine 的空/非空 owner;本仓收集数 124 与你的声明一致。
- 阴性对照:同一 BF16 别名输出用例在未打补丁的 v0.5.17 基线上精确失败于 dtype 断言(收到 bf16 而非 fp32),确认测试能拦截提升逻辑丢失——与你的反向变体结论一致。
- 限制:本审查环境无 GPU,四卡 NCCL/CUDA graph 覆盖与性能数据按作者报告记录;PR 正文已单独列出测量方法、范围与限制,处置合适。
| self.maybe_sleep_on_idle() | ||
|
|
||
| + def _poll_paused_hicache(self) -> None: | ||
| + # Pause stops generation, but in-flight GPU/CPU DMA must complete. |
There was a problem hiding this comment.
[P3] 暂停轮询无节流:长时间暂停期间以无上界速率自旋集合通信
暂停分支直接 continue(maybe_sleep_on_idle 仅经 on_idle 触达,暂停路径被跳过),因此多分钟级权重更新暂停期间,每个事件循环迭代都会执行 check_hicache_events() → _sync_hicache_ready_counts(attn-TP/CP 组上的 CPU 张量 MIN all-reduce)+ 队列 drain,速率可达每秒数千次,占用 CPU 并与同进程的权重加载线程竞争。正确性不受影响(同一 engine 的全部 TP/PP rank 同时收到暂停,集合通信配对不被破坏)。
建议:暂停期间复用 maybe_sleep_on_idle,或在队列清空后改为每 N 次迭代轮询一次,为轮询频率加上界。
| recv_reqs = self.request_receiver.recv_requests() | ||
| self.process_input_requests(recv_reqs) | ||
| if self._engine_paused: | ||
| + self._poll_paused_hicache() |
There was a problem hiding this comment.
[P3] 暂停泵覆盖不对称:disagg decode 分支与 flexkv-only 配置未纳入
同一停顿前提(in-flight GPU/CPU DMA 未排空导致 is_fully_idle 永不成立、flush_cache 持续被拒)还存在于两类未覆盖路径:
- disagg decode 暂停分支:
srt/disaggregation/decode.py的暂停分支为裸continue。enable_decode_hicache是受支持的 decode 模式(正常路径存在对应的check_hicache_events泵),暂停时ongoing_load_back永不排空。PR 配方关闭了 decode hicache,故当前配方未踩到,但提交信息的理由同样适用于此。 - flexkv-only 配置:正常路径的泵门控为
enable_hierarchical_cache or get_memory().enable_flexkv,而_poll_paused_hicache仅门控 hicache——--enable-flexkv且无 hicache 时暂停同样不排空。
建议:将 decode 的暂停分支纳入同一轮询;flexkv 若在支持范围内,门控条件与正常路径对齐。
| req.swa_uuid_for_lock = lock_result.swa_uuid_for_lock | ||
| # carry the skip set so this node's dec releases only what we locked | ||
| req.skip_lock_node_ids = lock_result.skip_lock_node_ids | ||
| diff --git a/python/sglang/srt/managers/io_struct.py b/python/sglang/srt/managers/io_struct.py |
There was a problem hiding this comment.
[P3] data_parallel_rank → routed_dp_rank 迁移失去唯一测试覆盖
剥离补丁内嵌的 4 个 sglang 测试段本身合理(运行时 hunk 逐字节不变,Relax CI 从不运行 sglang 内嵌测试)。但其中 test_native_dp_rank_compat.py 是本节迁移逻辑(GenerateReqInput 上的 deprecated 别名 + normalize_batch_and_arguments 顶部迁移)唯一的测试,而 fork 路由的常规 DP-aware 路径(router.rs 的 DP_RANK_KEY 发送 data_parallel_rank)依赖它。
失败场景:未来升级 sglang 补丁基线时若静默丢失该迁移块,常规 DP-aware 路由将发送未迁移字段,请求落到 DP controller 的默认调度而非目标 rank。
建议:在 tests/backends/sglang/ 增加一个小用例,断言 GenerateReqInput(data_parallel_rank=1) 经 normalize_batch_and_arguments() 后得到 routed_dp_rank == 1。
There was a problem hiding this comment.
已在 3b7b5e5 补上 tests/backends/sglang/test_native_dp_rank_compat.py,测试位于 Relax 仓库,SGLang patch 未修改。
17 个用例直接使用真实 GenerateReqInput 和 Pydantic 解析,覆盖 Python/JSON 输入、旧字段 rank 0/1、显式 routed_dp_rank 优先级、空值、弃用警告与旧字段清理,以及批量请求拆分后的 rank 保留。仅未安装 SGLang 根包时跳过,不吞掉模块内部导入或行为错误。
验证:在与当前 PR 运行时 hunk 一致的 SGLang 源码上,这 17 项全部执行通过;连同 BF16、HiCache 参数、router registration 和 Mini SWE HiCache 测试,共 111 passed(无跳过)。另用未打别名补丁的真实 SGLang 执行旧字段 JSON rank=1 用例,准确失败于 routed_dp_rank 的 None != 1,确认能拦住迁移逻辑丢失。pre-commit run --all-files --show-diff-on-failure 全部通过。
本次只改单测;验证使用 CPU,未重跑多节点 GPU 集成或性能实验。
There was a problem hiding this comment.
已独立复核,该 P3 记录为解决。在与 PR 运行时 hunk 一致的补丁后源码上,选定用例(json 旧字段 rank=1、routed_dp_rank=None+旧字段的迁移优先级、python 显式 routed_dp_rank、批量拆分后 rank 保留)全部通过;另在未打别名补丁的 v0.5.17 基线(2948168 归档副本)上运行 json rank=1 用例,精确失败于 routed_dp_rank 的 assert None == 1(test_native_dp_rank_compat.py:41),确认测试能拦截迁移逻辑丢失——与你的反向实验结论一致。将覆盖移入 Relax 仓库的处置正确:Relax CI 从不运行 sglang 内嵌测试,仓库内测试才受 CI 保护。
| export CARGO_PROFILE_RELEASE_LTO=false | ||
| export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16 | ||
| export CARGO_BUILD_JOBS=16 | ||
| bash "$RELAX_ROOT/docker/scripts/build_sglang_router.sh" \ |
There was a problem hiding this comment.
[P3] ROUTER_SOURCE_ARCHIVE 离线覆盖未写入文档
build_sglang_router.sh 支持 ROUTER_SOURCE_ARCHIVE 指向预取的源码归档(SHA256 仍强制校验,无法绕过 pin),但本 README 与 examples/mini_swe_agent/README.md 均未提及。离线构建主机按文档操作时只会遇到无法解释的 curl 失败,而覆盖入口其实存在。
建议:在"Build an isolated wheel"一节加一句说明该环境变量的用途与哈希校验行为。
| sizes = [0, 1, 3, 4] if variable else [rows // dp_size] * dp_size | ||
| output = torch.empty((sizes[rank] if variable else rows // dp_size, width), dtype=dtype) | ||
|
|
||
| def reduce_scatter(destination, value): |
There was a problem hiding this comment.
[P3] mock 忽略被归约张量的内容与形状:错误缓冲区类回归可通过测试
mock 的 reduce_scatter 从硬编码 contribution 计算结果,既不检查 value 是否为 source.float() 的像,也不检查 value.numel() == destination.numel() * world_size 契约。因此"传入未初始化的 fp32 缓冲而非 input.float()"或"错误设置 reduce_output 尺寸"这类回归仍会得到 1.5 并通过,而真实集合通信会归约垃圾数据。
建议:在 mock 内补充断言——value.dtype == torch.float32、数值与 source.float() 一致、形状满足 numel 契约。
There was a problem hiding this comment.
已在 3b7b5e5 补齐 test_dp_moe_reduce_scatter.py 的 mock 断言,SGLang patch 未修改。
reduce_scatter 现在先检查实际传入张量:BF16 分支的输入/输出均为 FP32,值精确等于该 rank 的预期贡献,输入/输出形状正确,且 value.numel() == destination.numel() * tp_size。预期值独立构造,避免源张量被错误修改时相互掩盖。all_gather 同时检查形状和 attention-TP 的元素数量关系;其真实复制与已有最终结果断言继续验证内容。FP16/FP32 和可变长度路径的原有测试保留。
验证:该文件 16 项通过,相关 5 个测试文件合计 111 passed(无跳过),pre-commit --all-files 全部通过。另在临时源码副本分别注入零输入、展平输入、错误输出形状、BF16 累加器四种错误,均被对应新增断言拦住。上述反向实验未修改仓库 patch 或共享运行源码。
There was a problem hiding this comment.
已独立复核,该 P3 记录为解决。在与 PR hunk 一致的补丁后源码上运行 [0-2](非等分分支)与 [3-4](等分分支),新的 dtype/形状/numel 契约与值断言均通过——两分支中 destination.shape == (rows // tp_size, width) 断言均成立。mock 现在用独立构造的期望值校验实际传入张量确为源张量的 fp32 像,此前"未初始化 fp32 缓冲替代 input.float() 可通过"的缺口已闭合;all_gather 的形状与元素数量断言也补齐了对应契约。
| base_gpu_id=0, | ||
| sglang_overrides=overrides, | ||
| ) | ||
| expected = worker_type != "decode" if override is None else override |
There was a problem hiding this comment.
[P3] 未固定"未知 override 键"的行为契约
_compute_server_args 的 sglang_overrides 循环对任意键无条件赋值(与 _compute_genrm_server_args 的 warn-and-drop 不同),YAML 键名拼写错误会在引擎启动时以 TypeError 暴露。本 PR 三个 YAML 的全部 override 键已验证有效,但新测试未固定这一契约。
建议:补一个含伪造键的用例,明确文档化"override 键会被直接传入 ServerArgs"的行为,避免未来靠启动期报错才发现拼写问题。
Exercise real native request parsing and normalization for legacy DP rank aliases, including zero ranks, canonical precedence, warnings and batches. Validate collective input values, dtypes, shapes and element counts so incorrect BF16 accumulator buffers cannot pass the simulated reduction. Keep all regression tests in Relax without changing the SGLang patch.
Accumulate BF16 reduce_scatterv inputs in FP32 and copy the result back into the original output buffer, preserving its dtype and aliasing. Keep FP16 and FP32 collectives unchanged. Cover uneven and empty owners, automatic output allocation, aliases, and equal-size fallback. Add a real four-rank NCCL/CUDA graph regression with changed inputs on replay. Validation: 219 related CPU tests, the four-GPU regression, A/B/B/A collective benchmarks, and pre-commit run --all-files all passed.
rai-studio-bot
left a comment
There was a problem hiding this comment.
复审结论(head e073fb4)
上一轮完整审查(1 P2 + 6 P3)后,作者以 e073fb4 将 P2 从范围豁免升级为实际修复。本轮为增量复审,仅核验该提交的变更(补丁 +21 行、两个测试文件);其余范围(HiCache、路由构建管线、文档与示例)未变动,此前结论维持。
P2 已实际修复并经独立复核
修复落在共用的 GroupCoordinator.reduce_scatterv(parallel_state.py,pynccl varlen 分支):BF16 输入与归约临时输出均提升 FP32,归约后 copy_ 写回调用者原输出;FP16/FP32 保持原 collective dtype。核验结果:
- 修复点覆盖完整:该函数无其他 fallback 分支,5 个调用点(
deepseek_v4.py:1918、dp_attention.py:834/959、communicator.py:1368、token_dispatcher/standard.py:255)全部汇入,生产调用均显式传sizes(sizes=None仅为防御性回退);plain-TP 固定路径不受影响,影响面与作者"targeted collective validation"的表述一致。 - 选定 CPU 用例 5 项通过(补丁后源码):BF16 空 owner + 别名输出写回、BF16 等分回退 + provided 输出 identity、FP16 全空输入保持原 dtype、DP attention 变长 combine 空/非空 owner;测试收集数 124 与作者声明一致。
- 阴性对照成立:同一 BF16 用例在未打补丁的 v0.5.17 基线(
2948168)精确失败于 dtype 断言(收到 bf16 而非 fp32),确认测试能拦截提升逻辑丢失;新增测试 AST 提取真实补丁函数执行而非 mock 替身。 - PR 正文 Validation scope 已如实改写为实际修复 + 四卡套件拓扑说明,与核实结果一致。
限制
本审查环境无 GPU:四卡 NCCL/CUDA graph 覆盖(36 组合、eager + 三次图重放)与性能数据(+40–65% μs/op,微基准)按作者报告记录;PR 正文已单独列出测量方法、范围与未验证项(TP4/DP4/EP4 整模型、多节点、symmetric-memory)。CI(新 head)当前无失败实例。
剩余开放项(无阻塞)
- P3(作者已在 PR 正文确认范围):暂停轮询无节流自旋;disagg decode 暂停分支与 flexkv-only 配置未纳入暂停泵。
- P3(建议级):
ROUTER_SOURCE_ARCHIVE离线构建覆盖未写入 README;test_cpu_hicache_args未固定"未知 override 键直接传入"契约。


What
Add CPU HiCache recipes for Qwen3.5-35B-A3B Mini SWE rollouts in regular and prefill/decode (PD) deployments, together with the SGLang lifecycle fixes, DP-aware routing, and router packaging needed by these configurations.
The eight-GPU recipes cover:
Add English and Chinese CPU cache guides covering configuration, capacity planning, cache-hit verification, and invalidation across RL weight updates. The supported cache tiers are GPU and CPU memory.
Why
Multi-turn agents repeatedly submit long prefixes. CPU HiCache allows prefixes evicted from GPU memory to be restored, reducing repeated prefill work when reuse outweighs transfer costs.
These workloads also expose correctness issues: paused engines must finish outstanding cache transfers before flushing; chunked Full KV/Mamba requests can miss the CPU backup of a valid checkpoint before a short final tail; and PD routing with attention DP must identify the prefill and decode owners independently. BF16 MoE reductions can additionally produce different results depending on the destination rank's accumulation order.
How
routed_dp_rankvalues to prefill and decode, plusdisagg_prefill_dp_rankto decode, while preserving native fields such asrouted_experts. Accept the legacydata_parallel_rankalias in SGLang.dp_reduce_scatter_tensorandGroupCoordinator.reduce_scatterv, then copy back to the original output dtype/buffer. Preserve FP16/FP32 behavior and BF16 attention-TP all-gather.TRAIN_IMAGE.run_mini_swe_agent_hicache.sh; select regular or PD deployment withHICACHE_DEPLOYMENTand YAML overrides.Validation scope: the BF16 precision fix covers fixed-size
dp_reduce_scatter_tensorand the sharedGroupCoordinator.reduce_scattervused by variable-size DP/MoE callers. The direct MoE path requires global TP = attention DP = EP; the new four-GPU collective suite exercises TP = DP = EP = 4 separately from the TP4 / attention DP2 / EP4 recipe. This is a targeted collective validation, not a claim about every BF16 reduction in SGLang.The paused cache-completion fix is validated for regular and prefill CPU HiCache. The supplied PD recipes disable decode HiCache; decode-cache and FlexKV-only configurations are outside this validation. Paused polling is currently unthrottled, and its overhead has not been measured separately; the existing review thread remains open.
Testing
Added Python regressions for cache argument precedence across engine roles, recipe selection and runtime preservation, and BF16 cancellation/collective dtype behavior. The router patch includes Rust tests for independent P/D ranks, DP1 passthrough, and physical bootstrap hosts.
Validation recorded in 96b1266 and ac0f148 includes three Mini SWE RL cycles for all three layouts, per-rank CPU restores and flushes, P/D session affinity, and real four-GPU collective/CUDA graph checks.
821aa7e records successful router wheel build/import, protocol checks, 26 Docker Makefile regressions, and pre-commit checks. A complete Docker image build was not run because the validation host had no Docker daemon.
On head
821aa7e, the CI, GPU Unit Tests, and Integration Tests workflows all completed successfully (rechecked 2026-10-16).pre-commit run --all-filespassesRelevant targeted pytest suites pass (scope and hardware evidence below)
New tests added (if applicable)
Documentation updated (if applicable)
Historical CPU HiCache performance (2026-09-15–16)
Qwen3.5-35B-A3B on one 8 × H20 host, two regular TP4 engines, SGLang 0.5.17 (
29481685462732237d80d86076d6563e1f658102), PyTorch 2.11.0+cu129, Ray 2.58.0. Each run completed 20 GRPO steps × 128 sessions, using the same initial weights, seed and training settings. Both used a 600,000-token GPU pool per engine.The treatment enabled CPU HiCache (
ratio=2,size=0,write_through,direct,page_first_direct, no storage backend) and changed page size from 1 to 64. These are historical observations from Relaxbc66c3384048afd74060529c30c2db0ebcf221fa, not a benchmark of head821aa7eor of the three new recipe layouts.Effective throughput is
sum(loss_mask) / sum(rollout wall seconds) / 8; tool-observation tokens are excluded, and per-step throughputs are not averaged. Total cache hit rate is weighted by repeated request prompt tokens, rather than averaged over sessions. Baseline prompt totals are reconstructed from per-step cached-token counts and hit rates. For the HiCache run, the reconstructed prompt, generated and cached totals also match the request counters: 1,220,350,844 prompt tokens, 22,165,623 generated tokens, 507,353,600 GPU-cached tokens and 662,292,928 CPU-cached tokens.CPU cache pools totaled approximately 476 GiB across all eight ranks. Container peak memory, including checkpoint saving, was 1,776.9 GiB against a 1,800 GiB limit; this is total task memory, not the cache allocation. Both runs completed 20/20 steps; recorded scalar metrics were finite.
Limits: one run per configuration, no independent repetitions, and generated trajectories differ. Page size and HiCache changed together, so their individual contributions cannot be separated. The baseline's extra first-step compilation is excluded from the steps 2–20 training-step comparison. Reward is reported as a guardrail, not evidence of equal model quality. Baseline request-level TTFT/TPOT and comparable continuous memory measurements are unavailable. Current regular-TP2/PD recipes have functional validation below, but no matched HiCache-off/on performance comparison is claimed.
Historical run provenance and per-step measurements
miniswe_rl20_20260915_124525; treatment:hicache_rl20_20260915_213500.baseline_metrics.safe.jsonandmetrics.safe.json; cross-checked withfinal_comparison.jsonand request counters.a330a5e53456f74326b62e8cf2b3cbf669a70dff8036fe7b5207ceeefd0d5de1.283850a5e76f89eb7382e8977ec89706652f97c0d373658d6b9ef28f63cc4c18.FP32 accumulation cost and current recipe validation (2026-10-14–15)
The fixed-size reduction change in ac0f148 was measured separately in A/B/B/A order: original BF16 accumulation versus FP32 accumulation with BF16 all-gather. Qwen3.5-35B-A3B, 8 × H20, 1P1D attention DP2 × TP2 / EP4; two warmup waves and six measured waves per workload per run. Across two runs per variant, each workload has 12 measured waves: 12 requests at concurrency 1, or 96 at concurrency 8. Each request generates 128 tokens. Cold inputs have 8,193 tokens; mixed inputs alternate 2,048/8,193 tokens.
With decode CUDA Graph enabled, aggregate service throughput and request latency were:
The eager control showed throughput changes of −0.89%, −1.61%, −1.36% and −1.75% for the same four workloads. Graph runs contain first-token spikes on both variants; all samples are retained. The apparent aggregate gains in two rows are not a general speedup claim: median-wave throughput fell by 0.15%, 1.50%, 2.34% and 1.28%, respectively. The concurrency-1 percentiles are descriptive statistics from only 12 requests.
These are service measurements at 16K context / 0.70 memory fraction, not full RL step measurements (32K / 0.75). Warm-prefix cases hit GPU-resident cache and do not measure CPU restoration. Original per-request records from all eight runs were rechecked on 2026-10-16 for matching input hashes and lengths, 128 output tokens, finite logprobs, and agreement with the recorded throughput/latency aggregates.
Functional evidence is separate:
821aa7e, the SGLang runtime patch sections were byte-identical to the validatedac0f148sections; that commit removed embedded test sections and added router packaging. The later variable-size reduction fix has separate validation below. All GPU evidence here is single-node; multi-node operation and other model families were not exercised.Variable-size BF16 reduction validation (2026-10-16)
e073fb4 extends FP32 accumulation to the shared
GroupCoordinator.reduce_scatterv. BF16 inputs and temporary reduction outputs use FP32; the result is copied into the original output buffer. Provided outputs, aliases, automatic allocation and the equal-size fallback retain their original shape/dtype contract. FP16/FP32 calls retain their existing buffers and collective dtype. The SGLang patch contains runtime changes only; tests live in Relax.[0,1,3,4]/[1,3,0,4]/ all-zero / equal-size fallback, and provided/allocated/aliased outputs. Each rank checks eager execution and three graph replays with changed inputs, including exact values, dtype, shape and output identity.pre-commit run --all-filespassed on the final candidate. GPU and CPU validation used an isolated runtime whose patchedparallel_state.pySHA256 is147254c964ecb0dea277de61346867c916499ccfbf1448a11a76961892c7568a.256, 1, -256, 0.5should sum to1.5. Before the fix, the three nonempty owners had maximum absolute errors0.5 / 1.5 / 1.0; after the fix every nonempty owner had zero error at all three measured row counts.Collective cost: one H20 host, four GPUs, PyTorch 2.11.0+cu129, CUDA 12.9, NCCL 2.28.9; BF16 tensors of shape
[N, 2048], owner splits[0, N/8, 3N/8, N/2]. Only thereduce_scattervimplementation differs between A (original BF16) and B (FP32 accumulation). Warmed A/B/B/A phases each contain 20 CUDA-event samples of 10 operations. For each sample, take the maximum elapsed time across the four ranks; the table reports the pooled median of the two phases per variant.The measured graph overhead is 5.57–11.89 μs per collective; it includes conversion, FP32 communication and copy-back. This is a hot-buffer microbenchmark, not model or RL throughput. Two phases per variant on one host do not establish cross-host variance. The largest case requires a calculated maximum of 3 MiB of additional FP32 input/output tensor storage per rank; this is not a measured model memory peak. Full-model TP4/DP4/EP4 training, multi-node behavior and symmetric-memory allocation were not exercised. The previous full-model fixed-size measurements above remain historical evidence for their original topology.
Variable-size benchmark provenance
Validation run:
relax-pr442-variable-7irtq0jv. Final patch/test hashes match the files in the linked commit. Benchmark script SHA256:9b06301521c084e8a7dd7b85bfa664f3224cf8d0d25e710c9f80998861c07a90.Per-rank raw timing JSON SHA256:
09cb57b7d68051ab666556233e0ac306766ea14caabe6124b7648820fe7cc5196c867c3a0f42359f3ee566ff33832e287392b866d46a0d095c6cb53d050302aafb5a5195044f1110cb3bd3a242f1b3bd83344c6e8acdc873075421010f9b05d37f5641b5e82eb2be6cedbc5a84927a2038625376fd93fa532fb902df19db871bType of Change
Screenshots / Logs