Repository navigation
Description
Context
Physical K/V tensors currently live in per-sequence dense KVCache placeholders; in Fp16/Int8 paged mode the PagedBlockPool tracks only block-table metadata (see its doc comment in cache/paged.rs). Move the actual tensor storage into the shared pool so a sequence's KV is a list of physical block ids rather than a contiguous buffer.
Phase 0 outcome (ADR 0001, #117): the pool tensor layout is layout A
[num_blocks, block_size, n_kv_heads, head_dim](per-layer), chosen over the head-split layout (~2.1x faster on gather+SDPA in the microbench); keep the default block size 32. The block append must reassign the pool tensor (pool = slice_update(pool, ...)) so MLX donates the buffer and the write is O(block) in place. The microbench's O(pool)slice_updatefigures are the no-donation upper bound, not the real append cost. Seedocs/adr/0001-paged-attention-gather-vs-fused-kernel.md.
Tasks
- Add per-layer pool tensors to
PagedBlockPool(cache/paged.rs) using the layout chosen in Phase 0. - Implement token writes into
pool[block_id, slot, ...]viaslice_update/scatter; extendappend_tokens/acquire_blockto write into pool storage instead of the dense placeholder. - Implement visible-block gather (
take(pool, block_ids, axis=0)reshaped to[1, H, T, D]). - Route Fp16 and Int8 through pool storage; keep the Turbo4 per-page sidecars (
PagedTurboPageSidecars) consistent with the new storage so detach/adopt still round-trips bit-identically. - Update
nbytes/PagedCacheStatsaccounting to read from pool tensors.
Acceptance criteria
- A paged sequence stores KV only in the pool, with no dense placeholder duplication.
- For a contiguous block table, gathered visible K/V is byte-identical to the previous contiguous-slice result; existing paged decode tests pass.
Dependencies
Blocked by Phase 0 (#116 child: feasibility spike).
Part of #116
Activity
perf: page-gather decode microbench and paged-attention ADR (#145)
feat: add physical block-pool K/V tensor storage to PagedBlockPool (#148
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
feat: unify radix prompt cache with paged block pool for prefix shari…
perf: page-gather decode microbench and paged-attention ADR (lablup#145)
feat: add physical block-pool K/V tensor storage to PagedBlockPool (l…
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…