Skip to content

Phase 1: Global block-pool tensor storage #118

Closed

Description

@inureyes

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_update figures are the no-donation upper bound, not the real append cost. See docs/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, ...] via slice_update / scatter; extend append_tokens / acquire_block to 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 / PagedCacheStats accounting 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

  1. added this to the 0.2.0 milestone on May 27, 2026
  2. added
    status:backlog
    type:enhancement
    priority:high
    area:core
    on May 27, 2026
  3. added
    status:in-progress
    status:review
    status:done
    and removed
    status:backlog
    status:in-progress
    status:review
    on Jun 2, 2026
  4. added 2 commits that reference this issue on Jun 2, 2026
    2b4a074
    c6af2fd
  5. self-assigned this
    on Jun 4, 2026
  6. modified the milestones: 0.2.0, 0.1 on Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:corepriority:highstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions