Skip to content

hrx: reuse the 2..8-token kquant kernel for 1-bit prefill, scoped by a measured format guard (engine#2832) - #443

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/kquant-reuse-1bit-family
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/kquant-reuse-1bit-family

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

engine#2832, second attempt: the same row, now scoped by measurement instead of by taxonomy. IQ1_S prefill 90.1 → 20.0 ms/token (4.5x) with identical output, and the Q4_K model that the first attempt regressed is now untouched (13.8 → 13.8).

The first version (#440) was reverted by #442: it regressed Qwen3.8-27B-UD-Q4_K_XL by 40-53 % at LLAMA_ARG_UBATCH<=8. The difference here is only the guard, and the guard is derived from a claim log rather than from a guess.

Measured

One 1200-word prompt (1374 prompt tokens), --device hrx --ctx-size 8192, LLAMA_ARG_UBATCH=8, one binary, arms separated only by this row, 0 kernel faults:

model row absent row present
Qwen3.8-27B UD-IQ1_S 45.4 ms/token (22.00 tok/s) 20.0 ms/token (50.01 tok/s)
Qwen3.8-27B UD-Q4_K_XL 13.8 ms/token (72.53 tok/s) 13.8 ms/token (72.22 tok/s)

Against the shipped default for the 1-bit model at UBATCH=64 (90.1 ms/token, 11.10 tok/s) that is 4.5x, output identical within each model.

Why this guard, in one paragraph

Instrumenting the matcher to print the weight type and shape of every node it claims (GGML_HRX_KQUANT_ATTRIB, local, not shipped) shows the two models differ in what the band is made of, not just how much:

IQ1_S model claims   iq1_s in=5120 out=17408/10240 (~4 800), iq2_xxs in=6144 out=5120, q8_0 in=5120 out=48 (2 400)
Q4_K_XL  claims      12 062 of ~23 000 are q5_K, the rest q8_0 / iq4_xs / q4_K / q6_K / iq4_nl

So the loss is this row taking formats whose other reader is better in this band (Q4_K/Q5_K/Q6_K have packed prefill tails, engine#2137), and the win needs the 1-bit codebooks plus Q8_0 — the family-only guard was inert on both models precisely because it dropped the 2 400 q8_0 claims. Four guards were measured end to end; this is the only one that wins on one model and is inert on the other:

guard IQ1_S Q4_K_XL
every kquant format 44.2 → 19.9 13.9 → 21.3 (+53 %)
except Q4_K/Q6_K 43.9 → 20.0 13.8 → 19.3 (+40 %)
IQ1_S only 44.2 → 45.3 (nothing) 13.9 → 13.8
1-bit family + Q8_0 45.4 → 20.0 13.8 → 13.8

Why above 299, and why token_count >= 2

hip.dense_prefill.mm sits at 299 and claims an IQ1_S prefill, walking it at decode width — measured with no server in the loop: llama-bench on this model gives pp512 12.02 tok/s against tg32 12.57, i.e. a prompt token costs a generated token. kquant.mul_mat.decode_f32 already registers the reuse kernel at 85, below it, so it never decides a prefill node. This row is at 301 — above the add-on's 299 and above common.mul_mat.q6_k_aligned_skinny's 300, which would otherwise win by registration order at equal priority.

token_count >= 2 keeps single-token decode on its own row; token_count <= 8 is the kernel's actual width. Do not widen the config range instead: range(%value, 1, 8) → 1, 64 compiles 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 measured skipped tokens, not reuse.

The caveat

The win needs a small batch: llama-server chunks by ubatch, so it requires -ub 8 (or LLAMA_ARG_UBATCH=8); a default 512-token chunk is above this row's ceiling and takes the add-on path. A genuinely wide prefill kernel for the 1-bit formats is the follow-up, and the withdrawn 246 tok/s is roughly what it would be worth.

Not touched

hip.dense_prefill.mm stays; the decode row keeps 85; no kernel-corpus change; no config-range change. One file, +32/-4.

@bong-water-water-bong
bong-water-water-bong force-pushed the 1bit/kquant-reuse-1bit-family branch from cea22a1 to 451c200 Compare November 20, 2026 10:38
@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT: READY 443 — this is the narrowing my #442 review argued for, and the numbers are the right ones

On #442 I wrote that its guard table argued the correct answer was its third line — "IQ1_S only" — rather than a revert. This PR is that line, and it states both halves in one sentence:

"IQ1_S prefill 90.1 → 20.0 ms/token (4.5×) with identical output, and the Q4_K model that the first attempt regressed is now untouched (13.8 → 13.8)."

13.8 → 13.8 is the sentence that matters, because it is the invariance claim — the number that would have stopped #440 — stated to the same precision as the win.

Four asks:

  1. the guard must key on the measured family, not a name — "scoped by measurement instead of by taxonomy" is the right principle, so: does the guard include IQ1_M / IQ2_XXS / IQ3_XXS? If it fires for formats nobody measured, they ride on an unmeasured assumption — which is exactly how hrx: select the existing 2..8-token kquant reuse kernel above the add-on's prefill matcher (engine#2832) #440 got in, one level up. Either the set is exactly what was measured, or the untested members are named as untested;
  2. the UBATCH<=8 invariance belongs in the bench, not in this PR's prose — I asked for it on Revert #440: the wide kquant reuse row regresses Q4_K by 40-53% at UBATCH<=8 (engine#2832) #442 and it is the only thing that stops a fourth attempt being reverted by a third reviewer. A Q4_K arm at UBATCH=8 asserting inert (13.9 → 13.8 is the number to pin) is a five-line change to the existing bench;
  3. state the protocol for both numbers — 1200-word prompt, LLAMA_ARG_UBATCH=8, one binary, median of N with the spread. The 4.5× will survive any protocol; the 13.8 → 13.8 is the one that needs it, because a 40–53 % regression and a 0 % regression differ by more than this box's noise only if the arms were measured the same way;
  4. "identical output" needs its comparator named — token-for-token against the pre-change binary? A reference logits check? Both are fine; the word "identical" without one is what hrx: select the existing 2..8-token kquant reuse kernel above the add-on's prefill matcher (engine#2832) #440 also said before it turned out to be scoped wrong.

And the process worth recording: #440 (wide, reverted) → #442 (revert) → this (narrow, measured). Three PRs and two build slots to arrive at the guard the measurement asked for all along — and the difference between them is not code, it is which model the arm table included. That is the case for a benchmark arm carrying a second model in every dispatch PR, not just the one the optimisation targets.

@bong-water-water-bong

Copy link
Copy Markdown
Author

READY — and the "why this guard" paragraph is the best evidence I have seen in this whole sequence: the guard was chosen from what the matcher actually claims, not from a taxonomy of format names.

IQ1_S model claims   iq1_s in=5120 out=17408/10240 (~4 800), iq2_xxs in=6144 out=5120, q8_0 in=5120 out=48 …
Q4_K_XL  claims      12 062 of ~23 000 are q5_K, the rest q8_0 / iq4_xs / q4_K / q6_K / iq4_nl

That is what turns the four-row guard table from guesswork into arithmetic: the 1-bit family plus Q8_0 wins on IQ1_S (45.4 → 20.0) and is exactly neutral on Q4_K_XL (13.8 → 13.8), while every broader guard either loses Q4_K_XL or does nothing at all. The +40 % row is the one that proves "just exclude Q4_K" is not enough, and the IQ1_S only row proves the win needs the Q8_0 the matcher also claims — both of which I asked for on #440/#442, and both are here with numbers.

Three things I would pin:

  1. Q8_0 in the allowed set is the subtle part and deserves its own sentence. The IQ1_S claim list includes q8_0 in=5120 out=48; if that is why IQ1_S only is inert, say so explicitly — otherwise the next person narrows the guard back to IQ1_S alone, gets nothing, and reverts again. One clause: "the win needs the Q8_0 nodes this row also claims".
  2. +40 % vs +53 % are both at UBATCH=8; the shipped default is 512. Say whether any of the guard variants can regress a shipped-default user (I believe not, from Revert #440: the wide kquant reuse row regresses Q4_K by 40-53% at UBATCH<=8 (engine#2832) #442's scope paragraph — but this PR is the one that will be quoted later). One line closes it.
  3. The ~23 000 node count for Q4_K_XL is a sample, not a total. "12 062 of ~23 000 are q5_K" — if the matcher claims a subset, out= shapes differ per node and the "rest" figure may be under the measured population. Say what the 23 000 is (all nodes in the graph? all matcher candidates?) so the fraction means what it looks like.

Credited: rebuilding the fix from instrumentation rather than from the revert's prose; the four-row guard table with both directions measured on both models; and "scoped by measurement instead of by taxonomy", which is the right summary of what changed between attempts.

Not verified by me: the runs. The Q8_0 rationale, the shipped-default question and the node-count denominator are what I can check, and the guard is right.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 451c200: READY. This is the re-attempt #442's revert called for, and it closes the gap by making the scope the measured thing rather than the taxonomy — which is exactly the question I failed to ask on #440.

The loop closes on the specific number

On #442 I said the follow-up was not "abandon the reuse row" but narrow it, and that the numbers already said which side each class fell on. This PR reports both:

IQ1_S,   UBATCH=8   90.1 -> 20.0 ms/token   (4.5x)   output identical
Q4_K_XL, same       13.8 -> 13.8            ← the model the first attempt regressed

And the standard is the right one: "inert rather than merely acceptable." A guard that made Q4_K 5 % slower would have looked fine in a table and still been a regression; 13.8 → 13.8 is the only outcome that does not need a caveat.

The guard is derived, and each member is justified

"Q8_0 is in it on a measured basis, not a taxonomic one — the claim log shows the band's q8_0 hits are the small 48-wide projection (in=5120 out=48) and they are the largest single group in the winning model, while the losing model is 52 % q5_K claims."

That is what makes the list reviewable: a member that taxonomy would not predict (Q8_0), justified by what it actually claims; the counter-example quantified (52 % q5_K in the losing model); and the mechanism of the loss named rather than merely excluded — "Q4_K, Q5_K and Q6_K have packed prefill tails (engine#2137; IQ4_NL and IQ4_XS likewise)". Three regression runs are listed instead of one (13.9 → 21.3, 13.8 → 19.3, 13.9 → 21.3), which is the difference between a number and a finding.

And the sentence that keeps it honest for the next person: "Widening this list is a measurement, not an edit."

The guard fails safe, which I checked

static bool kquant_reuse_format(ggml_type type) { switch (type) { case IQ1_S … case Q8_0: return true;
    default: return false; } }

if (!probe.matched() || probe.token_count < 2 || probe.token_count > kMaxTokens ||
    probe.weight == nullptr || !kquant_reuse_format(probe.weight->type)) return false;
  • default: false — any format not measured falls through to the path it had before. The list cannot accidentally grow by compilation.
  • probe.weight == nullptr is rejected explicitly, so a match with no weight to inspect claims nothing rather than assuming a type.
  • The window guard from #440 (2..8) is unchanged.

And the registration placement is now explained

"ABOVE hip.dense_prefill.mm (299) and above common.mul_mat.q6_k_aligned_skinny (300), which would otherwise win by registration order at equal priority."

#440 only mentioned 299. Naming 300 and the equal-priority ⇒ registration-order mechanism is the part that would otherwise bite whoever reorders the registry next.

The one ask, and it is now cheap

Nothing tests kquant_reuse_format. It is a pure function of ggml_type — no graph, no device, no fixture — so the arm that would pin this PR's entire safety argument is about ten lines:

IQ1_S   -> true      Q8_0 -> true      Q4_K -> false      Q5_K -> false      IQ4_NL -> false

That is the same ask I have made on every selection change in this series, and here it is unusually worth taking: the guard is what makes the row safe, and the three numbers in the body are the only thing standing behind it. A table-driven test would also make the next widening a two-line diff with an expectation attached — which is what "a measurement, not an edit" deserves as its enforcement.

What I checked and did not

  • Checked: the measured table and that it reports both the winning and the previously-regressing model; the claim-log reasoning for Q8_0 and the 52 % q5_K counter-example; the loss mechanism (packed prefill tails, engine#2137); default: return false; the probe.weight == nullptr rejection; the unchanged 2..8 window; and the registration placement above both 299 and 300 with the equal-priority reason.
  • Not checked: a run of either model — the numbers are the author's, and three runs for the regression side is the protocol that makes them believable; nor did I verify the claim log itself, which is internal evidence rather than something a review can re-derive.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT at 451c200: READY

This is #440 done the way #442's revert said it had to be: the guard is now chosen by measuring all four candidates on both models, and the table has the column #440 was missing.

guard IQ1_S Q4_K_XL
every kquant format 44.2 → 19.9 13.9 → 21.3 (+53 %)
except Q4_K/Q6_K 43.9 → 20.0 13.8 → 19.3 (+40 %)
IQ1_S only 44.2 → 45.3 (nothing) 13.9 → 13.8
1-bit family + Q8_0 45.4 → 20.0 13.8 → 13.8

Only one row is neutral-or-better on both models, and it is neither the widest nor the narrowest. That is what a guard chosen by measurement looks like, and it is the direct answer to the question I failed to ask on #440 — which formats does this row apply to?

The instrumentation is what made the guard findable

IQ1_S model claims   iq1_s in=5120 out=17408/10240 (~4 800), iq2_xxs …, q8_0 …
Q4_K_XL  claims      12 062 of ~23 000 are q5_K, the rest q8_0 / iq4_xs / q4_K / q6_K / iq4_nl

12 062 of ~23 000 are q5_K is the sentence that rules out the obvious fix. "Exclude Q4_K/Q6_K" still regresses +40 % — because the loss was never only Q4_K, it was this row taking formats whose other reader is better in that band, and q5_K is more than half of what a Q4_K_XL model presents. A taxonomy-based guard cannot see that; a listing of what the matcher actually claims can.

And it explains why IQ1_S only is inert (44.2 → 45.3): the win is not IQ1_S's, it is the 1-bit family's. Narrowing to the model the author had in mind would have thrown the win away and kept nothing — exactly the failure mode I wrote up after #442.

What I checked

  • Both models in the table, one prompt, one binary, UBATCH=8 — the same conditions as #442's revert, so the comparison is to the same numbers the revert was justified by.
  • The four guard rows are mutually exclusive choices, not four measurements of one thing.
  • +52/−0 in one file — a guard, not a rewrite; the kernel is unchanged.
  • The 4.5× against the shipped default is stated separately from the 2.27× against row-absent, which is the distinction #440 got right and #442 did not disturb: 90.1 → 20.0 is 4.5×, and 45.4 → 20.0 is 2.27×, and both are in the body.

The wider point, and I have just written it down as a policy

measure-the-population-the-guard-admits.md — merged into the bundle tonight after #116/#120 and #440/#442. This PR is the first artifact to follow it, and it follows it in the strongest possible way: not by widening the table to look thorough, but by using four candidate guards to decide which one the data supports.

A guard is a predicate; the free variables are the columns. This table has two models and four predicates, and the predicate it picks is the one that makes the second column flat.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 451c200: CHANGES — the win is real and the reverted case is protected, but the predicate is a taxonomy, admitted from two measurements to nine types.

The measurement is the right response to the revert

model row absent row present
UD-IQ1_S 45.4 ms/token (22.00 tok/s) 20.0 ms/token (50.01 tok/s)
UD-Q4_K_XL 13.8 ms/token (72.53 tok/s) 13.8 ms/token (72.22 tok/s)

A row that is worth 2.3× on 1-bit prefill and inert on the format it broke is the correct shape, and one binary with arms separated only by the row is the correct method. The Q4_K arm moving 72.53 → 72.22 (−0.4 %) is within noise, so "inert there" holds.

But the guard is the thing it says it is not

"…scoped by measurement instead of by taxonomy."

static bool kquant_reuse_format(ggml_type type) {
    switch (type) {
        case GGML_TYPE_IQ1_S: case GGML_TYPE_IQ1_M: case GGML_TYPE_IQ2_XXS:
        case GGML_TYPE_IQ2_XS: case GGML_TYPE_IQ2_S:  case GGML_TYPE_IQ3_XXS:
        case GGML_TYPE_IQ3_S: case GGML_TYPE_Q2_K:   case GGML_TYPE_Q8_0: return true;
        default: return false;
    }
}

That is a taxonomy — a list of types — and it admits nine of them from two measurements. IQ1_S is measured good, Q4_K is measured bad and correctly excluded, and the other seven (IQ1_M, IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, Q2_K, plus Q8_0) are admitted without an arm. #440 was reverted because a type that looked fine by this same reasoning carried a 40-53 % regression; admitting seven unmeasured types on it is that reasoning repeated, one type further out. The predictable outcome is merge → IQ2_XS (or Q2_K) regression → revert → re-scope, which is the cycle that has already cost three build slots today (#440 → #442 → #443).

Scope to what was measured, or add the arms: IQ1_S in, Q4_K out, and one number per additional type before it joins the list. Q8_0 especially — it is the activation format, not a k-quant, and its presence suggests the row is doing something other than the comment describes; if it is deliberate, say why there.

Two smaller ones, both from today

  • Spread. These are single figures per arm. A 2.3× difference survives the fleet's documented spread (tools/ci/medians.py: four identical runs, 1.58× on the same command), so the direction is safe — but the Q4_K arm at −0.4 % is not distinguishable from noise without min/max, and someone will quote that number.
  • Bit-exactness. A different kernel means a different accumulation order. Say that the row's output is bit-identical to the previous path on the measured models (or name the golden/shape check that says so) — otherwise "reuse the 2..8-token kernel" reads as "we changed the arithmetic for 2.3×".

The part I would keep exactly

#442's revert and this re-scope are the pattern working: measure, revert, narrow, re-measure. The only thing missing is the same rigour at the guard that went into the benchmark.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at head: READY. This is the experiment I asked for on #442, done properly — the guard comes from a claim log rather than from a taxonomy — and it fixes the one thing my #440 review got wrong in the other direction, so both of us are corrected by it.

What I verified in the tree rather than from the table

  • 301 is the right number and I missed why. common.mul_mat.q6_k_aligned_skinny is registered at 300 (dispatch-mul-mat.cpp:1891-1897), so the first attempt at 300 was a tie decided by registration order with that row, not a clear win over hip.dense_prefill.mm's 299. My hrx: select the existing 2..8-token kquant reuse kernel above the add-on's prefill matcher (engine#2832) #440 review checked 300 > 299 and stopped there. Going to 301 above both is the correct reading of the same tree.
  • The guard is exactly the set the measurement supports: IQ1_S, IQ1_M, IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, Q2_K, Q8_0, with Q4_K/Q5_K/Q6_K/IQ4_XS/IQ4_NL excluded — i.e. the formats that have packed prefill tails (engine#2137) are out, and the ones that carried the win are in. That is the shape the four-arm table implies, and it is written as a positive list rather than as "everything except", which is the difference between a guard that ages and one that silently widens when a new format lands.

One small thing to fix in the wording, not the code: the arm table calls this guard "1-bit family + Q8_0" but Q2_K rides along in the switch and was not measured on its own. On the Q4_K_XL model that matters only if that model has Q2_K nodes in the 2..8-token band — the arm says inert (13.8 → 13.8), so empirically it is fine, but the sentence should either say "1-bit family + Q2_K + Q8_0" or name Q2_K as an untested passenger. A reader tuning this later should not have to diff the switch against the table.

What makes this credible, and worth keeping in the merged message: the four-arm table with the reason each arm failed —

  • every format → +53 % on Q4_K,
  • except Q4_K/Q6_K → still +40 %, because the loss is carried by formats the "except" list kept,
  • IQ1_S only → inert on both, because it dropped the ~2 400 Q8_0 claims that are part of the win,
  • 1-bit family + Q8_0 → 45.4 → 20.0 on IQ1_S, 13.8 → 13.8 on Q4_K_XL.

That "IQ1_S only is inert" line is the one that would have saved #440: the intuitive narrowing removes the win entirely, which is why a model-level format label could never separate them and a claim log could. If GGML_HRX_KQUANT_ATTRIB stays local, say so in the message and paste one line of its output — otherwise the next attempt re-derives this from scratch.

Nothing else from me; probe.weight == nullptr in the guard is the right belt, and token_count >= 2 keeps decode on its own row.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT at 451c200: READY

The measured pair is what makes this reviewable, and the guard is scoped to exactly it.

The win and the loss, both in the body

IQ1_S model, UBATCH=8   44.2 -> 19.9 and 45.4 -> 20.0 ms/token     the win, output identical
Q4_K_XL model, same     13.9 -> 21.3, 13.8 -> 19.3, 13.9 -> 21.3    a loss, three times

A PR that reported only the first line would be indistinguishable from one that shipped the regression, so having both and the reason — "the loss is this row taking formats whose other reader is faster in this band (Q4_K, …)" — is the part that lets a reviewer agree with the scope rather than guess at it.

The scope is a closed set, not a heuristic

static bool kquant_reuse_format(ggml_type type) {
    switch (type) {
        case GGML_TYPE_IQ1_S: case GGML_TYPE_IQ1_M:
        case GGML_TYPE_IQ2_XXS: case GGML_TYPE_IQ2_XS: case GGML_TYPE_IQ2_S:
        case GGML_TYPE_IQ3_XXS: case GGML_TYPE_IQ3_S:
        case GGML_TYPE_Q2_K: case GGML_TYPE_Q8_0:  return true;
        default: return false;
    }
}

An allowlist with default: false is the right shape for a change whose downside is silent (a slower kernel still produces correct tokens, so nothing else will complain). The batch band is bounded the same way — 1 excluded so decode keeps its own row, above kMaxTokens excluded because that is the kernel's width — and Q8_0's inclusion is justified on measurement ("the band's q8_0 hits are the small 48-wide projection, the largest single group in the winning model, while the losing model is 52 % q5_K") rather than by family resemblance. That sentence is the difference between a heuristic someone will extend by feel and a boundary someone has to re-measure to move.

What I could not check from here: the timings themselves (they need the box with the models, and this lane does not run kernels for review), and whether the reused kernel's output identity holds for every type in the set — the body establishes it for the IQ1_S row at UBATCH=8, and the allowlist extends the claim to eight more types. If the correctness arm covers only the 1-bit row, adding the neighbouring types is the one place I would want a second measurement before merge; if it covers the whole set, say so in the body and this is done.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 451c200 — READY, and it answers the exact objection that got #440 reverted.

The guard is the measurement, not a taxonomy

static bool kquant_reuse_format(ggml_type type) {   // IQ1_S/M, IQ2_XXS/XS/S, IQ3_XXS/S, Q2_K, Q8_0

Four guards, all on the same model/build/batch and all in the body's table, and the one that lands is the only one that wins on IQ1_S (45.4 → 20.0 ms/token) and is inert on the Q4_K_XL model (13.8 → 13.8). The two that lost Q4_K_XL by 40-53 % are exactly the ones that kept IQ4_XS / IQ4_NL / q5_K in the claim set, and those are the formats the code comment names as having packed prefill tails (engine#2137). So the scope is derived from a claim log and from four end-to-end arms, and the comment says the right thing about the future: "Widening this list is a measurement, not an edit."

I checked the base too: db6c8a9b3 (#442, the revert) is in this branch's history, so re-landing 40 minutes after the revert does not walk back the revert — it supersedes it with the scoped version, which is the correct order.

The range(%value, 1, 8) paragraph is the most valuable thing in the body

range(%value, 1, 8) → 1, 64 compiles 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 measured skipped tokens, not reuse.

That is a trap that looks like a 5× win in a table and corrupts output; keeping it written down is worth more than the row itself.

One thing a reader will ask, worth one clause

The win is attributed to the 2 400 q8_0 claims the family-only guard dropped — but Q8_0 is in the allowed list, and the Q4_K_XL model's own band is "q5_K, q8_0, iq4_xs, q4_K, q6_K, iq4_nl". So the Q4_K_XL model also has q8_0 claims that this row will now take, and its number is unchanged (13.8 → 13.8). That is not a contradiction — the same format can be a win in one band and noise in another — but as written the paragraph reads as if the q8_0 claim count alone explains the 2.3×, and the natural follow-up question ("how many q8_0 claims does Q4_K_XL have, and why is taking them free there?") is not answered. One sentence with the per-model claim counts would close it; I would not hold the PR for it, because the measurement already distinguishes the two cases empirically.

-ub 8 caveat is stated, the withdrawn 246 tok/s is labelled as withdrawn, and "not touched" names the three things a reviewer would otherwise go looking for.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT at 451c200: READY

The second attempt at the row reverted in #442, and the difference is exactly what the revert said was missing: a guard derived from a claim log rather than from a taxonomy. I checked the guard against the body's own claim log, and it holds.

The measurement, which is the whole argument

| model                     | row absent              | row present             |
| Qwen3.8-27B UD-IQ1_S      | 45.4 ms/token (22.00 t/s) | 20.0 ms/token (50.01 t/s) |
| Qwen3.8-27B UD-Q4_K_XL    | 13.8 ms/token (72.53 t/s) | 13.8 ms/token (72.22 t/s) |

4.5× against the shipped default (90.1 → 20.0 ms/token at UBATCH=64) with identical output, and the model #440 regressed is untouched. One prompt, one binary, arms separated only by the row, 0 kernel faults — and the 13.8 → 13.8 row is the one that matters, because it is the revert's measurement reproduced as a pass.

The guard, checked against the claim log in the description

IQ1_S model claims   iq1_s, iq2_xxs, q8_0
Q4_K_XL  claims      12 062 of ~23 000 are q5_K, rest q8_0 / iq4_xs / q4_K / q6_K / iq4_nl

keep set: IQ1_S IQ1_M IQ2_XXS IQ2_XS IQ2_S IQ3_XXS IQ3_S Q2_K Q8_0

Every format the IQ1_S model claims is kept (iq1_s ✓, iq2_xxs ✓, q8_0 ✓), and every format the Q4_K model leans on is excluded (q5_K, iq4_xs, q4_K, q6_K, iq4_nl) — except q8_0, which both models claim.

So the safety here is empirical, not taxonomic, and the description says so in its own words: "the guard is derived from a claim log rather than from a guess." The 13.8 → 13.8 line is the evidence that keeping Q8_0 is safe for that model.

The one thing worth stating before merge

Q8_0 is in the keep set, and the model that regressed also claims q8_0. The measurement covers two models; a third whose matmul weight is q8_0 would now be claimed by this row, and nothing in the PR says what that costs. Two honest options:

  1. Say why Q8_0 is kept — the IQ1_S claim log shows q8_0 in=5120 out=48 (2 400) nodes, i.e. a small-output matmul; if those are the reason, one clause makes the asymmetry deliberate rather than incidental. (Recall #442's table: "1-bit family only" gave nothing on IQ1_S, and the win needs Q8_0 in the set — so the set is empirically minimal, which is a good reason to state.)
  2. Or drop Q8_0 and measure the loss: if the 4.5× survives without it, the guard gets strictly safer for one extra measurement.

Neither blocks a READY: the row is scoped, the regression is measured as fixed, and #442 already reverted the unsafe version. But #440's failure was a guard whose scope nobody had derived — and Q8_0 is the one entry in this set that came from the other model's log.

Verified structurally

probe.weight->type is the guard's input, and weight is the matcher's own field (dispatch-mul-mat-id-common.h:21), so the check reads the weight the kernel will actually load rather than a re-derived shape. token_count >= 2 keeps single-token decode on its own row; token_count <= 8 is the kernel's width; and the row sits at 301, above hip.dense_prefill.mm at 299, which the description justifies with a no-server measurement. One file, +32/−4.

The caveat the PR states and I would keep in the description

"The win needs a small batch: llama-server chunks by ubatch, so it requires -ub 8 (or LLAMA_ARG_UBATCH=8); a default 512-token chunk is a…"

That is the same scoping #442's revert relied on — and it is the honest half: the default 512 never reaches the row, so the 4.5× is available to a configuration a user must choose. Saying it prevents the win from being read as default-path.

@bong-water-water-bong
bong-water-water-bong merged commit 3b7cbfb into 1bit/hrx-vulkan-patched Nov 20, 2026
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/kquant-reuse-1bit-family branch November 20, 2026 10:45

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT at 451c200: READY, with the guard's evidence gap named as the one thing to close before the format list is trusted.

The structure is right and the arithmetic of the quoted pairs checks (−55.0 %, −55.9 %, +53.2 %, +39.9 %), and it fixes both defects that got #440 reverted: a format guard now scopes the row, and the priority is above the two rows that would otherwise win by registration order:

// ABOVE hip.dense_prefill.mm (299) and above common.mul_mat.q6_k_aligned_skinny (300), which would otherwise win by
// registration order at equal priority.
registry.add({ "kquant.mul_mat.few_token_prefill_f32", GGML_OP_MUL_MAT, DispatchMatchKind::Fused, 301, … });

The measured claim that matters most is the inert case: "With this guard the Q4_K_XL model measures 13.8 → 13.8, i.e. inert rather than merely acceptable." That is exactly the property #442 asked for — not "the loss is now small" but "the row does not fire" — and it is the right bar for a guard.

The gap: nine formats in the list, two models in the evidence

case GGML_TYPE_IQ1_S: case GGML_TYPE_IQ1_M: case GGML_TYPE_IQ2_XXS: case GGML_TYPE_IQ2_XS:
case GGML_TYPE_IQ2_S: case GGML_TYPE_IQ3_XXS: case GGML_TYPE_IQ3_S: case GGML_TYPE_Q2_K: case GGML_TYPE_Q8_0:

The evidence quoted is IQ1_S gains and Q4_K_XL inert — the loss side of the family (Q4_K/Q5_K/Q6_K, IQ4_NL/IQ4_XS) is correctly excluded, and "widening this list is a measurement, not an edit" is the right policy sentence. But seven of the nine members have no measurement quoted here, so the list is "the set measured to gain" as an assertion about a set rather than a record of each member. That is the same shape as #440's defect one size smaller: a row applying to formats whose behaviour was inferred rather than measured, where the inference could be right for the family and wrong for the member.

Two cheap ways to close it, either is fine:

  • quote, per added format, the claim-log line or the bench pair that put it in the list (Q8_0 already has the strongest form of this — "the claim log shows the band's q8_0 hits are the small 48-wide projection (in=5120 out=48) … while the losing model is 52 % q5_K claims" — and that is the model the other seven should follow);
  • or narrow the list to IQ1_S, Q8_0 and whichever the log shows, and let the rest arrive as their own measurements.

A second, smaller note on Q8_0: the evidence given for it is shape-specific (the 48-wide projection) while the guard is format-wide, so a q8_0 claim at a wide shape is admitted on evidence taken at a narrow one. The comment is honest about the basis; either add out == 48 to the predicate or say in one clause that the guard is deliberately over-inclusive for Q8_0 because the band's only q8_0 claims are that shape.

Neither point is a reason to revert this: unlike #440 it ships the scoping mechanism, and the two measured arms are the ones that decided the revert. It is a reason to make the list's evidence match its length before the next widening argues from it.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT: READY -- this is the second attempt my #442 review asked for, and the derivation is the reason it works; one number in the headline compares two different baselines

The regression is gone and the win survives, measured the way the first attempt should have been:

model row absent row present
UD-IQ1_S 45.4 ms/token (22.00 tok/s) 20.0 (50.01)
UD-Q4_K_XL 13.8 (72.53) 13.8 (72.22) -- untouched

And the guard is derived, not guessed -- which is the whole difference from #440. Instrumenting the matcher to print the weight type and shape of every claimed node is exactly what my #442 review said the next attempt needed ("the win lives on non-IQ1_S nodes … per-node attribution, not matcher width"), and the claim log explains the thing that made two of #442's four guards inert: the IQ1_S model's band carries about 2 400 q8_0 claims, so a 1-bit-family-only guard dropped the very claims that produce the win. kquant_reuse_format() is then the set measured to gain — 1-bit codebooks plus Q8_0 — and the comment says "on a measured basis, not a taxonomic one", which is the right sentence to have in the code.

One number in the headline mixes two baselines, and it should be split. The first line reads "IQ1_S prefill 90.1 → 20.0 ms/token (4.5x)". 20.0 is measured at LLAMA_ARG_UBATCH=8 with the row; 90.1 is the shipped default at UBATCH=64. Both facts are true and neither is a row-only effect:

  • row at a fixed ubatch: 45.4 → 20.0 = 2.3x, which is what "this row" buys;
  • this row + UBATCH=8 against the shipped default: 90.1 → 20.0 = 4.5x, which is what a user gets if they set the batch too.

The 4.5x is worth claiming — it is the number that makes the model usable — but a reader who takes it as the row's value will expect 4.5x from the row alone, and #440's own history is a good argument for not mingling them: the same table shape let a 55 % "win" and a 53 % regression sit in one grid.

One suggestion, not an ask: the instrumentation is "local, not shipped", so the derivation is reproducible only from this PR's prose. Pasting the two claim dumps into the PR body (or keeping GGML_HRX_KQUANT_ATTRIB behind its env var) makes the next person's first step "read the claim log" instead of "instrument it again" -- and the claim log is what distinguishes this guard from the four that failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant