Skip to content

perf(cache): Turbo4Asym decode uses slow sparse-V path (0.13-0.24x fp16); route through dequant-SDPA #367

Closed

Description

@inureyes

Problem

While running the #354 KV-cache throughput sweeps, Turbo4Asym (fp16-K + 4bit-V, the advisory --recommend-quant suggestion for medium/long context) decode throughput is catastrophically slow: 0.13-0.24x fp16, scaling worse with context.

Measured on M1 Ultra, qwen2.5-7b-4bit at ~4k context, greedy, decode tok/s:

mode decode tok/s vs fp16
fp16 99 1.00x
int8 77 0.78x
turbo4-asym 13 (default) -> 24 (max sparse-V threshold) 0.13-0.24x
turbo4-delegated 79 0.80x

So Turbo4Asym is the slowest mode while Turbo4Delegated and int8 are fast. The bench_kv_cache.sh acceptance gates expect turbo4-asym decode >= 0.95x fp16; the reality is far below that (these gates were never validated, per #327).

Root cause

Turbo4Asym decode is hardwired to the sparse-V weighted-sum path (KVCache::update_and_sparse_v_attention -> turbo::sparse_v::attention_sparse_v_turbo4) in the model dispatch (src/models/qwen3.rs around line 177 and src/models/llama3.rs around line 218: if l == 1 && cache.sparse_v_available() { update_and_sparse_v_attention } else { ... }, where sparse_v_available() is matches!(mode, Turbo4Asym)). The sparse-V path computes a post-softmax alive-mask, sparse-gathers V, and weighted-sums it; at the default threshold 1e-6 almost nothing is skipped, so it pays the full V-dequant cost plus the masking/gather overhead. Raising MLXCEL_SPARSE_V_THRESHOLD to 0.1 only reaches 0.24x (the masking/gather overhead dominates, not the skip count).

Symmetric Turbo4 and Turbo4Delegated both already have a dequant-first SDPA path (KVCache::update_and_turbo4_dequant_sdpa_attention / update_and_turbo4_delegated_attention, both default-on) that dequantizes V transiently and runs native MLX SDPA, reaching 0.79-0.80x fp16. Turbo4Asym is the only Turbo mode with no such path.

Not a #353 regression: turbo4-asym is equally slow at MLX_MAX_OPS_PER_BUFFER=40 (12.2 tok/s) and 1000 (13.6 tok/s).

Proposed fix

Give Turbo4Asym decode a dequant-then-SDPA path: dequantize the 4bit-V to fp16 transiently and run native SDPA with the fp16-K, mirroring int8 / Turbo4 / Turbo4Delegated. Make it the default (it is both more accurate than the sparse-V approximation and ~3-6x faster), keeping the sparse-V path reachable behind an env flag for A/B and fallback. Update every model call site that routes Turbo4Asym through sparse-V (qwen3, llama3, and any others; confirm which model handles qwen2.5 since it was slow in the sweep).

Acceptance criteria

  • Turbo4Asym decode reaches roughly int8 throughput (>= 0.7x fp16) at 4k/16k/32k on M1 Ultra.
  • Output is numerically correct: parity with the exact dequant + SDPA reference (the lossy sparse-V approximation is replaced by exact dequant + native SDPA, so quality should improve or match).
  • The sparse-V path remains reachable via an env flag (A/B / fallback), default off-the-hot-path.
  • No regression to Turbo4 / Turbo4Delegated / int8 / fp16 decode.

Found while running #354; the advisor's Turbo4Asym recommendation depends on this fix.

Activity

  1. added
    status:in-progress
    type:performance
    priority:medium
    area:core
    area:inference
    status:review
    status:done
    and removed
    status:in-progress
    on Jun 19, 2026
  2. added this to the 0.3 milestone on Jun 21, 2026
  3. self-assigned this
    on Jun 21, 2026
  4. added a commit that references this issue on Jun 23, 2026
    7ef0a9d
  5. added a commit that references this issue on Oct 27, 2026
    e05ed6a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:corearea:inferencepriority:mediumstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions