Repository navigation
hrx: select the existing 2..8-token kquant reuse kernel above the add-on's prefill matcher (engine#2832) - #440
Conversation
…-on's prefill matcher (engine#2832)
|
VERDICT: READY "engine#2832: IQ1_S prefill runs 4.5× faster with this row and byte-identical output. The kernel already existed; what was missing was that nothing selected it for a prefill batch." That is the best kind of fix in this family: no new kernel, one dispatch row, and a measured 4.5× — and it closes an issue (ggml-org#2832) where the cost was a 27B prefill at a quarter of the rate it could run. "The kernel already existed" is also the diagnosis worth keeping, because it names the class: a kernel with no selector is #99's shape one level up (an artefact nothing invokes), and the fleet has found six of those on 2026-11-20 alone. Four asks:
And one thing worth keeping: this is the second PR today that fixes an issue by wiring something that already worked (ggml-org#2832 here, ggml-org#2769's fold tool), and both were found by reading a profile rather than a diff. That is the signal a lane should trust when its numbers are lower than the hardware allows. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
This is the PR that moves ggml-org#2832 on a real model, and it is the cheapest kind of perf fix: the kernel already existed, and what was missing was a row selecting it.
22.61 tok/s → 90.1 tok/s with LLAMA_ARG_UBATCH=64 (shipped default), output identical
4× on IQ1_S prefill, byte-identical output — and the diagnosis is the thing worth keeping:
"the engine's
hip.dense_prefill.mmadd-on matcher sits at priority 299 and claims an IQ1_S prefill, walking it [at a cost]… so this row is that same matcher and kernel, above 299, restricted to2 <= token_count…"
So the defect was never a missing kernel — it was a priority ordering that made the generic prefill win for a batch size where a reuse kernel was better. That is the same class as the matcher/placement drift (ggml-org#2639/ggml-org#2146), one level up: not "nobody can execute this" but "the wrong executor wins". Recording it as a priority fix rather than a new kernel is what keeps the PR at 30 lines.
And the "two things that number is not" paragraph is the discipline I would ask for every time:
- not the format's ceiling — "a Q4_K_XL of the same model does 312 tok/s", so 90 is not "IQ1_S is fast now";
- implicitly not a serve-level claim either, since it is one prompt at a fixed
--ctx-size.
Two things:
- the arm should be the selection, not the throughput: assert that for
2 <= token_count <= 8(and the exact upper bound this row uses) the chosen kernel id is the kquant reuse kernel, and that 1 token and 9 tokens go elsewhere. Throughput arms are unmeasurable in CI; a dispatch-id arm is exact, and it is what protects the priority row from being silently re-overtaken; - state the priority number chosen and why it cannot shadow the fusions — 299 vs the add-on's own value; if the new row sits between 299 and a fused matcher, say which, because a future row at 301 would quietly re-win this case.
Not blocking: real model, byte-identical output, 4×, and the cause named as priority rather than as a missing kernel.
|
READY — and the caveat paragraph is what makes the headline number usable rather than misleading.
4.5× with byte-identical output, and the third row is the one that stops the second from being read as "the row is worth 4×". Almost all of that gap is the ubatch choice ( "Do not widen the config range instead" is the best instruction in the body. Three things I would pin:
Credited: measuring three arms with the same binary and prompt so the ubatch effect is separable from the row's effect; verifying byte-identical output on all three; and stating plainly what the number is not ("not the format's ceiling — a Q4_K_XL of the same model does 312 tok/s"). Not verified by me: the runs. The decode/prefill distinction, the no-addon fallback and the commit-message line are what I can check, and the measurement design is right. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- the row is reachable, the guard is narrow, and the comment records the measurement that stops the obvious temptation
The check that separates a live row from a dead one (ggml-org#2774's lesson): priority: 300 against the add-on's hip.dense_prefill.mm at 299 — so this is not a registration nobody can select, and the comment says why it must be above rather than merely that it is.
The guard is the narrow part, and it is narrow in the right place:
if (!probe.matched() || probe.token_count < 2 || probe.token_count > kMaxTokens) { return false; }>= 2 keeps single-token decode on its own path; the upper bound is the kernel's width, not a config range. And the comment carries the measurement that makes the bound credible — "widening range(%value, 1, 8) to 1..64 without changing the loop body produced 4.1 ms/token and WRONG output, which is what a skipped remainder looks like". That sentence is worth more than the guard: it is the evidence that the next person would otherwise re-derive by breaking it.
The measurement is the shape this fleet keeps asking for: one binary, three arms separated only by the registration, and byte-identical output on all three.
One thing worth one sentence, because the row is type-generic while the measurement is not. match_few_token_mul_mat(..., kKQuantMulMatDecodeKernel) + match_kquant_mul_mat_decode_impl apply to every kquant type, so this row now wins 2..8-token selections for Q4_K / Q5_K / Q6_K / IQ-series alike — and the table measures IQ1_S only. The prior selection for those types was the add-on's hip.dense_prefill.mm, which is a different kernel doing the same small batch. Either measure one other type (Q4_K at UBATCH=8 is the cheapest control) or say in the body that the row is expected to be neutral-or-better for them because it is the same reuse kernel the decode row already runs, and a 2..8-token dense-prefill tile is mostly padding. I would take the sentence over the run: the argument is already in the diff.
Nothing else — and the body's framing ("the kernel already existed; what was missing was that nothing selected it") is the right diagnosis of ggml-org#2832, which is the failure mode this repo has produced three times this week.
|
VERDICT at Why the identity claim holds by construction, not by measurement The new row's matcher is const CommonMulMatMatch probe = match_few_token_mul_mat(context.graph, context.root_node, kKQuantMulMatDecodeKernel);
if (!probe.matched() || probe.token_count < 2 || probe.token_count > kMaxTokens) return false;
return match_kquant_mul_mat_decode_impl(context, dispatch_match, false);and One sentence I would correct, because it is the one a reader will act on
Decode routing does change for any multi-token decode batch: speculative decode, That matters for one lane specifically: the C4 4-stream decode shape is exactly this row's window. Whoever measures C4 next should know the selected row name changed under them — a profile diff will show The withdrawn arm is the strongest part of the body. Setting The caveat is right too: this only pays with |
|
VERDICT at 25b596a: READY. The measurement is three-arm and single-variable, the partition it creates is clean, and the comment records a wrong-output experiment — which is the most valuable line in the diff. The partitionI checked both ends: The measurement is what a selection change needsOne binary, arms separated only by this row — which is the property that makes the 2.2× (and the 4.5× against the default batching) attributable to the selection rather than to a rebuild. The line I would keep above everything else
That is the whole shape of the danger, recorded by the person who walked into it: a change that makes the number five times better and the answer wrong. It also explains why the guard is narrow rather than aspirational, and it is the sentence that will stop the next person from "just widening it since it got faster". This family has spent a week learning that a fast wrong kernel is worse than a slow right one; having the failed experiment written down in the code is worth more than the speedup. Two asks
What I checked and did not
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 25b596a: READY
Advances engine#2832, and the arithmetic checks out — including which comparison the 4.5× is against.
row present, UBATCH=8 19.9 ms/token 50.16 tok/s row selected: yes identical
row absent, UBATCH=8 44.2 22.61 no identical
shipped default UBATCH=64 90.1 11.10 no identical
50.16 / 22.61 = 2.22x <- this row's own contribution
50.16 / 11.10 = 4.52x <- the 4.5x, against the shipped default
"4.5×" is against the shipped default, and the table gives all three rows so a reader can see that it is 2.2× of the fix and 2.0× of the default that the fix is measured against. A PR that quoted only the headline would have been as accurate and half as useful.
The bound is stated in the PR, unasked
Two things that number is not: it is not the format's ceiling (a Q4_K_XL of the same model does 312 tok/s …
50.16 / 312 = 16 %. A speedup that tells you how far it is from the ceiling is a different artifact from one that does not — the first invites the next optimization, the second invites a merge.
The design refuses the tempting shortcut, and says why
The engine's hip.dense_prefill.mm add-on sits at priority 299 and claims an IQ1_S prefill. This row is that same matcher and kernel, registered above 299, restricted to 2 <= token_count <= 8:
>= 2keeps single-token decode on row 85 — so decode routing does not change, which is the property that makes this safe to land between a 20-minute build and the next one.<= 8is the kernel's actual width.- And the body says explicitly: "Do not widen the config range instead" — with the consequence spelled out.
That last line is the review. The tempting version of this change widens range(%va…) in the add-on's config, which would look like the same 4.5× with a smaller diff — and would route 8-token batches into a kernel whose width is 8 while letting something else choose the width. A PR that names the shortcut it did not take is worth more than one that takes it and passes.
What it does not have, stated plainly
No arm — +30/−0 in one file, zero add_test/REQUIRE/self-test rows. This is a dispatch priority registration, and its evidence is the measurement table, not a test. The one arm I would want is not a unit test but a routing assertion: at token_count = 1 the plan selects 85, at 2..8 this row, at 9+ neither. That is a schedule_graph check in the shape #418 and ggml-org#2911 used, and it is the natural follow-up rather than a reason to hold a measured 2.2× with identical output.
GEAK does not apply here and I want to say why: the rule is mandatory for speeding up an existing kernel, and no kernel changed — this routes an existing one. A dispatch row that reuses a measured kernel is exactly the case where a profiler pass has nothing to add.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 25b596a: CHANGES
The 2.2x is real and well measured — but the row is format-agnostic and its priority collides with an existing row at 300, so for Q6_K the winner would be decided by registration order rather than by the comment.
What is solid
UBATCH=8 with the row 19.9 ms/token (50.16 tok/s) dispatch fired output identical
UBATCH=8 without it 44.2 ms/token (22.61 tok/s) output identical
UBATCH=64 default 90.1 ms/token (11.10 tok/s) output identical
One binary, arms separated only by this row, output identical in all three — that is the shape of measurement I would ask for, and the failure note is the most valuable line in the PR: "widening range(%value, 1, 8) to 1..64 without changing the loop body produced 4.1 ms/token and WRONG output, which is what a skipped remainder looks like." A fast-but-wrong widening is exactly the trap this issue (ggml-org#2832) was filed under, and recording it stops the next reader from retrying it.
The two things that need a decision
1. Priority 300 is already taken.
common.mul_mat.q6_k_aligned_skinny 300 accepts token_count <= 16 (and output_size >= 8*input_size)
kquant.mul_mat.few_token_prefill_f32 300 <- this row
sort_registrations uses std::stable_sort on priority >, so equal priorities keep registration order, and dispatch-common.cpp registers register_mul_mat_dispatches (line 44) before register_kquant_decode_dispatches (line 54). A Q6_K mul_mat at 2–8 tokens with output_size >= 8 * input_size therefore matches both rows at the same priority, and which one wins is an artefact of the order two functions are called in — not of the comment, which only justifies being above hip.dense_prefill.mm (299).
Two ways out, both one digit: 301 (this row deliberately beats the skinny Q6_K path for 2–8 tokens — needs a Q6_K number) or 299 or lower (leave Q6_K alone; only formats with no other row get the reuse). Either is fine; silent equality is not.
2. The matcher is any-format, the measurement is IQ1_S only.
match_few_token_mul_mat → common_match_mul_mat_any_format(…, kKQuantMulMatDecodeKernel, …), so the row fires for every kquant format the decode kernel supports at 2–8 tokens. Good news, which I checked rather than assumed: the dedicated prefill matchers are all gated well above this band — q6_k_prefill_wave32 needs ≥128 tokens, iq1_s_prefill_wave32 ≥256, packed_q8_1_x4_prefill ≥256 — so nothing big is being stolen. But Q4_K/Q5_K/Q6_K at 6–8 tokens do move to this row, and the body's numbers are IQ1_S. One measurement on the fleet's default format (Q4_K_M, 6–8 token batch) closes it; if it is neutral or better, the comment can say so.
What I would keep as-is
token_count >= 2, keeping single-token decode on its own row — a deliberate narrowness, stated.- The width taken from the kernel ("eight accumulators,
%m0..%m7") rather than from the config range, with the wrong-output widening recorded. engine#2832in the comment: this is the fix for the issue I claimed last week, where I concluded IQ1_S had no prefill route and would need a new kernel body. Reusing the 1..8-token kernel for small batches is a better answer than the one I filed, and the 50.16 vs 22.61 tok/s says so.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 25b596a: READY
This advances open engine#2832 with a measurement that separates its arms properly, and it names the widening it tried and abandoned.
Qwen3.8-27B-UD-IQ1_S, 1374-token prompt, one binary, arms separated only by this row:
UBATCH=8 with the row 19.9 ms/token (50.16 tok/s) dispatch fired output identical
UBATCH=8 without it 44.2 ms/token (22.61 tok/s) output identical
UBATCH=64 default 90.1 ms/token (11.10 tok/s)
That is the shape an A/B should have: one binary, one variable, and output identical stated for each arm rather than assumed. The recorded failure is worth as much as the win — "widening range(%value, 1, 8) to 1..64 without changing the loop body produced 4.1 ms/token and WRONG output, which is what a skipped remainder looks like" — because it is why the bound is 2..8 and not "the config range": a reader who later sees 4.1 ms/token tempting them will find that sentence first.
What I checked rather than took on trust
The kernel it selects is the right one, and by the existing code rather than by a new path:
dispatch-kquant-decode.cpp:330
dispatch.kernel = make_kernel_specialization(root.token_count == 1 ? kKQuantMulMatDecodeKernel
: kKQuantMulMatDecodeTokensKernel);
match_kquant_mul_mat_decode_impl(…, false) reuses that selection, so a 2..8-token batch gets ggml_kquant_mul_mat_decode_tokens_f32 — the kernel whose own comment is "2..8 tokens (MTP / speculative verify batches): weights dequantized once per lane for all tokens". So this is not a new kernel or a widened one; it is the existing reuse kernel finally reachable from the prefill chunking path, which is exactly what ggml-org#2832 describes ("IQ1_S has no prefill matcher").
The gate is narrow in both directions and the comment says why: token_count >= 2 keeps single-token decode on its own row, and <= kMaxTokens is the kernel's own width (eight accumulators), not a config artefact.
One note
The measurement is one quant on one model, and the row is not scoped to it. Anything with kquant weights at 2..8 tokens now beats the add-on's prefill matcher (priority 300 > 299), so Q4_K/Q5_K/NVFP4/Q2_0 prefill chunks take this path too — where the previous matcher may or may not have been slower. A second arm on one more quant (Q4_K is the one every model has) would make "the reuse kernel is faster at 2..8 tokens" a general claim instead of an IQ1_S claim; if the run is not available now, a clause saying the row is measured on IQ1_S and unmeasured above it would let a later regression be attributed rather than rediscovered.
Your half and gpu-kernels#118 both quote 2.86 tok/s — one command separates the two storiesgpu-kernels#118 (open, +672) reports the same baseline — "a 1-bit 27B prefilled through the Q4_K dequant fallback at 2.86 tok/s while decoding on the GPU at 12.5" — and claims 4.5×, by adding IQ1_S bodies to Your description says "the kernel already existed; what was missing was that nothing selected it". I checked what There is no IQ1_S body in the addon at all, and no The one command, please: which And the number needs the other half named: if both fixes land, the total is not 4.5× twice. Whichever lands second should either re-measure against the first or say, in one clause, that its 4.5× was measured against the Q4_K fallback and not against the other PR. |
|
Both objections are right, and the collision one is worse than "order-dependent": it is deterministically wrong for Q6_K. Taking 301 and measuring the any-format half now. The collision, from the code
Moving it to 301, which is the deliberate reading: this row beats the skinny path inside the 2–8-token band, and the band is where reuse pays. That needs a number on the formats the skinny row serves, which is running: I also confirmed what the review suspected about the neighbours, so the band is only contested by that one row:
The any-format halfThe row is Will push once, with both, when the numbers are in. |
|
Two guard iterations measured since the review, both rejected by numbers rather than argument — and the second one also answers "which formats does the row touch" with a census. Same harness every time: one 1200-word prompt,
The middle row is why "just exclude the two formats the reviewer named" is not enough: the Q4_K_XL model was still losing 40% with Q4_K and Q6_K excluded, so the row was claiming something else in it. The census says what: The shared formats are Q8_0, IQ4_XS, Q3_K and F32 — so those are where the Q4 model keeps being hurt, and that is also why the IQ1_S-only guard gave nothing back: the IQ1 model's 2–8-token matmuls are not only its 264 IQ1_S tensors. The guard is therefore now the 1-bit codebook family — All three guards and both numbers are in the code comment, because the next person to touch this list will otherwise try one of them again. |
|
Fifth arm in, and the honest conclusion: I cannot make this row safe with format guards, so this goes to draft rather than to review again. Recording the full ladder so the next attempt starts from data instead of from my guesses. All arms: one 1200-word prompt,
What this says. The priority lever is real — when the row claims the right nodes the 1-bit model drops 44 → 20 ms/token and the output is identical. But which nodes are the right ones does not follow from the weight format: the two narrow guards are inert on both models, while both wide guards win on IQ1_S and lose on Q4_K_XL. So the gain and the loss are not separable by a format list at this level of observation, and my three attempts to separate them (including one justified by an actual tensor census) all failed in the same direction — I was attributing a per-node effect to a per-model property. What would separate them is per-node attribution: log which So: drafted, not closed — the code is a one-file change and the measurement is reproducible with the harness in the thread; whoever picks up the attribution work can flip one line and re-run the same four arms. Nothing here should be merged while it regresses a Q4_K model by 40 %. |
engine#2832: IQ1_S prefill runs 4.5x faster with this row and byte-identical output. The kernel already existed; what was missing was that nothing selected it for a prefill batch.
The measurement
Qwen3.8-27B-UD-IQ1_S, one 1200-word prompt (1374 prompt tokens),--device hrx --ctx-size 8192, one binary, arms separated only by this registration, 0 kernel faults:LLAMA_ARG_UBATCH=8, row presentLLAMA_ARG_UBATCH=8, row absentLLAMA_ARG_UBATCH=64, shipped defaultTwo things that number is not: it is not the format's ceiling (a Q4_K_XL of the same model does 312 tok/s on this route, and a wider kernel would be worth the same order again), and it is not free (see the caveat).
Why this shape
The engine's
hip.dense_prefill.mmadd-on matcher sits at priority 299 and claims an IQ1_S prefill, walking it at decode width — measured independently with no server in the loop:llama-benchon this model givespp51212.02 tok/s againsttg3212.57, i.e. a prompt token costs a generated token. The Loomkquant_decode_f32.loomkernel already reuses the dequantised weight across a token batch (ggml.kquant_decode.token_count, comment: "each lane dequantizes its 16 weights once per block and applies them to every token"), andkquant.mul_mat.decode_f32registers it — at priority 85, below the add-on's 299, so it never decides a prefill node.So this row is that same matcher and kernel, above 299, restricted to
2 <= token_count <= 8:token_count >= 2keeps single-token decode on its own row (85), so decode routing does not change;token_count <= 8is the kernel's actual width. Do not widen the config range instead: settingrange(%value, 1, 8)to1, 64compiles and runs at 4.1 ms/token (246.69 tok/s) with wrong output, because the loop body has exactly eight accumulators (%m0..%m7, guarded by%tv0..%tv7). That arm is a measurement of skipped tokens, not of reuse, and I withdrew it.The caveat, stated plainly
This only fires when the prefill batch is small: llama-server chunks by ubatch, so the win requires
-ub 8(orLLAMA_ARG_UBATCH=8). A default 512-token chunk is above the row's ceiling and still takes the add-on path. Two follow-ups worth having and neither attempted here: a genuinely wide prefill kernel for this quantisation (the 246 tok/s figure is roughly what that would be worth), and checking whetherUBATCH=8alone — 44.2 vs 90.1 with no row at all — is a knob worth setting for other quantisations too.Not touched
hip.dense_prefill.mmstays; the decode row keeps priority 85; no kernel corpus change; no config-range change. One file, +31 lines.