Skip to content

perf(cache): fuse V dequant into Turbo4Asym attention (reach int8/delegated decode speed) #370

Closed

Description

@inureyes

Background

Follow-up to #367. #367 routed Turbo4Asym decode through an exact rotated-codec-basis dequant-SDPA, raising it from 0.14x fp16 (the old lossy sparse-V path) to ~0.40x and making it exact. But it still materializes a full dequantized V and runs attention as two passes, and the 4bit PolarQuant + Walsh-Hadamard V dequant is ~2x costlier than int8's linear dequant, so it caps around 0.40x fp16.

Measured on M1 Ultra, qwen2.5-7b-4bit decode tok/s:

mode 4k 16k
fp16 98 70
int8 75 48
turbo4-asym (after #367) 39 (0.40x) 30 (0.43x)
turbo4-delegated 78 (0.80x) 51 (0.73x)

Turbo4Delegated reaches 0.73-0.80x because it FUSES the cold-V dequant into the attention kernel (the steel-envelope attention_turbo4_delegated_steel / attention_turbo4_delegated_fused), never materializing the full V. Turbo4Delegated is effectively "Turbo4Asym + hot/cold split + fused decode".

Proposed work

Bring the fused dequant-into-attention approach to Turbo4Asym so it reaches int8/delegated decode throughput (0.7-0.8x fp16) without the hot/cold split, OR decide that the advisor should recommend Turbo4Delegated (already fast) for the fp16-K + 4bit-V use case and keep Turbo4Asym as the exact/simple fallback. Either adapt the delegated steel-envelope kernel for the non-hot/cold asym layout, or evaluate the recommend-Turbo4Delegated route.

Acceptance criteria

  • Turbo4Asym decode reaches >= 0.7x fp16 at 4k/16k/32k on M1 Ultra, OR a documented decision that Turbo4Delegated is the recommended fast fp16-K+4bit-V mode and Turbo4Asym stays the exact/simple option.
  • Numerically exact (parity with the dequant reference).
  • No regression to other modes.

Discovered during #354 / #367.

Activity

  1. added
    type:performance
    priority:low
    area:core
    area:inference
    on Jun 19, 2026
  2. inureyes commented on Jun 20, 2026

    @inureyes
    MemberAuthor

    Why fusion is the one lever (empirical, from the #354 sweep + A/B)

    Cross-checked mlxcel's Turbo4Asym decode against the upstream turboquant_plus sparse-V paper to see whether reviving sparse-V (instead of fusing) could close the gap. It cannot. Full writeup in ADR 0002 (lands with #376).

    A/B, M1 Ultra, decode tok/s, turbo4-asym:

    path qwen3-30b-a3b @16k qwen3.5-35b-a3b @32k (paper's exact model)
    fp16 40.34 (1.00x) 49.83 (1.00x)
    dequant-SDPA (#369) 10.51 (0.26x) 54.56 (1.10x)
    sparse-V kernel, tau=1e-6 10.47 (0.26x) 55.34 (1.11x)
    sparse-V graph, full dequant 10.55 (0.26x) 54.59 (1.10x)
    sparse-V kernel, tau=1.0 (skip all V) 6.08 54.39 (1.09x)

    Findings:

    1. sparse-V is exact, not lossy. Default tau=1e-6 skips only positions whose attention weight is below FP16 round-off (matches the paper's 0.0000 PPL delta). So the choice here is purely about speed.
    2. The sparse-V skip buys nothing in mlxcel. The paper's +22.8% is the skip kernel vs its own full-dequant baseline. The mlxcel analog (kernel vs graph) is +1.4% at 32K on the paper's exact model. Skipping the entire V weighted-sum (tau=1.0) equals full dequant.
    3. Root cause = split design. mlxcel computes scores + softmax in graph FP32 ops, then handles V separately (materialize for dequant-SDPA, or a skip kernel for sparse-V). The V step is a negligible fraction of decode, so optimizing it (skip or otherwise) does not move the needle. The paper's +22.8% lives inside a fused flash-attention where V dequant is a large, eliminable slice.

    Implication for this issue. Neither dequant-SDPA nor sparse-V can beat the 0.24x to 0.40x decode ceiling on cache-bound standard-attention models, because both leave the V dequant as a separate, non-overlapped step. The fused kernel (#370) is the only path that captures all three wins at once: V never materialized, the dequant rides inside the fused scores + softmax + accumulate, and the sparse-V skip finally removes hot-path work. When #370 lands, re-run the A/B above; the prediction is that a fused dequant-in-SDPA kernel is the first mlxcel path where the skip and the long-context bandwidth win both appear.

  3. added a commit that references this issue on Jun 21, 2026
  4. added this to the 0.3 milestone on Jun 21, 2026
  5. self-assigned this
    on Jun 21, 2026
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:lowstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions