Skip to content

docs(cache): record #370 fused-V attempt regression, keep Turbo4Asym on dequant-SDPA - #378

Merged
inureyes merged 1 commit into
mainfrom
perf/370-turbo4asym-steel-fused-v
Jun 21, 2026
Merged

inureyes merged 1 commit into
mainfrom
perf/370-turbo4asym-steel-fused-v

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

#370 asked to fuse the Turbo4Asym V dequant into the attention kernel so it reaches int8/delegated decode speed (0.7-0.8x fp16), or to document that Turbo4Delegated is the recommended fast fp16-K + 4-bit-V mode with Turbo4Asym as the exact/simple fallback. I took the first route, benchmarked it on real hardware, and it does not work, so this PR lands the documented decision backed by the measurement.

What was tried

Turbo4Asym is structurally the all-cold case of Turbo4Delegated (FP16 K, every visible V token 4-bit packed, no hot FP16 tail). So the attempt routed asym decode through the existing delegated steel-envelope fused kernel (attention_turbo4_delegated_steel) with cold_offset = offset, hot_offset = 0. The kernel fuses the cold-V dequant into the attention accumulate and never materializes V.

  • Parity held. A 16-step Turbo4Asym decode through the steel kernel matched the dequant-SDPA reference at RMS < 5e-3 (threshold 0, no skip).
  • Speed regressed. M1 Ultra, qwen2.5-7b-4bit, decode tok/s:
mode 4K 16K 32K
fp16 94.83 (1.00x) 68.95 (1.00x) 50.62 (1.00x)
turbo4-asym dequant-SDPA (#369) 28.61 (0.30x) 22.76 (0.33x) 14.55 (0.29x)
turbo4-asym steel (the #370 attempt) 10.68 (0.11x) 4.41 (0.06x) 2.15 (0.04x)
turbo4-delegated 63.50 (0.67x) 48.38 (0.70x) 34.64 (0.68x)

The fused kernel makes asym 3x slower at 4K and 7x slower at 32K.

Why

  1. The hand-written fused kernel (graph scores, two-pass online softmax, per-token nibble-unpack + codebook-lookup + accumulate sweep) is slower than materializing the rotated V and calling MLX's optimized native flash-attention. The split dequant + native SDPA is the faster arrangement on this hardware.
  2. Turbo4Delegated's 0.66-0.80x does not come from the steel kernel. The delegated decode path defaults to dequant-SDPA (turbo4_delegated_dequant_sdpa_enabled() is on by default and returns before the steel try); the steel envelope is delegated's slow fallback. The premise that motivated perf(cache): fuse V dequant into Turbo4Asym attention (reach int8/delegated decode speed) #370 (delegated is fast because it fuses V dequant into the kernel) was wrong.

There is no fuse-into-native-SDPA option, because MLX's SDPA consumes a dense V.

Decision

Keep Turbo4Asym on the exact dequant-SDPA path (the simple, fully-quantized-V, untouched-K option at ~0.3-0.5x). For the fp16-K + 4-bit-V use case that wants speed, use Turbo4Delegated (~4x V compression at ~0.7x decode), which the --recommend-quant advisor already promotes (post-#376), so no advisor change is needed. The remaining asym-vs-delegated gap is the hot/cold split, not V-dequant fusion, and is left as-is by design.

Changes

No code change: the fused-kernel wiring was reverted after the benchmark. Validation is the real-checkpoint benchmark above.

Closes #370

…on dequant-SDPA

#370 proposed fusing the Turbo4Asym V dequant into the attention kernel to reach
int8/delegated decode speed. Turbo4Asym is the all-cold case of Turbo4Delegated,
so the attempt routed it through the existing delegated steel-envelope fused
kernel (cold_offset=offset, hot_offset=0). Parity held (RMS < 5e-3 over 16 decode
steps), but the M1 Ultra benchmark on qwen2.5-7b-4bit measured a 3-7x decode
regression, not a win:

  mode                          4K     16K    32K
  fp16                          94.83  68.95  50.62
  turbo4-asym dequant-SDPA      28.61  22.76  14.55  (0.30/0.33/0.29x)
  turbo4-asym steel (attempt)   10.68   4.41   2.15  (0.11/0.06/0.04x)
  turbo4-delegated              63.50  48.38  34.64  (0.67/0.70/0.68x)

The hand-written fused kernel is slower than native SDPA over a materialized V,
and Turbo4Delegated's 0.7x comes from its default dequant-SDPA path, not the
steel envelope (which is delegated's slow fallback). The #370 premise did not
hold and there is no fused-asym path worth shipping.

Decision (ADR 0002 addendum): keep Turbo4Asym on the exact dequant-SDPA path and
steer the fp16-K + 4-bit-V speed use case to Turbo4Delegated, which the
--recommend-quant advisor already promotes. The remaining asym-vs-delegated gap
is the hot/cold split, not V-dequant fusion, and is left as-is by design.

No code change: the fused-kernel wiring was reverted after the benchmark. Adds
the measured sweep under benchmarks/turbo_kv/ as the evidence.
@inureyes inureyes added type:docs Documentation improvements or additions type:performance Performance improvements area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) status:done Completed labels Jun 21, 2026
@inureyes
inureyes merged commit a23e438 into main Jun 21, 2026
4 checks passed
@inureyes
inureyes deleted the perf/370-turbo4asym-steel-fused-v branch June 21, 2026 09:09
@inureyes inureyes added this to the 0.3 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added priority:low Low priority and removed type:performance Performance improvements labels Sep 7, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…4Asym on dequant-SDPA (lablup#378)

lablup#370 proposed fusing the Turbo4Asym V dequant into the attention kernel to reach
int8/delegated decode speed. Turbo4Asym is the all-cold case of Turbo4Delegated,
so the attempt routed it through the existing delegated steel-envelope fused
kernel (cold_offset=offset, hot_offset=0). Parity held (RMS < 5e-3 over 16 decode
steps), but the M1 Ultra benchmark on qwen2.5-7b-4bit measured a 3-7x decode
regression, not a win:

  mode                          4K     16K    32K
  fp16                          94.83  68.95  50.62
  turbo4-asym dequant-SDPA      28.61  22.76  14.55  (0.30/0.33/0.29x)
  turbo4-asym steel (attempt)   10.68   4.41   2.15  (0.11/0.06/0.04x)
  turbo4-delegated              63.50  48.38  34.64  (0.67/0.70/0.68x)

The hand-written fused kernel is slower than native SDPA over a materialized V,
and Turbo4Delegated's 0.7x comes from its default dequant-SDPA path, not the
steel envelope (which is delegated's slow fallback). The lablup#370 premise did not
hold and there is no fused-asym path worth shipping.

Decision (ADR 0002 addendum): keep Turbo4Asym on the exact dequant-SDPA path and
steer the fp16-K + 4-bit-V speed use case to Turbo4Delegated, which the
--recommend-quant advisor already promotes. The remaining asym-vs-delegated gap
is the hot/cold split, not V-dequant fusion, and is left as-is by design.

No code change: the fused-kernel wiring was reverted after the benchmark. Adds
the measured sweep under benchmarks/turbo_kv/ as the evidence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:low Low priority status:done Completed type:docs Documentation improvements or additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant