You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Phase 4: Radix-trie and block-pool unification (scheduler wiring) #121
This is the actual unification and the core of the epic. Today the radix trie stores whole dense DetachedCacheSet snapshots and adopt moves tensors into a new sequence, and the whole path is disabled under the paged backend. Make trie nodes reference physical blocks and reuse them across requests by refcount, reusing the copy-on-write primitive that already exists in cache/paged_detach.rs.
Tasks
Change prompt-cache entries (src/server/prompt_cache/entry.rs, store.rs) to hold physical block references via DetachedPagedCacheSet / retain_block instead of dense DetachedCacheSet.
Wire CachePool::detach_paged / adopt_paged into donate_finished_sequence_cache and try_adopt_cached_prefix (scheduler.rs).
Remove the decode_storage_backend == Paged -> return None guard in try_adopt_cached_prefix and replace it with the paged adopt path.
On a prefix hit, point the new sequence's block table at the matched physical blocks (refcount bump), with no tensor copy; the first write triggers the existing COW automatically.
Reuse the APC block-hash chains as the block-granular match key so matching aligns to block boundaries.
Acceptance criteria
Prefix reuse and paged batching run simultaneously (the documented "Dense backend only" limitation no longer applies).
A hit reuses physical blocks with zero tensor copy, verified by observing refcount > 1 on the shared blocks.
cached_tokens in the usage payload is reported correctly for paged hits.
#121 complete — unified paged KV cache is live for the pool-backed families
Decomposed into three merged sub-steps:
(a) feat: back paged scheduler sequences with the shared KV block pool #167 — scheduler wiring: CachePool → Rc<RefCell>, Fp16 paged sequences pool-backed via KVCache::new_paged, decode is_paged_backed() guard routes pool-backed caches through per-sequence update_and_fetch. (Also fixed a pre-existing fast_rope_batched dense-batched stride-aliasing bug.)
(b) feat: unify radix prompt cache with paged block pool (sub-step b of #121) #168 — radix↔pool unification: DetachedKvSet{Dense,Paged} union, removed the try_adopt_cached_prefix Paged guard, adopt_paged/detach_paged dispatch. Two requests sharing a prompt prefix store it once in the pool; the second adopts it (refcount-pinned blocks) with no re-prefill. adopt_paged rebuilds pool-backed caches and restores per-layer RoPE offset.
Verification (real-model, byte-identical greedy decode — stronger than the RMS < 5e-3 DoD)
case
qwen3-0.6b
llama-3.2-1b
single-sequence paged == dense
✓
✓
batched B=2 paged == dense (both rows)
✓
✓
concurrent prefix-share == cold no-cache
✓
✓
Tests: tests/paged_scheduler_parity.rs, tests/paged_prefix_share_parity.rs (also the earlier single-stream tests/paged_real_model_parity.rs from #152). Run with --features metal,accelerate --release -- --ignored.
Scope
Pool-backing is gated to Fp16 dense-natural-backend sequences — qwen3 and llama3 — at CachePool::allocate_with_layout (src/lib/mlxcel-core/src/cache.rs). Model-owned-state families (gemma3, llama4, qwen3.5) and quantized-KV (Int8 / Turbo) paths keep the dense backend; their decode path is unchanged by #121. Bringing those families onto the pool is future work and overlaps #124.
Activity
feat: pooled paged decode read path over real block tables (#119) (#149)
feat: paged prefill writer with shared-prefix copy-on-write (#150)
feat: transparent pool-backed KVCache + real-model paged parity test (#…
feat: back paged scheduler sequences with the shared KV block pool (#167
inureyes commentedon Jun 6, 2026
Reopening: PR #167 implemented only sub-step (a) (scheduler paged decode/prefill wiring + hybrid-SSM gate, + a pre-existing
fast_rope_batchedbatched-decode bug fix). It was auto-closed because the PR body's phrase "does not close #121" matched GitHub's closing-keyword parser (which ignores the negation). Sub-steps (b) radix adopt/donate +try_adopt_cached_prefixPaged-guard removal + concurrent prefix-sharing, and (c) multi-model RMS<5e-3 sweep, remain.feat: unify radix prompt cache with paged block pool for prefix shari…
test: extend paged KV cache parity to llama3 (#121 sub-step c) (#169)
inureyes commentedon Jun 7, 2026
#121 complete — unified paged KV cache is live for the pool-backed families
Decomposed into three merged sub-steps:
CachePool→Rc<RefCell>, Fp16 paged sequences pool-backed viaKVCache::new_paged, decodeis_paged_backed()guard routes pool-backed caches through per-sequenceupdate_and_fetch. (Also fixed a pre-existingfast_rope_batcheddense-batched stride-aliasing bug.)DetachedKvSet{Dense,Paged}union, removed thetry_adopt_cached_prefixPaged guard,adopt_paged/detach_pageddispatch. Two requests sharing a prompt prefix store it once in the pool; the second adopts it (refcount-pinned blocks) with no re-prefill.adopt_pagedrebuilds pool-backed caches and restores per-layer RoPE offset.Verification (real-model, byte-identical greedy decode — stronger than the RMS < 5e-3 DoD)
Tests:
tests/paged_scheduler_parity.rs,tests/paged_prefix_share_parity.rs(also the earlier single-streamtests/paged_real_model_parity.rsfrom #152). Run with--features metal,accelerate --release -- --ignored.Scope
Pool-backing is gated to Fp16 dense-natural-backend sequences — qwen3 and llama3 — at
CachePool::allocate_with_layout(src/lib/mlxcel-core/src/cache.rs). Model-owned-state families (gemma3, llama4, qwen3.5) and quantized-KV (Int8 / Turbo) paths keep the dense backend; their decode path is unchanged by #121. Bringing those families onto the pool is future work and overlaps #124.Deferred to later epic phases
DetachedPagedCacheSet→ Distributed block-table serialization (kv_cache_serde) #125feat: pooled paged decode read path over real block tables (lablup#119)…
feat: paged prefill writer with shared-prefix copy-on-write (lablup#150)
feat: transparent pool-backed KVCache + real-model paged parity test (l…
feat: back paged scheduler sequences with the shared KV block pool (l…
feat: unify radix prompt cache with paged block pool for prefix shari…
test: extend paged KV cache parity to llama3 (lablup#121 sub-step c) (l…