Repository navigation
Description
Context
The decode kernel currently slices per-sequence dense buffers using an identity block table built by PagedDecodeMetadata::from_visible_lengths ([0, 1, 2, ...]). With real pool storage in place, attention must gather the sequence's actual, possibly non-contiguous, physical blocks.
Phase 0 outcome (ADR 0001, #117): option A is gather-then-SDPA —
take(pool, block_ids, axis=0)(layout A), thenreshape, thentranspose [0,2,1,3], then fusedscaled_dot_product_attention, reusing existing FFI with no new kernel. MLX fuses the gather into the SDPA read, so gather+SDPA stays within ~15% of contiguous SDPA at <=4k single-sequence context (it climbs with context and batch; the fused-kernel alternative is deferred to #123). Build the gather on the layout-A pool from #118. Seedocs/adr/0001-paged-attention-gather-vs-fused-kernel.md.
Tasks
- Replace the identity tables with the sequence's real
PagedSequenceStateblock tables in the decode dispatch (src/models/model_owned.rsand the per-model paths inqwen3.rs/llama3.rs/gemma3.rs/llama4.rs). - Update
paged_decode_attention_dense_compat(C++ incpp/mlx_cxx_bridge.cpp) and the Rust fallbackpaged_decode_attention_dense_fallback(layers.rs) to gather by physical block id from the pool (Phase 0 option A). - Apply the same change to the rotating / sliding-window variant
paged_decode_attention_rotating_compat.
Acceptance criteria
- Decode output with a fragmented (non-contiguous) block table matches the dense-backend reference within RMS < 5e-3 over 200 steps.
- Supported models (llama3/llama4/qwen3/qwen3.5/gemma3 and their VLM wrappers) are functionally unaffected.
Dependencies
Blocked by Phase 1 (global block-pool tensor storage).
Part of #116
Activity
feat: add physical block-pool K/V tensor storage to PagedBlockPool (#148
chore: fix doc_lazy_continuation clippy lint in paged_pool_tests
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: add physical block-pool K/V tensor storage to PagedBlockPool (l…
feat: 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…