Skip to content

feat(rollout): enable CPU HiCache for regular and PD rollouts - #442

Merged
yuanlehome merged 7 commits into
redai-studio:mainfrom
yuanlehome:feat/pd-hierarchical-cache-miniswe
Oct 16, 2026
Merged

yuanlehome merged 7 commits into
redai-studio:mainfrom
yuanlehome:feat/pd-hierarchical-cache-miniswe

Conversation

@yuanlehome

@yuanlehome yuanlehome commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Four regular TP2 engines (default).
  • Two prefill and two decode TP2 engines, with CPU cache on prefill.
  • One prefill and one decode engine, each using attention DP2 × TP2 and EP4, with CPU cache on prefill.

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

  • Extend the SGLang v0.5.17 patch to poll HiCache completion events while regular and prefill engines are paused, and finish deferred backups of protected Full KV/Mamba checkpoints.
  • Patch the R3-capable router to use physical HTTP/bootstrap endpoints while retaining virtual DP worker identities. Send independent routed_dp_rank values to prefill and decode, plus disagg_prefill_dp_rank to decode, while preserving native fields such as routed_experts. Accept the legacy data_parallel_rank alias in SGLang.
  • Accumulate BF16 DP MoE reductions in FP32 in both fixed-size dp_reduce_scatter_tensor and GroupCoordinator.reduce_scatterv, then copy back to the original output dtype/buffer. Preserve FP16/FP32 behavior and BF16 attention-TP all-gather.
  • Build and install the patched router in both CUDA Dockerfiles using a separate builder stage, pinned source/toolchain, a checked-in Cargo lockfile, and recorded build provenance. The wheel is installed after Python requirements, including with an external TRAIN_IMAGE.
  • Reuse the existing Mini SWE Ray driver through run_mini_swe_agent_hicache.sh; select regular or PD deployment with HICACHE_DEPLOYMENT and YAML overrides.

Validation scope: the BF16 precision fix covers fixed-size dp_reduce_scatter_tensor and the shared GroupCoordinator.reduce_scatterv used 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-files passes

  • Relevant 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 Relax bc66c3384048afd74060529c30c2db0ebcf221fa, not a benchmark of head 821aa7e or of the three new recipe layouts.

Metric HiCache off, page 1 CPU HiCache, page 64 Change
Mean rollout wall time, all 20 steps 789.51 s 511.54 s -35.2%
Effective rollout tokens/s/GPU 176.79 270.82 +53.2%
Mean complete training-step time, steps 2–20 21.69 min 17.04 min -21.4%
Prompt-weighted GPU + CPU cache hit rate 43.97% 95.85% +51.88 percentage points
CPU-sourced cached tokens / prompt tokens 0% 54.27% +54.27 percentage points
Effective generated tokens 22,332,636 22,165,623 −0.75%
Mean training-batch reward 0.296094 0.280859 −0.015234
Truncated sessions 8.95% 8.16% −0.78 percentage points

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
  • Baseline run: miniswe_rl20_20260915_124525; treatment: hicache_rl20_20260915_213500.
  • Recomputed on 2026-10-16 from all 40 per-step records in baseline_metrics.safe.json and metrics.safe.json; cross-checked with final_comparison.json and request counters.
  • Baseline metric-file SHA256: a330a5e53456f74326b62e8cf2b3cbf669a70dff8036fe7b5207ceeefd0d5de1.
  • HiCache metric-file SHA256: 283850a5e76f89eb7382e8977ec89706652f97c0d373658d6b9ef28f63cc4c18.
Step Baseline rollout (s) HiCache rollout (s) Baseline effective tokens HiCache effective tokens
1 918.228 563.255 1252259 1238914
2 887.809 540.680 1248651 1214523
3 815.595 517.580 1137579 1143593
4 825.770 530.467 1120928 1130983
5 953.043 530.630 1177287 1121302
6 741.876 460.215 962820 972387
7 935.527 588.006 1187624 1257136
8 869.148 546.293 1219651 1258309
9 794.318 535.501 1184223 1242051
10 1172.942 585.405 1165846 1225199
11 712.514 501.640 1114923 1145705
12 845.725 509.288 1075783 1069634
13 874.168 557.377 1196863 1213828
14 733.726 508.130 1092005 1114104
15 707.775 488.905 1140681 1116018
16 418.847 411.954 900790 852007
17 562.429 389.060 883626 800680
18 657.198 491.145 1168824 1101992
19 822.649 544.883 1096445 1056183
20 540.904 430.483 1005828 891075

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:

Workload Output tokens/s, BF16 → FP32 Throughput change TPOT P50 (ms), BF16 → FP32 E2E P95 (s), BF16 → FP32
cold c1 111.61 → 114.17 +2.29% 5.950 → 6.002 1.234 → 1.137
cold c8 416.49 → 398.98 -4.20% 5.865 → 5.987 2.546 → 2.586
warm c8 817.11 → 795.99 -2.58% 7.272 → 7.463 1.796 → 1.889
mixed c8 442.22 → 447.41 +1.17% 6.784 → 6.844 2.505 → 2.269

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:

  • Regular 4 × TP2, PD 2P2D TP2, and PD 1P1D attention DP2 × TP2 / EP4 each completed three RL cycles and exported 24 sessions in the 2026-10-14 validation. The 2P2D run included one valid context-limit truncation.
  • After the FP32 fix, the DP2 recipe again completed three RL cycles / 24 sessions; all 822 response turns matched the requested P/D owners and bootstrap metadata, with weight versions 1→2→3 and final gradient norm 0.439274.
  • Six forced CPU restores, across both DP owners and pause/flush/rebuild boundaries, each recovered 8,192 logical prefix tokens. Restored outputs matched their same-owner cold references with maximum absolute logprob difference 0. Three cross-owner cold comparisons also had zero measured logprob difference after the fix. These finite cases do not establish universal bitwise equivalence.
  • The real four-GPU collective/CUDA Graph suite passed 112 checks. At 821aa7e, the SGLang runtime patch sections were byte-identical to the validated ac0f148 sections; 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.

  • 219 related CPU tests passed, including 124 reduction cases, native DP-rank compatibility, CPU HiCache arguments, router registration and Mini SWE recipe checks. Targeted reverse checks fail as expected when removing the promotion, promoting only the input, omitting the copy-back, or incorrectly skipping an empty owner.
  • Real four-GPU NCCL/CUDA graph regression passed on TP = attention DP = EP = 4, with the direct-MoE topology predicate enabled. It covers 36 combinations of BF16/FP16/FP32, splits [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-files passed on the final candidate. GPU and CPU validation used an isolated runtime whose patched parallel_state.py SHA256 is 147254c964ecb0dea277de61346867c916499ccfbf1448a11a76961892c7568a.
  • In the real-NCCL cancellation control, per-rank contributions 256, 1, -256, 0.5 should sum to 1.5. Before the fix, the three nonempty owners had maximum absolute errors 0.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 the reduce_scatterv implementation 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.

Total rows N Eager μs/op, BF16 → FP32 Eager change CUDA graph μs/op, BF16 → FP32 Graph change
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%

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:

  • rank 0: 09cb57b7d68051ab666556233e0ac306766ea14caabe6124b7648820fe7cc519
  • rank 1: 6c867c3a0f42359f3ee566ff33832e287392b866d46a0d095c6cb53d050302aa
  • rank 2: fb5a5195044f1110cb3bd3a242f1b3bd83344c6e8acdc873075421010f9b05d3
  • rank 3: 7f5641b5e82eb2be6cedbc5a84927a2038625376fd93fa532fb902df19db871b

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

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.
@yuanlehome
yuanlehome requested review from a team and a balanced review from Copilot October 15, 2026 11:37
@rai-studio-bot

rai-studio-bot commented Oct 15, 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 / 状态
审批人数 ✅ 1/1 · 至少 1 位有仓库 write 或更高权限的人 Approve · 已审批:DrRyanHuang
团队审批(relax-block-reviewers) ⏳ 0/1 · 可联系:Aurelius84, Yangruipis, SigureMo, NINGBENZHE
CI ✅ 已通过

@yuanlehome yuanlehome changed the title feat(cache) feat(cache): enable CPU HiCache for regular and PD rollouts Oct 15, 2026
@rai-studio-bot

rai-studio-bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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)当前无失败实例。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已检查:中英文 CPU 缓存文档与侧栏注册、示例 README 与启动脚本、tests/examples 示例回归、配置 last-wins 组合、dp_aware 路由接线、被回退的 SSD/file 模式无残留引用;文档声明已对照 pristine sglang 0.5.17 验证。e073fb42 增量未触及这些范围。无发现。
深度审查 ✅ 已完成 三路 scoped 调查完成并经父级交叉复核:① HiCache 暂停排空与 Mamba 延迟 chunked 备份不变量成立(无 P1/P2;F2 无节流轮询、F3 decode/flexkv 覆盖不对称两项 P3,作者已在 PR 正文确认范围);② BF16 FP32 累加:e073fb42 将修复扩展至共用 GroupCoordinator.reduce_scatterv(单点覆盖 5 个调用方,生产调用均显式传 sizes),选定 CPU 用例通过且对 pristine 基线复现突变失败;四卡 NCCL/graph 与性能数据为作者报告(本地无 GPU);③ 构建管线端到端实测通过。

审查发现

待处理
编号 严重性 问题状态规则来源
F2 Low severity 暂停轮询无节流:长时间权重更新暂停期间无上界速率自旋 gloo 集合通信 🚧 未解决 —
F3 Low severity 暂停泵覆盖不对称:disagg decode 暂停分支与 flexkv-only 配置未纳入 🚧 未解决 —
F5 Low severity ROUTER_SOURCE_ARCHIVE 离线构建覆盖未写入 README 🚧 未解决 —
F7 Low severity test_cpu_hicache_args 未固定"未知 override 键直接传入"契约 🚧 未解决 —
已解决或已取代
编号 严重性 问题状态规则来源
F1 Medium severity 可变长度 reduce_scatterv 的 DP MoE combine 仍按 bf16 累加(提交声称修复的同类路径,TP=DP=EP 拓扑可达) ✅ 已解决 —
F4 Low severity data_parallel_rank→routed_dp_rank 迁移随内嵌测试剥离失去唯一测试覆盖 ✅ 已解决 —
F6 Low severity BF16 测试 mock 不校验被归约缓冲的内容/形状契约,错误缓冲区类回归可通过 ✅ 已解决 —
提交范围 · 接收 20 · 建议移出 0 · 待确认 0

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

文件结论仓库维护必要性依据替代去向或方案
docker/patch/sglang/v0.5.17.patch
接收 PR 的运行时行为全部落在既有的 SGLang 镜像补丁机制内(HiCache 暂停期完成轮询、Mamba 受保护 chunked 检查点的 CPU 备份、io_struct 旧 DP-rank 字段兼容、BF16 DP 归约 FP32 累加);e073fb42 在共用 GroupCoordinator.reduce_scatterv 扩展 FP32 提升,覆盖全部变长调用方。 分支名 feat/pd-hierarchical-cache-miniswe 与各提交说明;补丁在 merge-base 已存在,是仓库既定机制。 改为升级/替换安装的 sglang 版本不可行(0.5.17 为 pinned 依赖);不改补丁则 PD DP 路由与变长归约精度修复无法成立。
docker/Dockerfile
docker/Dockerfile.cu13
接收 两份镜像(cu12/cu13)定义补丁应用与镜像内路由构建的相同阶段;Dockerfile 是镜像构建的唯一入口。 镜像构建是补丁 sglang/路由的部署契约。 无共享 include 机制,仓库约定为层内重复。
docker/patch/sglang-router/v0.3.2-9daabcd-pd-dp-aware.patch
docker/patch/sglang-router/v0.3.2-9daabcd-Cargo.lock
docker/scripts/build_sglang_router.sh
接收 用受管源码构建替代第三方预编译 wheel:固定上游 commit + 归档 SHA256 + 补丁 + 锁定 Cargo.lock,镜像内验证版本与来源指纹;1P1D attention-DP2 配方依赖该 PD DP-aware 路由。e073fb42 增量未触及此管线。 提交 821aa7e 与 docker/patch/sglang-router/README.md;examples/mini_swe_agent/README.md 的 1P1D 配方引用该补丁。 预编译 wheel 无 PD DP-aware dispatch;上游 PR 路径周期不受控。
docker/patch/sglang-router/README.md
接收 路由构建文档;离线构建覆盖(F5)仍为开放建议。 ROUTER_SOURCE_ARCHIVE 离线构建路径。 内联 Dockerfile 注释可发现性更差。
docs/.vitepress/config.mts
docs/en/guide/hierarchical-cache.md
docs/zh/guide/hierarchical-cache.md
接收 CPU HiCache 能力的中英文用户文档并注册侧栏;文档选项与行为已对照 pristine sglang 0.5.17 验证,是合入后必须维护的用户契约。 docs/.vitepress/config.mts 的 guide 侧栏;HiCache CPU 配方被示例配置引用。 并入 examples README 会失去站点导航与中英对照。
examples/mini_swe_agent/README.md
examples/mini_swe_agent/hicache-cpu-4x-tp2.yaml
examples/mini_swe_agent/pd-hicache-cpu-1p1d-dp2-tp2-ep4.yaml
examples/mini_swe_agent/pd-hicache-cpu-2p2d-tp2.yaml
examples/mini_swe_agent/run_mini_swe_agent_hicache.sh
接收 既有用户级示例目录内新增 CPU 缓存常规/PD/1P1D-DP2 三种拓扑配方与统一入口脚本,复用既有 PD 驱动;tests/examples 直接回归脚本与 YAML。 目录内既有 pd-2p2d-tp2.yaml 与 run_mini_swe_agent_pd.sh(merge-base 已存在)。 YAML 内联进文档会失去可直接提交的配方与测试锚点。
tests/backends/sglang/test_cpu_hicache_args.py
tests/backends/sglang/test_dp_moe_reduce_scatter.py
tests/backends/sglang/test_native_dp_rank_compat.py
tests/backends/sglang/test_reduce_scatterv_gpu.py
tests/examples/test_mini_swe_hicache.py
接收 补丁行为没有 relax/ 生产入口,仓库需要直接针对补丁源码的回归:CPU 测试 AST 提取真实补丁函数执行(归约测试 124 项),GPU 测试以 skipif 守护四卡真实 NCCL/CUDA graph,CI 镜像内全部解析到补丁源码。回应审查发现 F4/F6 与 P2 的扩展提升选项。 relax CI 从不运行 sglang 内嵌测试;unittest.yml 镜像含 docker/patch/**。 留在补丁内嵌不可行(CI 不运行);不补测试则补丁回归无守护。
精简审查与验证依据
审查范围进度结论
生产代码 ✅ 已完成 净 diff 不含 relax/ 生产代码;生产行为全部经既有补丁 + 镜像内构建机制交付。e073fb42 的修复置于共用集合通信实现(单点覆盖 5 个调用方)而非各调用点复制,无新增抽象。无已发布的简化发现。
测试 ✅ 已完成 四个测试均为最小源码级契约测试;test_dp_moe_reduce_scatter 经 e073fb4 扩展为 AST 执行真实补丁 reduce_scatterv(124 项),test_reduce_scatterv_gpu 以 skipif 守护四卡 NCCL/graph 覆盖。补丁内嵌测试剥离经核验合理。

生产代码的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
sglang v0.5.17 补丁与路由器源码构建管线 pinned sglang 0.5.17 上的 PD DP-aware 路由、CPU HiCache 暂停排空、Mamba 受保护 chunked 备份、BF16 归约精度 上游 PR 或更换 sglang 版本(0.5.17 pinned、周期不受控);下载预编译 wheel 保留 fork release v0.3.2-9daabcd 无 PD DP-aware dispatch(README + fork 源码核验);R3 端到端构建实测通过
Dockerfile/Dockerfile.cu13 约 20 行构建器阶段重复 两份镜像(cu12/cu13)需要相同的 router_builder 阶段 共享 provisioning 脚本 保留 docker build 无 include 机制;仓库约定为层内重复(int4_qat/FLA/Megatron 块同样重复);可共享部分(源码构建脚本)已共享

测试的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
tests/backends/sglang 四个新测试文件 固定 relax 既有契约(decode 跳过 + override 优先级)、补丁行为、启动脚本组合 删除或并入更大套件 保留 源码级、无 GPU 依赖;CPU 用例通过;BF16 用例对补丁源通过、对 pristine 失败(可捕获回归)
补丁内嵌的 4 个 sglang 测试段 sglang 树内部用例(含 test_native_dp_rank_compat.py) 保留在补丁中 删除 Relax CI 从不运行 sglang 内嵌测试(unittest.yml 仅跑 repo tests/);运行时 hunk 逐字节不变,覆盖损失已作为 P3 行内记录
Powered by Nyanpasu with glm-5.3-flash max, please check the suggestions carefully.

@yuanlehome yuanlehome changed the title feat(cache): enable CPU HiCache for regular and PD rollouts feat(rollout): enable CPU HiCache for regular and PD rollouts Oct 15, 2026

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.

🔵 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 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.

审查结论

本 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.dpaware wheel,通过 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-config last-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 测试执行(仅编译验证)等结论来自源码级核验,已在相应评论中注明。
Powered by Nyanpasu with glm-5.3-flash max, please check the suggestions carefully.

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

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.

[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。它经 pynccl ncclReduce 链在输入 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 说明中记录可变长度路径豁免的理由。

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.

已在 PR 描述的 Validation scope 中记录可变长度 reduce_scatterv 路径保留上游行为的依据,与本审查核实的拓扑门控一致(直接 MoE 路径要求全局 TP = attention DP = EP,本 PR 各配方均不满足),并明确声明并非修复所有 BF16 DP 归约——该 P2 的第二项建议(记录豁免依据)已满足,标记为解决。剩余选项(将 fp32 提升扩展到 reduce_scatterv,需独立的拓扑/空 owner/CUDA graph 验证)留待后续有该拓扑需求时再评估。

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.

已在 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 描述已保留历史端到端性能数据,并单独列出本次测量方法、范围和数据校验值。

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.

已独立复核,该 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 输入/输出逐 chunk ncclReduce,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.

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.

[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()

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.

[P3] 暂停泵覆盖不对称:disagg decode 分支与 flexkv-only 配置未纳入

同一停顿前提(in-flight GPU/CPU DMA 未排空导致 is_fully_idle 永不成立、flush_cache 持续被拒)还存在于两类未覆盖路径:

  1. disagg decode 暂停分支:srt/disaggregation/decode.py 的暂停分支为裸 continue。enable_decode_hicache 是受支持的 decode 模式(正常路径存在对应的 check_hicache_events 泵),暂停时 ongoing_load_back 永不排空。PR 配方关闭了 decode hicache,故当前配方未踩到,但提交信息的理由同样适用于此。
  2. 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

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.

[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。

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.

已在 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 集成或性能实验。

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.

已独立复核,该 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" \

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.

[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):

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.

[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 契约。

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.

已在 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 或共享运行源码。

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.

已独立复核,该 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

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.

[P3] 未固定"未知 override 键"的行为契约

_compute_server_args 的 sglang_overrides 循环对任意键无条件赋值(与 _compute_genrm_server_args 的 warn-and-drop 不同),YAML 键名拼写错误会在引擎启动时以 TypeError 暴露。本 PR 三个 YAML 的全部 override 键已验证有效,但新测试未固定这一契约。

建议:补一个含伪造键的用例,明确文档化"override 键会被直接传入 ServerArgs"的行为,避免未来靠启动期报错才发现拼写问题。

DrRyanHuang
DrRyanHuang previously approved these changes Oct 16, 2026

@DrRyanHuang DrRyanHuang left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

牛哇牛哇!后面有空的话可以在 PR 描述里补充一下实测的性能量化指标(如 Mini-SWE 场景下开启 CPU HiCache 后的缓存命中率、单步 rollout 端到端耗时对比啥的

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 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.

复审结论(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 键直接传入"契约。
Powered by Nyanpasu with glm-5.3-flash max, please check the suggestions carefully.

@SigureMo SigureMo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTMeow 🐾

@yuanlehome
yuanlehome merged commit b2b0bb0 into redai-studio:main Oct 16, 2026
21 checks passed
@apex-mochen apex-mochen mentioned this pull request Nov 16, 2026
2 of 18 tasks
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.

5 participants