Skip to content

serve: warn that a quantised KV cache takes attention off the device on hrx (engine#679) - #3279

Merged
bong-water-water-bong merged 1 commit into
mainfrom
i679/679-kv-fa-warning
Nov 22, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
i679/679-kv-fa-warning

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #679, and it corrects the premise of #3275, which merged an hour ago.

What #3275 introduced, and what it cannot do here

--ctk/--ctv now pass a KV cache type through to llama-server. The reason given was that a quantised cache halves the KV read that dominates long-context decode. On --device hrx that is false, and the matcher says so:

// fork dispatch-flash-attention.cpp:247 and :332 — both HRX flash-attention matchers
if (query->type != GGML_TYPE_F32 || key->type != GGML_TYPE_F16 || value->type != GGML_TYPE_F16 ||
    mask->type != GGML_TYPE_F16 || output->type != GGML_TYPE_F32) { return {}; }

Both HRX FA matchers require f16 K/V, and nothing in dispatch_registration/ accepts a quantised K or V (grep key->type == GGML_TYPE_Q8_0 → nothing). So --ctk q8_0 does not read less — it makes the matchers decline and attention runs on the CPU: a large slowdown, with nothing printed to say why.

The change

One warning, in the same voice as the other placement warnings, naming both types and the consequence:

1bit serve: --ctk q8_0 / --ctv f16 on --device hrx: the HRX flash-attention matchers take f16 K/V only,
            so attention will run on the CPU (slower, not faster)

A warning, not a refusal, on purpose: --device cpu serves quantised caches legitimately, and a future HRX K/V-quant matcher should not need this line edited before it can be reached.

Arms (device-free, no GPU, no model)

tests/print_backend.sh, over the existing --print-backend harness:

  • a quantised --ctk prints the warning;
  • an explicit --ctk f16 prints nothing;
  • an unasked serve still passes no -ctk/-ctv at all (the default stays llama-server's f16).

Why this is a draft tonight

The release holds the device and this branch is at current main, where I have no built tree — so the honest state is "CI is the build". I would rather it verifies in c35 than claim a local run I did not do. Ask when CI is green: a verdict, then it merges whenever the queue allows.

…on hrx (engine#679)

#3275 added --ctk/--ctv as a passthrough so a long-context serve could ask for a smaller KV cache. On hrx that
is a foot-gun rather than a lever, and the matcher is explicit about it:

  dispatch-flash-attention.cpp:247 and :332 -- both HRX FA matchers
    if (query->type != GGML_TYPE_F32 || key->type != GGML_TYPE_F16 || value->type != GGML_TYPE_F16 || ...) return {};

No registration anywhere in dispatch_registration/ accepts a quantised K or V, so a quantised cache does not
read less: the matchers DECLINE and attention runs on the CPU -- a large slowdown with nothing printed.

So say it, once, in the same voice as the other placement warnings, naming both types and the consequence.
Deliberately a warning and not a refusal: the cpu route serves quantised caches legitimately, and a future
HRX K/V-quant matcher should not need this line edited to become reachable.

Arms (device-free, tests/print_backend.sh): a quantised --ctk prints the warning, an explicit --ctk f16 does
not, and an unasked serve still passes no -ctk/-ctv at all.
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 58d6d16)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

679 - Partially compliant

Compliant requirements:

  • The PR adds a warning when quantized KV cache is used with --device hrx
  • The warning explains that attention will run on CPU and is slower
  • The warning is consistent with other placement warnings in the codebase

Non-compliant requirements:

  • The PR does not address the root cause of the performance issue (flash attention not enabled by default)
  • The PR does not implement the actual fix to enable flash attention for long context on HRX

Requires further human verification:

  • The performance comparison in the ticket needs to be verified with the new warning in place
  • The actual impact of the warning on performance needs to be validated
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Warning Logic

The warning logic correctly identifies when quantized KV cache is used with --device hrx and warns that attention will run on the CPU. However, the warning only covers cases where --ctk or --ctv are explicitly set to non-f16 values. It does not cover the case where --ctk or --ctv are set to f16 but the default behavior of the system still results in a mismatch with the flash attention matchers. This could lead to confusion if a user explicitly sets f16 but the system defaults to a different type.

if (device == "hrx" && ((!o.ctk.empty() && o.ctk != "f16") || (!o.ctv.empty() && o.ctv != "f16"))) {
    std::fprintf(stderr,
                 "1bit serve: --ctk %s / --ctv %s on --device hrx: the HRX flash-attention matchers take f16 K/V "
                 "only, so attention will run on the CPU (slower, not faster)\n",
                 o.ctk.empty() ? "f16" : o.ctk.c_str(), o.ctv.empty() ? "f16" : o.ctv.c_str());
}

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 58d6d16: READY — it is the warning that makes #3275's new flag safe on HRX, and the reason is checked in the matchers rather than asserted.

// both HRX flash-attention matchers require f16 K/V (dispatch-flash-attention.cpp:247 and :332) and no registration
// accepts a quantised K or V. A quantised cache therefore does not read less -- it makes the matchers DECLINE and
// attention runs on the CPU. Warn once … Not refused: the cpu route serves quantised caches legitimately

Three properties, and each is why this is the right instrument rather than a refusal:

  1. it is accurate about the mechanism — the flag does not reduce the KV read on HRX, it removes the GPU route for attention; a "smaller KV" that silently becomes a large slowdown is worse than no flag at all, and this is the warning that prevents that reading;
  2. a warning, not a 400 — the cpu route serves quantised caches legitimately, so refusing would break a real use to protect another;
  3. it names the two matcher sites (:247, :332), so the day an HRX K/V-quant matcher exists the warning is edited, not "somehow wrong" — and the comment says exactly that.

Test lands in tests/print_backend.sh (+6), the device-free argv/warning row. Draft, so it costs no slot; worth landing with #3275 in c35 if not tonight.

@bong-water-water-bong
bong-water-water-bong marked this pull request as ready for review November 22, 2026 03:30
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Un-drafted: CI is clean and the verdict is READY at 58d6d16. Every check has reported — hrx_build, reviewer, pr_agent, all Analyze/CodeQL SUCCESS, hw_gate SKIPPED (no pin moved), and build finished; mergeStateStatus is CLEAN. Engine carries 2 non-draft PRs with this one, inside the three cap.

It missed the 23:00 cut, so it rides c35 — which costs nothing: it changes no default (f16 stays), it only makes the flag #3275 added shout instead of silently moving attention to the CPU. No rebase pushed, no further commits; the branch is i679/679-kv-fa-warning at 58d6d16.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 58d6d16: READY

The claim is falsifiable and I checked it at the source, in the fork at the engine's current pin (7737fa364):

dispatch-flash-attention.cpp:247   if (query->type != GGML_TYPE_F32 || key->type != GGML_TYPE_F16 || value->type != GGML_TYPE_F16 ||
dispatch-flash-attention.cpp:332   … identical predicate, the second matcher …

key/value must be GGML_TYPE_F16 in both, and neither returns anything else — so a --ctk q8_0 graph makes both matchers return {} and the node falls to whatever else accepts it, which is the CPU. The warning's sentence ("does not read less — it makes the matchers DECLINE") is exactly right, and it is the kind of thing that would otherwise be measured as "q8_0 KV made decode 30 % slower for no reason".

Three things I would keep exactly as they are:

  1. a warning, not a refusal — the cpu route serves quantised caches legitimately, and the comment says the reason: a future HRX K/V-quant matcher should not need this warning edited to become reachable. That is the right side of the line to err on for a foot-gun that only costs speed.
  2. f16 asked for explicitly is silent — the second arm (--ctk f16 → no warning) is what makes the first arm mean something; a warning that fires on every hrx serve would be noise and would be switched off.
  3. the condition is per-flag (!o.ctk.empty() && o.ctk != "f16", and the same for ctv), so --ctk q8_0 --ctv f16 warns and the message prints the effective pair (o.ctk.empty() ? "f16" : …), which is what a reader needs to see.

Placement is right too: inside launch_for, after the -np block and before the argv push, so it fires for hybrid as well — that route recurses into auto_gguf_device(o), which is hrx on this build, and that is the case where the warning matters most because hybrid's decode is the HRX path.

Not run: tests/print_backend.sh needs a 1bit built from this PR (the binaries here predate the flag), so the two arms are read, not executed — the parsing is a two-line else if chain and the arms assert on $scratch/err with exact substrings, so the run is CI's build.

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 58d6d16

@bong-water-water-bong
bong-water-water-bong merged commit 912d47b into main Nov 22, 2026
14 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the i679/679-kv-fa-warning branch November 22, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant