Repository navigation
Closed
Labels
area:coremlxcel-core: MLX FFI, primitives, KV cache, layersarea:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:lowLow prioritystatus:doneCompletedtype:performancePerformance improvements
Description
Problem / Background
- PR perf(core): adaptive selector for the native paged-attention decode kernel #709 (issue perf(core): adaptive selector for the native paged-attention decode kernel #331) added an adaptive selector to
paged_decode_attention_pooledin src/lib/mlxcel-core/src/layers.rs so the fused Metal paged-attention kernel dispatches only in its measured winning regime (docs/adr/0001-paged-attention-gather-vs-fused-kernel.md). The PR perf(core): adaptive selector for the native paged-attention decode kernel #709 review then established thatpaged_decode_attention_pooledhas NO production caller: under the scheduler's paged backend, pool-backed model layers gate out of the native path (e.g. src/models/llama3.rsis_paged_backed()returning the native-kernel arm None) and route through the per-sequenceupdate_and_fetchpool intercept, which gathers the visible window (CachePoolgather_visible, src/lib/mlxcel-core/src/cache.rs around line 2669) and runs standard SDPA. Production models callpaged_decode_attention_dense_compat/_fallback, never_pooled. - The selector, the fused kernel behind it, and the tri-state
MLXCEL_PAGED_ATTENTION_NATIVEoverride are therefore exercised today only byexamples/paged_attention_kernel_bench.rs, the unit/FFI tests, and external mlxcel-core API consumers. Insidemlxcel-serverthey are latent.
Current state (post PR #709, M1 Ultra bench)
- The reachable native win regime is the single-slab batched island: B>=4 at context <=256 tokens (block_size 32 slabs hold 32 blocks), measured 1.34x-1.94x over gather. Everything else is B=1 (kernel loses, 0.81-0.92x) or multi-slab (kernel declines).
- ADR 0001's adaptive-selector addendum records both the selector thresholds and the reachability caveat.
Proposed direction
Decide between two exits, with trace evidence:
- Wire in: add a scheduler/model decode arm that calls
paged_decode_attention_pooledfor pool-backed Fp16 layers, so the selector picks native on the single-slab batched island in real serving. Requires the batched-decode dispatch in each transformer family to thread batch/visible/slab inputs, and a real-model A/B (short-context batched decode, e.g. B=4/8 with prompts <=256 tokens) proving the island materializes end to end and nothing regresses elsewhere. - Retire: if server traces show the single-slab island is negligible in production workloads (contexts under ~256 tokens at B>=4 are rare in chat serving), remove the pooled entry point (or explicitly mark it a library-only API) and record the decision in ADR 0001.
Either way the multi-slab kernel spike stays gated behind live-trace evidence, per issue #331 and the ADR.
Acceptance criteria
- A decision (wire in vs retire/library-only) recorded in ADR 0001 with trace or A/B evidence. Decision: retire to a library-only API (occupancy derivation in ADR 0001, perf(core): wire the pooled paged-attention decode entry point into the scheduler or retire it #710 section).
- If wired in: real-model batched short-context A/B numbers on Apple Silicon showing the island win end to end, plus no-regression checks at B=1 and long context.
- If retired: the pooled entry point removed or documented as library-only, tests/bench adjusted accordingly. Documented as library-only (kept + tested;
use_native_paged_kernelleft in place as it is shared with the livedense_compatpath).
References
- Issue perf(core): adaptive selector for the native paged-attention decode kernel #331 / PR perf(core): adaptive selector for the native paged-attention decode kernel #709 (adaptive selector; review finding that the pooled path is production-latent).
- docs/adr/0001-paged-attention-gather-vs-fused-kernel.md (Phase 6 table, perf(core): chunked slab storage for the paged pool to eliminate growth reallocation entirely #235 chunked-slab decline, perf(core): adaptive selector for the native paged-attention decode kernel #331 addendum).
- src/lib/mlxcel-core/src/layers.rs (
paged_decode_attention_pooled,select_pooled_paged_dispatch), src/server/batch/scheduler.rs (paged decode dispatch), src/models/llama3.rs (native-arm gate).
Metadata
Metadata
Assignees
Labels
area:coremlxcel-core: MLX FFI, primitives, KV cache, layersarea:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:lowLow prioritystatus:doneCompletedtype:performancePerformance improvements
Activity
docs(adr): note the pooled paged-attention selector is server-latent (#…
docs: reconcile paged-attention native-kernel docs with the #331 sele…
perf(core): adaptive selector for the native paged-attention decode k…
test(cuda/attn): host-side selector tests and fix paged-decode retire…
docs(core): retire pooled paged-attention decode to library-only API (l…
docs: record the paged decode strategy reversal in ADR 0001 and the s…
docs: add the six paged-decode v2 variables and correct the NATIVE row (
docs: fix stale "not a server knob" claim in turbo-kv-cache.md (#1571)
perf(core): adaptive selector for the native paged-attention decode k…
docs(core): retire pooled paged-attention decode to library-only API (l…
docs: add the six paged-decode v2 variables and correct the NATIVE row (