Skip to content

Phase 4: Radix-trie and block-pool unification (scheduler wiring) #121

Closed

Description

@inureyes

Context

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.

Dependencies

Blocked by Phase 3 (paged prefill).

Part of #116

Activity

  1. added this to the 0.2.0 milestone on May 27, 2026
  2. added
    status:backlog
    type:enhancement
    priority:high
    area:architecture
    area:core
    on May 27, 2026
  3. added
    status:in-progress
    and removed
    status:backlog
    on Jun 6, 2026
  4. inureyes commented on Jun 6, 2026

    @inureyes
    MemberAuthor

    Reopening: PR #167 implemented only sub-step (a) (scheduler paged decode/prefill wiring + hybrid-SSM gate, + a pre-existing fast_rope_batched batched-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_prefix Paged-guard removal + concurrent prefix-sharing, and (c) multi-model RMS<5e-3 sweep, remain.

  5. added a commit that references this issue on Jun 7, 2026
  6. inureyes commented on Jun 7, 2026

    @inureyes
    MemberAuthor

    #121 complete — unified paged KV cache is live for the pool-backed families

    Decomposed into three merged sub-steps:

    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.

    Deferred to later epic phases

  7. self-assigned this
    on Aug 31, 2026
  8. added
    status:done
    and removed
    status:in-progress
    on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:architecturearea:corepriority:highstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions