Skip to content

Phase 0: Feasibility spike — page-gather microbench and paged-attention kernel ADR #117

Closed

Description

@inureyes

Context

Before changing storage, measure the decode-time cost of gathering scattered physical blocks on MLX, and decide between two attention strategies:

  • (A) gather-then-SDPA: use take / concatenate to materialize a contiguous K/V per sequence from scattered blocks, then call the existing fused scaled_dot_product_attention. Small delta from the current paged_decode_attention_dense_compat.
  • (B) fused Metal paged-attention kernel: a custom kernel modeled on src/lib/mlx-cpp/turbo/sparse_v_sdpa.metal that reads scattered blocks directly with no gather copy.

This spike de-risks the whole epic by quantifying the (A) gather cost so we know whether and when (B) is worth building.

Tasks

  • Microbench per-step take(pool, block_ids) + reshape + fused SDPA vs the current contiguous-slice path, across context lengths (1k / 4k / 16k / 32k) and batch sizes, on Apple Silicon. Reuse the harness described in docs/bridge-overhead-microbench.md.
  • Record block-size sensitivity (16 / 32 / 64) on gather cost and on fragmentation.
  • Decide the global pool tensor layout (per-layer [num_blocks, block_size, n_kv_heads, head_dim] vs a head-split layout) based on take / slice_update performance.
  • Write an ADR under docs/ recommending (A) first and (B) as a later optimization, including the measured crossover context length where gather cost becomes material.

Acceptance criteria

  • Microbench numbers committed and reproducible.
  • ADR merged with a layout decision and a kernel-strategy decision the downstream phases can follow.

Dependencies

None. This is the entry point.

Part of #116

Activity

  1. added this to the 0.2.0 milestone on May 27, 2026
  2. added
    type:performance
    priority:high
    area:core
    platform:macos
    status:investigation
    on May 27, 2026
  3. self-assigned this
    on May 30, 2026
  4. added
    status:in-progress
    status:review
    status:done
    and removed
    status:investigation
    status:in-progress
    status:review
    on May 31, 2026
  5. added a commit that references this issue on May 31, 2026
    889bd84
  6. modified the milestones: 0.2.0, 0.1 on Jun 5, 2026
  7. added a commit that references this issue on Oct 27, 2026
    859d7e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:coreplatform:macospriority:highstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions