Skip to content

perf(core): record 4k/16k/32k KV-cache sweeps to back the Turbo KV advisor recommendations #354

Closed

Description

@inureyes

Problem / Background

Follow-up to #327 (merged PR #343). The Turbo KV-cache advisor emits per-family and per-context KV-mode recommendations via mlxcel generate --recommend-quant (docs/turbo-kv-cache.md), but they remain advisory/opt-in because the supporting sweeps were never run. Two acceptance items in #327 are still unchecked: the 4k/16k/32k sweeps, and the documented quality guard.

Proposed Solution

  • Run scripts/bench_kv_cache.sh-style sweeps at contexts 4k/16k/32k for at least two dense and two MoE/VLM families.
  • Apply a quality guard: short deterministic outputs plus a longer logprob-trace comparison where available.
  • Validate and tune the advisor's per-family/context recommendations against the recorded data.
  • Where the data is confident, consider promoting a recommendation to a non-advisory per-family default.

Acceptance Criteria

Technical Considerations

Constraint: preserve bf16 scales and biases for quantized models. No recommendation or sweep may reintroduce the bf16 -> f16 promotion that caused the #289 decode regression. The advisor stays advisory until each family has both throughput and quality coverage; only then is a non-advisory per-family default in scope. References: docs/turbo-kv-cache.md, scripts/bench_kv_cache.sh.

Activity

  1. added
    type:performance
    area:core
    area:inference
    priority:backlog
    status:ready
    status:in-progress
    and removed
    status:ready
    on Jun 18, 2026
  2. inureyes commented on Jun 19, 2026

    @inureyes
    MemberAuthor

    KV-cache sweep diagnosis (turbo4-asym was broken; fixed in #367)

    Running the initial sweep surfaced a real bug rather than just data: the advisor's recommended Turbo mode, turbo4-asym, had catastrophically slow decode (0.13-0.24x fp16) because it was hardwired to a lossy sparse-V weighted-sum path. The #353 MLX_MAX_OPS_PER_BUFFER gate was ruled out (turbo4-asym was equally slow at ops=40 and ops=1000). Fixed in #367 (exact rotated-codec-basis dequant-SDPA, ~0.40x fp16, about 3x faster and now exact instead of lossy).

    Current M1 Ultra decode (qwen2.5-7b-4bit, after #367):

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

    Remaining work for this issue (deferred to a fresh session)

    1. Clean re-sweep with the fixed turbo4-asym (and turbo4-delegated included) at 4k/16k/32k for at least 2 dense and 2 MoE/VLM families, recorded to benchmarks/turbo_kv/.
    2. Re-tune the --recommend-quant advisor against the data. int8 and delegated are the fast cache options (0.68-0.80x); turbo4-asym is now exact and 3x faster but still ~0.40x, so it should be framed as a memory/exactness option, not a speed-competitive default. The medium/long recommendations need revising.
    3. Correct the bench_kv_cache.sh acceptance gates: the >= 0.95x fp16 targets for turbo4-asym are unrealistic and were never validated (per perf(core): extend the quant/KV-cache advisor to recommend Turbo KV modes per family and context #327).
    4. Quality guard doc (short deterministic outputs plus a longer logprob-trace comparison where available).

    The partial sweep CSVs (qwen2.5-7b and qwen3-8b complete; qwen3-30b-a3b fp16/int8 only) in benchmarks/turbo_kv/ recorded the pre-#367 (broken) turbo data and should be regenerated. The deeper fused-kernel work to bring turbo4-asym itself to int8/delegated speed is tracked in #370.

  3. added
    status:ready
    and removed
    status:in-progress
    on Jun 19, 2026
  4. added this to the 0.3 milestone on Jun 21, 2026
  5. self-assigned this
    on Jun 21, 2026
  6. added
    status:done
    and removed
    status:ready
    on Sep 6, 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:backlogstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions