Skip to content

[Fix] radix-cache: Separate logical and reclaimable value lengths in tree components - #45238

Merged
cctry merged 1 commit into
mainfrom
oss-sync-3cc5dd45b8
Oct 20, 2026
Merged

cctry merged 1 commit into
mainfrom
oss-sync-3cc5dd45b8

Conversation

@metamergebot

@metamergebot metamergebot commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

A tree node's device value has two lengths that the tree cores treated as one: the logical length of the stored index tensor, which slicing, prefix matching and collect_path_info spans read, and the number of allocator slots the pool gets back when the value is evicted, which the evictable/protected ledgers count. A component whose backing is released or shared under a value can occupy fewer pool rows than the logical value describes, and the ledgers then drift from what the allocator actually reclaims: prefill admission adds the evictable ledger to the allocator's free space and the eviction walk counts it toward its request, so both over-report.

Modifications

  • Python: TreeComponent.reclaimable_tokens becomes reclaimable_value_len, and every ledger site in the Full, SWA and Mamba components (insert, lock, release, materialize, evict, recount) reads it instead of len(value). value_len stays the logical length.
  • Rust: Node gains device_reclaimable_value_len, zero for roots and absent values, and the same ledger sites in the Full, SWA and Mamba components and the core use it instead of device_value_len or the tensor's first dimension. The SWA component's private value_len helper goes away.
  • adjust_component_size rejects a delta that would drive a ledger negative with ValueError and leaves the counters untouched, on both cores; the interface docstring says so.
  • evict_device_next_node reports progress when a step freed device or host backing even though no node was consumed, so an eviction walk over zero-accounted nodes keeps going instead of stopping early.

Nothing changes for components whose reclaimable length equals the logical one, which is every in-tree component today.

Accuracy Tests

Not applicable: no model or kernel numerics change.

Benchmarking and Profiling

Not applicable: the ledger sites already called a per-node accessor; this changes which one.

Checklist

  • Rust: cargo test --lib in rust/sglang-radix-tree, including the new tests/node.rs assertions.
  • Python: test/registered/unit/mem_cache/test_rust_tree_core_integration.py, test_unified_radix_cache_unittest.py, test_tree_core_registry.py and test_swa_locked_full_recover_unified.py on both tree-core backends.
  • pre-commit (isort, ruff, ruff-format, codespell, rustfmt) clean on the touched files.

CI States

Latest PR Test (Base): ✅ Run #39394107972
Latest PR Test (Extra): ❌ Run #39394107869
Latest PR Test (AMD ROCm 10): ❌ Run #39394108029

…tree components

A tree node's device value has two lengths that happened to coincide:
the logical length of the stored index tensor, used for slicing, prefix
matching and path spans, and the number of allocator slots handed back
when the value is evicted, used by the evictable/protected ledgers.
A component whose backing is released or shared under a value can
occupy fewer pool rows than the logical value describes, and the
ledgers then drift from what the allocator actually gets back.

Keep the two apart in both the Python and the Rust tree cores:

- Python: TreeComponent.reclaimable_tokens becomes
  reclaimable_value_len, and every ledger site in the Full, SWA and
  Mamba components (insert, lock, release, materialize, evict, recount)
  reads it instead of len(value). value_len stays the logical length.
- Rust: Node gains device_reclaimable_value_len, zero for roots and
  absent values, and the same ledger sites in the Full, SWA and Mamba
  components and the core use it instead of device_value_len or the
  tensor's first dimension. The SWA component's private value_len
  helper goes away.
- adjust_component_size rejects a delta that would drive a ledger
  negative with ValueError and leaves the counters untouched, on both
  cores; the interface docstring says so.
- evict_device_next_node reports progress when a step freed device or
  host backing even though no node was consumed, so an eviction walk
  over zero-accounted nodes keeps going instead of stopping early.

Tests cover the Rust node accessor, the negative-delta rejection, a
Full component with side backing across lock transitions and a locked
split, and Python SWA/Mamba components whose reclaimable length differs
from the logical one through lock/release and internal eviction.

Co-authored-by: Jialin <[email protected]>
@metamergebot

Copy link
Copy Markdown
Collaborator Author

This port clears our bar on a887748f2f8109d32658315c305741c4fdda1702: every base-a and base-b job is green.
base-c and the accelerator suites are reported but not gated, because they run
on scarce hardware and upstream merges through them routinely.

gate✓ lint✓ build 4✓✗1✂1 A✓ B✓ C 0/14⏳ other✓ · accel ✗amd,npu

@fei-xx @merrymercy @Jialin — could one of you take a look and merge it if you are happy? Nothing else is waiting on our side.

@cctry
cctry merged commit 0b536ca into main Oct 20, 2026
183 of 202 checks passed
@cctry
cctry deleted the oss-sync-3cc5dd45b8 branch October 20, 2026 20:24
detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
… C closure -- the post-merge port queue is now decided

ARRIVAL SCAN (git log 12dc623..2a6c204 --grep) + LIVE gh STATE +
head-sha comparison for EVERY deferred item. Verdicts:
  RELEASED-BY-MERGE: sgl-project#42689 (@ 7a632cf in-range -- the SECTION-B
    cherry is now redundant; behavior note rides the restart).
  CLOSED (C-items whose PRs arrived and whose integration this stack
    performed): C1 (the dedicated merge week WAS merge sgl-project#5; all eight
    precursor PRs in-range), C2 (sgl-project#44993/sgl-project#44994 -- B5), C3 (sgl-project#45232/
    sgl-project#45236/sgl-project#45334 -- B2), C4 (sgl-project#45238/sgl-project#45241/sgl-project#45242 -- B3), C5 (sgl-project#44912/
    sgl-project#44913 -- arrived; entry-230 canary re-planted as its guard),
    C9 (sgl-project#39727 -- verified OPT-IN, no purge; BOOT_DELTA anti-needle),
    C0a (arrival shas already recorded at entry 310 -- Section C now
    carries NO open code-integration items: C6/C10 retain only their
    explicitly-named docs/boot-measurement remainders, re-stated).
  STILL-OPEN: sgl-project#44342 (head unchanged; auto-merge comfort LOST to
    #46970x), sgl-project#46153/sgl-project#37106/sgl-project#32479/sgl-project#45391 (gh CONFLICTING -- stale
    bases, rebase before any port), sgl-project#41624/sgl-project#42525/sgl-project#42660/sgl-project#44462/sgl-project#35617
    (open, heads unchanged), sgl-project#46191/sgl-project#39845-class (watch-list, none in
    range).
  HOLD STANDS (operator decision, binding): sgl-project#43356/sgl-project#46452/sgl-project#43240/
    sgl-project#43471 KV route -- step-1 'MERGE sgl-project#5 lands first' is NOW MET; the
    sequence may be re-visited ONLY with the post-merge PCIe-IPC
    measurement at an operator sitting. sgl-project#44732: the 'one purge if done
    WITH the merge' premise LAPSED when merge sgl-project#5 completed without it
    -- later execution costs the SAME single purge once; no penalty,
    no haste. Recorded for the operator, not decided by B6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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