Repository navigation
Conversation
xiezhq-hermann
left a comment
There was a problem hiding this comment.
Thanks @koladefaj. This is a focused fix with a clear root cause and convincing before/after numbers. I checked it against current main (34f49c9):
- It merges cleanly. On the Rust side, the four new
host_eviction_*tests pass, andcargo testforsglang-radix-treepasses (969 tests). - The new Python test doesn't collect on current main. It imports
UnifiedLRUListandUnifiedTreeNodefromsglang.srt.mem_cache.unified_radix_cache, and #47990 (11-02) removed that re-export. With the import pointed atsglang.srt.mem_cache.unified_cache.unified_tree_core, all 4 tests pass with your change and all 4 fail on main, so they do pin the new order. - The existing Mamba and HiCache unit files I could run give identical results with and without the patch. The real-tree HiCache suites (
test_unified_radix_cache_hicache.py,test_unified_radix_cache_load_back.py) did not run cleanly in my environment on either tree, so CI is the check there.
Requests:
- Rebase and fix the import. Please rebase onto current main and fix that import.
mamba.pyalso changed after your base (among others #44718 host-only checkpoints and #47680), though without textual conflicts. A re-run of yourrepro.py 4comparison on the rebased branch would be good to have in the description. - Add one real-tree test. The Python test drives
MambaComponentagainst a_FakeTreeCorethat stubs_evict_component_and_detach_lruand_cascade_evict. So it checks the order, but not the symptom. Could you add one case on a realUnifiedRadixCachewith Full + Mamba and a host pool? The FULL_MAMBA classes intest/registered/unit/mem_cache/unified_radix_cache/test_unified_radix_cache_hicache.pyrun on both tree cores. For example: build a path with several host-only checkpoints plus an older tail, callevict_host, and assert thatmatch_prefixstill returns the host hit up to the tail. - A question on
_is_pass_through_checkpoint. It also counts a child whose Mamba state is on device only. That is what lets the sweep make room while the next checkpoint is being backed up. But the child might later be evicted from the device without a host copy, for example underwrite_through_selectivebefore its second hit, or when its backup can't get a host slot. Then the path loses both states, and the host hit falls back to an earlier ancestor. Is that reachable in practice? If you keep the device case on purpose, a short comment explaining why would help.
On #45400: #48431 (opt-in, request-end-only Mamba backups) attacks the same symptom at write time, and the two PRs merge cleanly together. We'd like this PR to be the primary fix for #45400, and to evaluate #48431 on top of it. @MarlzRana, if your 2048-chunk / 400 s / 16-agent workload can run against this branch, that would be a useful second data point.
After the rebase we can run CI.
f3796ab to
864dda0
Compare
|
Thanks @xiezhq-hermann, all three are addressed. The branch is rebased onto current main (
Verification, on 1x RTX PRO 6000 Blackwell Server Edition, image
The real-tree suites run cleanly there. On my laptop they failed on both trees (host-memory preflight, then a CUDA illegal address on an 8 GB 4060), including Full-only configs this PR doesn't touch, so I think that was the environment.
All 16 answers are correct. Cold requests take 17.0–18.2 s on both trees. @MarlzRana, a run of your 2048-chunk / 16-agent workload against this branch would still be welcome. |
|
Thanks @koladefaj, all three points are addressed: the real-tree FULL_MAMBA test now fails on main on both tree cores ( |
|
Here they are @xiezhq-hermann and @koladefaj: Tested this on a different setup from the PR's, with a before/after/control comparison. It fixes the zero-hit symptom from #45400 there tool. Setup
Results (single runs; cells are the four re-asks, in order)
The stock Rust and stock Python runs behave the same, so the Python core is not what changes the result. The unpatched backup count (397) is close to the issue's 394 for With Not covered
|
Motivation
Fixes #45400.
On a hybrid GDN model with
--enable-hierarchical-cache, host-tier hits drop to zero once the evicted working set is a few long prefixes larger than the device pool. The KV pages are still on host, but identical requests getcached_tokens: 0and a full recompute.A host prefix hit ends at the deepest node on the matched path that still has a Mamba state (device or host). Host Mamba eviction (
drive_host_eviction) is plain LRU, and a long prefill backs up many chunk checkpoints along one path. With few host Mamba slots, newer intermediate checkpoints evict the tail states of earlier documents, so their host KV is left with no usable Mamba state.--mamba-max-states-per-pathdoesn't help, because it only trims device states after they've been backed up.Modifications
unified_cache/components/mamba.pyandrust/sglang-radix-tree/src/components/mamba.rs: host Mamba eviction now runs in two LRU passes. The first pass evicts only pass-through checkpoints (a node with one child that holds its own Mamba state on host). A device-only child doesn't count, because it can leave the device without a host copy (write_through_selectivebefore its threshold, or a backup that finds no host slot). The second pass, which runs only if the first one didn't free enough, is the existing LRU order. Path tails, forks, and states whose child has no host state are kept until no pass-through checkpoint is left, so each path keeps the state its host hit ends at. This matches what_evict_excess_path_statesalready preserves on device.The Python and Rust cores get the same change.
components/README.md: describes the new order underdrive_host_eviction().Tests, in both cores:
Python:
test/registered/unit/mem_cache/test_mamba_host_eviction_order.py(CPU). Rust:rust/sglang-radix-tree/src/tests/components/mamba.rs.Real-tree test:
test_hicache_mamba_host_eviction_keeps_path_tailsintest_unified_radix_cache_hicache.py(FULL_MAMBA, both tree cores). It builds an older single-state path and a multi-checkpoint path, makes every state host-only, evicts one host Mamba state, and asserts that both paths keep their full host hit. It fails on main on both cores and passes with this PR.Accuracy Tests
Answers are unchanged: all 24 responses across the three runs below return the correct passphrase. This change only affects which host Mamba states are evicted, not model outputs.
Speed Tests and Profiling
1x NVIDIA RTX PRO 6000 Blackwell Server Edition, driver 595.91.07, image
lmsysorg/sglang:nightly-dev-cu13-20261029-c10e0e17. The sglang tree was checked out at this PR's base (97483164) for "before" and at this commit for "after", with the Rust core rebuilt for each. Modelnvidia/Qwen3.8-27B-NVFP4, launched with the flags from the issue minus PP and EAGLE:Host pools: 396,247 KV tokens and 26 Mamba state slots. Client:
repro.py 4from the issue (4 × ~89k-token documents, then an identical re-ask of each), with a fresh server per run.Rebased re-run (2026-11-10)
Same GPU and flags. Image
lmsysorg/sglang:nightly-dev-cu13-20261110-4a5c6b8f, trees set to exactly maine0187268f6and this PR. I deleted the image's prebuilt tree-core.soand setSGLANG_RUST_BUILD_MODE=auto, so each tree ran its own Rust core.e0187268f6cached_tokensper re-askprefill_effective_tokens_total{mode="host_hit"}hicache_backup_tokens_total{pool="mamba"}hicache_host_used_tokenscargo test(sglang-radix-tree)test_unified_radix_cache_hicache.py+_load_back.py(Python core)test_unified_radix_cache_rust.py(Rust core)All 16 answers are correct.
Original run (base
97483164)cached_tokensper re-askprefill_effective_tokens_total{mode="host_hit"}hicache_backup_tokens_total{pool="mamba"}hicache_host_used_tokensBefore (main
97483164, Rust core)After (this PR, Rust core)
After (this PR, Python core,
SGLANG_UNIFIED_RADIX_TREE_CORE_BACKEND=python)Columns: label, prompt tokens, request time (s),
cached_tokens, answer. Cold requests take about 17 s in every run.Follow-up
Once no pass-through checkpoint is left, eviction falls back to plain LRU, so tails can still be evicted under heavy pressure, for example branch-heavy sub-agent workloads. A minimum-token-distance rule for keeping pass-through checkpoints is being discussed in the issue. This PR keeps to the reproduced case.
Checklist
CI States
Latest PR Test (Base): ✅ Run #42798150683
Latest PR Test (Extra): ✅ Run #42798150491
Latest PR Test (AMD ROCm 10): ❌ Run #42798150512
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: