Skip to content

[Fix] radix-cache: Order linker offloads behind the forward that writes the pages - #45559

Merged
hnyls2002 merged 5 commits into
mainfrom
lsyin/linker-offload-forward-stream
Oct 21, 2026
Merged

hnyls2002 merged 5 commits into
mainfrom
lsyin/linker-offload-forward-stream

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator
  • Mooncake and mori linker offloads now record one event on the scheduler's stream (the page indices) and one on the forward stream (the forward writing the pages), and the offload thread synchronizes both, so it reads a stashed chunk's KV only after that forward. The forward stream's own order is unchanged.
  • Prefill read-done is on by default since [Perf] prefill-cuda-graph: Make prefill shared-read completion explicit and default-on #37958. With TRTLLM MHA prefill or DeepSeek V4 (no CP, no HiSparse), the scheduler's stream then waits only on the forward's pre-replay read-done, so an offload event recorded on it alone can let the copy read KV the forward is still writing. The read-done gate turns the fast path off for HiCache, storage backends, and LMCache, but not for the external linker.
  • The registry passes the model runner's forward stream to the linker, as it already does for LMCache.
  • Adds unit tests for the two events, the Mooncake offload thread waiting on both, and the registry wiring.

No behavior change without the external linker. Found by code reading; not reproduced on main.


CI States

Latest PR Test (Base): 🚫 Run #39674091665
Latest PR Test (Extra): ❌ Run #39674091561
Latest PR Test (AMD ROCm 10): 🚫 Run #39674091472

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_unified_cache_linker.py test_unified_cache_linker_kl_dsv4.py test_unified_cache_linker_kimi_linear.py test_unified_cache_linker_kl_inkling.py test_unified_cache_linker_kl_glm52.py test_unified_cache_linker_kl_dsv41.py test_umbp_direct_linker_rank_keys.py test_registry.py test_linker_pool_assembler.py

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-5090 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_unified_cache_linker.py

🚀 4-gpu-h100 (3 tests): ✅ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/linker/test_unified_cache_linker_kl_dsv4.py
cd test/ && python3 registered/radix_cache/unified_radix_tree/linker/test_unified_cache_linker_kimi_linear.py
cd test/ && python3 registered/radix_cache/unified_radix_tree/linker/test_unified_cache_linker_kl_inkling.py

🚀 8-gpu-h200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/linker/test_unified_cache_linker_kl_glm52.py
cd test/ && python3 registered/radix_cache/unified_radix_tree/linker/test_unified_cache_linker_kl_dsv41.py

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_umbp_direct_linker_rank_keys.py
cd test/ && python3 registered/unit/mem_cache/test_registry.py
cd test/ && python3 registered/unit/mem_cache/test_linker_pool_assembler.py

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 21, 2026
@lixiufei-leo

Copy link
Copy Markdown
Contributor

Same fix for the UMBP linker: #45479 records a second event on the forward stream and the offload thread waits on both, as #45559 does. #45559 also covers Mooncake, so I'm happy to close #45479 in favour of it. A few notes:

  • On ROCm the coarse WAR barrier is off by default (_war_barrier_enabled = is_cuda() or SGLANG_ENABLE_WAR_BARRIER), so the race shows up there whenever a chunk is offloaded while its forward is in flight, independent of the read-done fast path. We reproduced it on MI355X (DeepSeek-V4-Pro 1P1D, UMBP linker, agentic c256, on 1e86143). A diagnostic that flags offloaded rows whose last layer is still mostly unwritten at copy time counted 61.2% of 4.53M offloaded rows incomplete without the fix and 0 of 4.56M with it. On the same node pair the decode step went from 49.69 to 47.71 ms.
  • The new tests check that both events are recorded and awaited, not the ordering itself. test_umbp_direct_linker_offload_ordering.py in [Fix] umbp: Order direct-linker offload copies after the forward that produced the KV #45479 runs a forward that is still writing a page on another stream and checks the offload reads the written values. Without the forward-stream event the copy reads the pre-forward contents; with it the test passes on MI355X. I can move it into [Fix] radix-cache: Order linker offloads behind the forward that writes the pages #45559.
  • Not for this PR, but possibly related: on ROCm the HiCache write-through D2H copy also waits only on the scheduler stream ([Fix] hicache: Order write-back host copies after the forward that produced the KV #44800 fenced only the blocking write-back drain), and linker loads record their ready event only on the scheduler stream, while HiCache loads use load_fence_stream. We did not see a measurable effect from fencing linker loads, so I'm only flagging these.

Co-authored-by: lixiufei-leo <[email protected]>
@hnyls2002
hnyls2002 merged commit 2c7a9e3 into main Oct 21, 2026
67 of 83 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/linker-offload-forward-stream branch October 21, 2026 20:53
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
…k-274, wanted_stack LANDED marks, CAVEATS docs-only ledger items

(A) Header: STACK line 260->274; three wave lines (+spec-mamba-2026-10-28
(pr45491+pr45435+pr45472+pr45670), +admission-2026-10-28(pr46272*+
pr43484*+pr46496*+pr46643*+pr45607*+pr45789*), +parsers-2026-10-28
(pr44124+pr45631+pr45855+pr46167)); tip line -> 2714457; updated
261-274 headline block (entry-119 SUPERSEDED by upstream sgl-project#45435/sgl-project#45472;
classic-pool mamba admission gate w/ upstream ImportError CAUGHT;
UNCONDITIONAL latch reset = TTFT watch; coder-parser union; logits
trilogy as CONTRACT UNIT; 14 picks, 0 integrator conflicts).

(B) wanted_stack.txt: FAM-A5 + FAM-B234 blocks deleted -> LANDED records
(chain shas, interlock audit, supersession + behavior-change pointers
into entries 261-270); SECTION-B sgl-project#44124/trilogy blocks -> LANDED;
sgl-project#37958/sgl-project#45559 block -> DONE (verdict now in CAVEATS).

(C) DOCS-ONLY LEDGER ITEMS: CAVEATS gains the sgl-project#37958/sgl-project#45559 VERIFIED-
INERT bullet (two independent hard gates, coarse-barrier fallback,
do-not-re-litigate-at-merge-sgl-project#5 line, revisit condition = dropping NEXTN
or HiCache) and the dated C0b/C0c corrections (sgl-project#44030 obsolete rationale,
sgl-project#44858 REVERSED by sgl-project#45289 [ported-pending wt-moe], sgl-project#44115 permanent N/A,
10-28 open-status re-verification list, no-pin-moves note: 0.7.2/0.4.9
floor unchanged) with the C0a tick (sgl-project#37625/sgl-project#37941/sgl-project#39727 still
outstanding; only sgl-project#43927/sgl-project#44849 partially satisfied). C0b/C0c/C8 marked
DONE in wanted_stack; C0a stays open.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hicache Hierarchical Caching for SGLang run-ci CI: run the baseline test suite on this PR unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants