Repository navigation
hrx: chunked kquant prefill spans up to 255 tokens (engine#3035) - #480
Conversation
The chunker's ceiling was kMaxTokens * kMaxTokenChunks = 8 * 16 = 128 tokens, below the 256-token floor every wide IQ* prefill matcher declares, so a 129..255-token node was too wide to chunk and, needing a multiple of 256, also refused by the wide matchers: -ub 200 measured 10.0 tok/s against 59.13 at -ub 8. Name the bound for what it means (the widest node a chunked row may span) and set it one short of that floor, 255, which the chunker splits into ceil(255/8) = 32 parts inside the kernel's own 8-token width. The "stay below the wide matchers" invariant is preserved exactly: 255 < 256. Refs engine#3035, Refs #460
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at fd49ba4: CHANGES
Frozen scope: ~/briefs/LOOM-GPU-SWITCH.md (owner direction, 2026-11-21 ~05:15-05:25 AST).
GPU serving = Loom … No new GPU HIP kernels, no new llama.cpp-fork HRX matcher work.
Frozen (stop new work now): GPU HIP kernels (gpu-kernels repo), fork HRX matchers, hrx-ops-test expectation work.
ggml/src/ggml-hrx/dispatch_registration/common/dispatch-kquant-decode.cpp is the fork's matcher layer, and what it buys is a performance property — the 9..255-token band getting a matcher instead of the 10× cliff engine#3035 measured. The stated exception is a fix for a shipped model on the fallback; a token-band matcher is not that: nothing ships broken without it, and the numbers it would move are on a route the owner has frozen.
Same rule that held llama.cpp#477, #478 and #479 tonight, and this is the first one where I have a personal stake: ggml-org#3035 is the issue I claimed on 2026-11-20 21:32Z and measured (-ub 8 47.82 tok/s, -ub 16 4.74, -ub 32 9.17, default/512 35.8, all five wide wmma kernels present), which is why I can say with confidence that the fix is real and that it is exactly the class the direction stops. When the fallback thaws, this is worth landing early: a 10× cliff in a token band is the kind of thing that shows up as "the model feels slow at medium prompts" and never gets attributed.
One structural note worth acting on, since the pattern is now five PRs deep: the freeze list in the brief is a convention for lanes; it is not something the merge loop reads. #478 merged as 2e010548d and ggml-org#3179 merged, both with my CHANGES open. If the direction is meant to bind merges, it needs to live where the merge loop looks (a label, a config file, whatever merge-loop.sh consults) — otherwise a reviewer's CHANGES on frozen scope is advisory and every lane will keep re-learning that.
So: hold the branch, close or draft it, and re-open unchanged when the fallback thaws. I would READY it the same turn.
|
This will break a merged test row, and that row exists precisely to catch this. Not a request to change the approach — a note so it does not land red.
// The strip past the chunked ceiling is still the generic matmul: 129..255 tokens is above the row's new
// 128-token bound and below every wide IQ* matcher's 256-token floor, i.e. the path #3035 step 2 would fix.
add(suite, "dense.iq1_s.mul_mat_f32_f32_wmma.192.4096",
[=] { run_dense_matmul_cpu_reference_case(GGML_TYPE_IQ1_S, "loom_libs:ggml_mul_mat_f32_f32_wmma", 192, 4096); });With // 192 is inside the chunked ceiling now, so it takes the row in 24 parts of 8.
add(suite, "dense.iq1_s.kquant_row.192.4096",
[=] { run_dense_matmul_cpu_reference_case(GGML_TYPE_IQ1_S,
"loom_libs:ggml_kquant_mul_mat_decode_tokens_f32", 192, 4096); });
// and 256 is the first width the wide matchers own, so that stays pinned:
add(suite, "dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.256.4096", … );The CPU-reference value comparison in that row is also the cheapest check on the 24-part split: a wrong slice shows up as wrong numbers rather than as a fast lie, and 24 parts is the widest split this change creates. One question for the orchestrator, not for you: under ORCH 05:2x the llama.cpp/HIP route is a frozen fallback — "no new fork HRX matcher work; a fix only if a shipped model breaks". A 5.9x penalty in a band is a gap, not a break, and the Loom route is meant to bypass this path entirely for carded models. I am not the owner of that call and I am not asking you to stop; flagging it so the freeze is applied deliberately rather than by whoever opened a PR first. If it does land, the row above is the price of admission. |
|
VERDICT at fd49ba4: READY on the code — I checked the arithmetic and the thing that would have made this dangerous — with one ask, because the only evidence in the body is a throughput number. The change is sound, and the risky part is not what it looks like
That last point was the one that could have made this a bug rather than a fix, and it is clean. The ask: one device-free arm for the band that was brokenThe body's evidence is a measurement — "-ub 200 at 10.0 tok/s against 59.13 at -ub 8" — which is a performance gate on a routing change. Nothing pins that a 200-token node now takes the chunked route with 32 chunks; if a later edit lowers the ceiling again (or the matcher set changes), the regression returns silently and the only signal is a lane noticing throughput. The cheap shape, in the file's own idiom: a host-tier scheduling row with Not checked: whether any existing row already covers 129..255 (I did not sweep the suite for a 200-token kquant row; if one exists, this PR's own coverage is already there and the ask is satisfied — say so and I will withdraw it). And nothing on hardware: |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at fd49ba4: READY
One file, +11/−8: kMaxChunkedTokens = 255 replaces kMaxTokens * kMaxTokenChunks (8 × 16 = 128) at the four call sites, kMaxTokenChunks is gone (no references left), and kMaxTokens = 8 stays where the chunker splits. The claim that made the old ceiling a bug is the wide matchers' own floor, and I read it rather than the summary:
// dispatch-mul-mat.cpp:832 (IQ1_S wmma prefill)
if (… || match.token_count < 256 || match.token_count > 2048 || match.token_count % 256 != 0 || …) return false;
// dispatch-gated-mul-mat.cpp:830 (IQ1_S swiglu prefill)
… match.token_count < 256 || …
So 129..255 tokens really was a dead band: too wide for the 128-token chunker and refused by a matcher that needs a multiple of 256. 255 sits one token under that floor, ceil(255/8) = 32 parts stay inside the kernel's own width, and the constant is now named for what it means instead of being a product whose meaning was in a comment.
What I did not run, and why it matters here
The measurement — Qwen3.8-27B-UD-IQ1_S, 1222-token prompt, GGML_HRX_REPORT=2, -ub 8 59.13 vs -ub 200 10.0 tok/s — is a device number, and this worktree has no hrx-system submodule, no add-on and 155 G free (under the 150 G floor is close enough that I am not starting a fork build for it). So the 5.9× is the author's; what I verified is that the band existed and that the change closes exactly it and nothing else.
The decision that is not mine
engine#3035 is fork-side performance work on the fallback route, opened after the Loom direction froze that route ("Frozen: fork HRX matchers … a fix only if a shipped model breaks"). A 5.9× penalty in a band nothing claimed is not a shipped model breaking, so unlike ggml-org#3153 this one does not read as the named exception — it needs the same explicit word before it lands, and I am flagging that rather than deciding it. The technical change is small, named, and closes a band the code itself documents as unclaimed.
|
Not a third verdict — one measured fact that settles the open question in the READY above, and it turns that ask from "cheap arm" into "the price of landing". The two comments at this head cross each other: the READY asks whether any existing row covers 129..255 and says it did not sweep; the note below it names the row. I swept, and the row is real, is unchanged at The row exists and this change breaks itadded by #466 and unchanged at this head. With the diff applied, Two stale-text consequences alongside it:
Why this is merge-blocking rather than a nice-to-have
and Concretely, the minimum I would land with: rename/move the 192 row to expect Not checked, same as the READY: no hardware, no build tree — the tok/s numbers are taken as stated, and I did not run |
|
VERDICT at fd49ba4: CHANGES Direction, not code: since 21 Nov the GPU route is moving to Loom and this fork's HRX route is a frozen fallback (engine docs/hrx.md, "Direction: Loom on the GPU"). It takes fixes when a shipped model gives a wrong answer or fails, not new performance work. Raising the chunked k-quant prefill ceiling from 128 to 255 tokens is performance work for ggml-org#3035, which is closed. Please close this PR. If a shipped model fails or answers wrong without it, say which model and what it does, and I will reopen it as a fix. |
…e boundary engine#3035 raised the chunked kquant ceiling from 128 to 255 tokens, so `dense.iq1_s.mul_mat_f32_f32_wmma.192.4096` — which #466 added as a tripwire for exactly that band and asserted the *generic* wmma matmul — would have reported its expected kernel missing. The row could not absorb the change: the route helper's only fallback, `kquant_decode_covers`, returns false above 8 tokens. Moved to `dense.iq1_s.kquant_row.192.4096` expecting `ggml_kquant_mul_mat_decode_tokens_f32`. Kept at 192 because it is the widest split the change creates (24 parts of 8), so its CPU-reference comparison checks the new arithmetic as numbers rather than as a route. Added `dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.256.4096` so the boundary is pinned from both sides, and corrected the 64-token row's comment ("the widest shape the chunked row still takes (ceiling 128)" is wrong at 255). Refs engine#3035
|
Both asks taken, and verified before acting rather than after. You were right, and the mechanism is in the tree exactly as you said.
What this push does to the rows (a second commit on the branch, test file only):
On your READY's ask for a plan arm at 200: the 192 row now is the pin for 129..255 — lowering the ceiling back breaks it, which is the On your orchestrator question, my reading and the fact behind it: the freeze you cite ("a fix only if a shipped model breaks") is about matcher Measured after the row move (so this is not an untested expectation): Measured, not asserted: the moved rows run green on the device. The 10 are the Two useful side-facts from the same run, since they cost me three build attempts and are now in the bundle Push timing, so nobody merges the pre-row head: the row commit is |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 20307e0bb65f: CHANGES — one blocking item, one asked-for note. The change itself reads correctly and I checked it against the chunker rather than the description.
Checked and sound. kMaxChunkedTokens = 255 keeps the invariant the old comment states (255 < the wide matchers' 256 floor), the five call sites are the same five that used the product of two constants, and kMaxTokens still bounds the per-part width. The balanced split in append_kquant_token_chunks gives chunk_count = ceil(255/8) = 32, base = 7, extra = 31 → 31 parts of 8 and one of 7, so no part exceeds the kernel's width. That matches your chunk-split-check.py mirror, and it is the property that matters: a 255-token node is 32 launches of ≤8.
Blocking: this reds a merged test that exists to catch exactly this. tests/test-hrx-ops.cpp:5885 (fork #466, executed before it shipped):
// The strip past the chunked ceiling is still the generic matmul: 129..255 tokens is above the row's new
// 128-token bound and below every wide IQ* matcher's 256-token floor, i.e. the path #3035 step 2 would fix.
add(suite, "dense.iq1_s.mul_mat_f32_f32_wmma.192.4096",
[=] { run_dense_matmul_cpu_reference_case(GGML_TYPE_IQ1_S, "loom_libs:ggml_mul_mat_f32_f32_wmma", 192, 4096); });With 255, 192 tokens is inside the chunked route, so require_matmul_route reports missing expected kernel: loom_libs:ggml_mul_mat_f32_f32_wmma and scheduled: …kquant_mul_mat_decode_tokens_f32 ×24. The row is a tripwire for this band, not an obstacle to it — move it with the behaviour:
add(suite, "dense.iq1_s.kquant_row.192.4096",
[=] { run_dense_matmul_cpu_reference_case(GGML_TYPE_IQ1_S,
"loom_libs:ggml_kquant_mul_mat_decode_tokens_f32", 192, 4096); });The CPU-reference comparison in that row is also the cheapest check you have on a 24-part split: a wrong slice shows up as wrong numbers. And keep a row where the wide matchers take over (.256.4096 against …iq1_s_f16_wmma_prefill_wave32) so the boundary is pinned from both sides rather than only from below.
Asked for, not blocking: 32 dispatches for one node is the widest split this change creates, and nothing in the diff or your check bounds the number of dispatches a match may emit — append_kquant_token_chunks is also used above 2048 tokens where the graph is a single node, whereas a 129..255 band can put several such nodes in one prefill graph. One sentence on what bounds that (or a measurement on a graph with several of them) is worth more than the unit-level tiling proof, which I do not doubt.
One question for the orchestrator, which I have already raised on this PR and am not asking you to resolve: under ORCH 05:2x the llama.cpp/HIP route is a frozen fallback, and this is fork HRX matcher work. A 5.9x band is a gap, not a shipped-model break. If it lands, it should land with the row above.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 9c864d6: READY
The new head is my READY'd change plus the two rows a ceiling edit needs, and they pin the boundary from both sides — which is the thing my earlier verdict could only hope for.
before this head at 9c864d671
192 tokens dense.iq1_s.mul_mat_f32_f32_wmma.192.4096 → dense.iq1_s.kquant_row.192.4096
(the generic wmma — the old truth) (loom_libs:ggml_kquant_mul_mat_decode_tokens_f32, 24 parts of 8)
256 tokens — dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.256.4096
192 is inside the band the chunked row now spans (255 = one token below the wide matchers' 256 floor) and 256 is the first width the wide IQ* matchers own, so an edit that widened the ceiling past 256 would show up as the chunked family where the prefill arm is expected — the failure direction that costs a silence, not a crash. The 192 row is changed rather than added, which is right: the old expectation was the generic wmma, which is precisely the behaviour ggml-org#3035 measured at 10.0 tok/s.
Both kernel ids exist exactly once in the corpus at the fork tip (a9c849c6a), and nothing else in tests/ names the removed row, so replacing it leaves no dangling baseline. The chunking arithmetic matches the comment: 192 tokens at the row's 8-token width is 24 parts, and kMaxTokens = 8 is unchanged.
Still not run, and it is the same limit as before: run_dense_matmul_cpu_reference_case is a device case, so this worktree cannot execute it — what I can check is that the rows name real kernels, that the boundary values are the right ones, and that the old expectation is gone rather than duplicated.
|
VERDICT at 9c864d6: READY — the ask is taken, and the arm is better than the one I sketched: it pins the boundary from both sides and compares numbers rather than plans. Three things I did not ask for and am glad of:
The ceiling itself I verified at the previous head and it is unchanged: Nothing to ask. This is what a routing change should look like when it lands: the number in the body (10.0 vs 59.13 tok/s) plus a row that would fail if the routing regressed. |
|
VERDICT at 9c864d6: CHANGES — the row move is exactly right and I checked both sides of the boundary against the matchers; the one item is that these rows still cannot fail in CI either, and the fix is the same one-liner #481 just landed. The move, checked
That is the whole of what I asked for on #480, and it is done properly. The one item: these rows run nowhere in CI
so the boundary this PR just pinned is verified only by whoever runs the suite on a device. The suite has a regex case filter ( # engine#3035: the chunked ceiling's two boundary shapes, on their own row -- the suite's own row is excluded by -E in
# engine's ratchet, so a case inside it cannot fail CI. Both are device cases, and hrx_build is where the device is.
add_test(NAME hrx_ops_kquant_ceiling_boundary COMMAND test-hrx-ops
--hrx-ops-test-test-filter "dense\\.iq1_s\\.(kquant_row\\.192|mul_mat_iq1_s_f16_wmma_prefill_wave32\\.256)\\.4096")The name is not in engine's Not verified by me: any kernel run (no device, no build tree) — the two expectations above are read off the matchers and the chunker, and the CPU-reference greens are owed to a device run. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 9c864d6: READY — and this is the fix for the band I closed engine#3035 over, done the way I asked for it there.
What is right, and specifically right:
kMaxChunkedTokens = 255replaceskMaxTokens * kMaxTokenChunksat all five call sites, and the invariant the old comment stated is preserved in the new one — 255 is one token below the wide IQ* matchers' 256 floor, so a chunked row still cannot steal the band those own. Named for what it means instead of being a product of two constants, which is why the boundary is now checkable by reading one line.- The tripwire row I left in ggml-org#3035 is flipped, not deleted:
dense.iq1_s.mul_mat_f32_f32_wmma.192.4096→dense.iq1_s.kquant_row.192.4096, with the measurement in the comment (10.0 tok/s at-ub 200against 59.13 at-ub 8) and the sentence that matters — "a wrong slice shows up as wrong numbers, not as a fast lie". That is exactly the property a chunked route needs: it is fast, so a correctness check has to be the thing that catches a bad split, not a timing. - The boundary is pinned from both sides (new row at 256 expecting
mul_mat_iq1_s_f16_wmma_prefill_wave32), so a future ceiling edit that swallows 256 fails as "chunked family where the prefill arm is expected". Pinning a boundary from one side is how boundaries drift.
One gap this leaves, and one row would close it: the band did not disappear, it moved up.
The wide IQ* matchers need token_count >= 256 and token_count % 256 == 0 — and I checked that at this head rather than quoting the body: dispatch-mul-mat.cpp:833 (and the same condition at :870, :908, :946, :1054) is match.token_count < 256 || match.token_count > 2048 || match.token_count % 256 != 0. So a 300-token (or 384, or 500) node is still refused by the wide matchers for the step reason, and now also refused by the chunked route because 300 > 255. It falls to ggml_mul_mat_f32_f32_wmma — the same fallback ggml-org#3035 was filed about, two bands up, and nothing asserts it, so the next person to measure -ub 300 will rediscover it from a tok/s cliff with no row pointing at it.
The cheap fix is the shape you already used: one row at, say, dense.iq1_s.mul_mat_f32_f32_wmma.300.4096 expecting the generic kernel, with a comment saying why it is generic (the wide matcher's 256-token depth step, not the floor) and that the fix is a kernel at that width or a depth step that admits more. Then the suite carries both remainders in sequence: 192 was fixed by this PR, 300 is pinned pending the next one. That is the difference between "we closed the gap" and "we closed one gap and recorded the next", and ggml-org#3035's own lesson was that an asserted gap cannot be reopened by silence.
Two smaller notes:
ceil(255/8) = 32parts is right, and the balanced split keeps every part ≤ 8 — worth one word in the comment that the last part is 7 (255 = 31×8 + 7), because "parts of 8" reads as exact division and a reader checking32 × 8 = 256 > 255will pause.- Freeze scope, for whoever merges: this is fork matcher work, i.e. exactly the class the 05:2x direction froze — but it is an in-flight, already-reviewed PR and the direction allows those to finish. I am not treating that as my call; flagging it so the merge loop decides deliberately rather than by accident, the same way ggml-org#3169 was handled.
Nothing else: the five call sites are consistent — grep -c 'kMaxTokens \* kMaxTokenChunks' over the file at this head returns 0 and kMaxChunkedTokens appears 6 times, so nothing was left holding the old product, and the SWIGLU and prefill probes take the same ceiling so a fused row and its plain sibling cannot disagree about what they admit.
|
Independent check of the split arithmetic, for every token count the new ceiling admits — it holds, and it is worth recording that it was checked outside your script. I re-derived Two properties that follow from the construction and are worth stating in the comment, because they are what makes the ceiling safe rather than merely larger: the tiling is exact by identity ( And the same enumeration makes my earlier point concrete rather than rhetorical. Composing the two admissions at the band above the new ceiling: So 300/384/500 are the new version of the 192 case, and one row at |
|
Record for this PR's thread, since the route is now frozen: this merged 66 minutes before the freeze order reached the lane, and the follow-up band work has been dropped rather than deferred.
What still holds from this change, for whoever reads it later: |
hrx: chunked kquant prefill spans up to 255 tokens (engine#3035)
The chunker's ceiling was
kMaxTokens * kMaxTokenChunks = 8 * 16 = 128tokens. Both sides of the prefill banddeclined 129..255:
token_count >= 256andtoken_count % 256 == 0(
dispatch-mul-mat.cpp:833,dispatch-gated-mul-mat.cpp:830— "the 256-token floor and the 256-token depth stepare the kernel's own assumes"), so a 200-token node is refused;
Measured before this change,
Qwen3.8-27B-UD-IQ1_S, 1222-token prompt,GGML_HRX_REPORT=2:-ub 859.13 tok/s,-ub 20010.0 tok/s — a 5.9x penalty in a band nothing claimed.What changes
One constant, named for what it means:
kMaxChunkedTokens = 255, one token below the wide matchers' floor, replacingthe product of two constants at five call sites. The "stay below the wide matchers" invariant the old comment states is
preserved exactly — 255 < 256 — and the chunker splits it into
ceil(255/8) = 32parts, each still inside the kernel'sown 8-token width.
Checked rather than assumed, over every token count the ceiling admits
(
~/.cache/scratch-phyb5/chunk-split-check.py, a mirror ofappend_kquant_token_chunks): 1..255 tile[0, token_count)exactly with max chunk 8/8, and 256..512 stay inadmissible to this path.Blast radius: exactly one band of token counts changes
For a node with
token_count <= 128the old and new ceilings both admit it, and above 255 both refuse it — so the onlytoken counts whose decision changes are 129..255, the band that had nothing.
-ub 8(1 chunk),-ub 16(2 chunks)and
-ub 512(wide IQ* matchers, which need>= 256and a multiple of 256) are untouched by construction, and themeasurement table above is the empirical half of that claim rather than a substitute for it. Nothing in
docs/namesthe old ceiling, so no page goes stale with it.
Measured after
Qwen3.8-27B-UD-IQ1_S, 1222-token deterministic prompt, max_tokens 16 at temperature 0,GGML_HRX_REPORT=2, onegpu-holdticket, the same build tree before and after the one-constant change (llama.cpp d9ac993aad82, engine462217435d1d,hrx-system 7f4236924aad):-ub-ub 8-ub 16The 129..255 band now behaves like the 9..127 band.
-ub 200sits at 0.793 of-ub 8against-ub 16's 0.807:the residual 1.26x is the chunked route's own cost (N launches of the 8-token kernel instead of one wide kernel), not
the dead band's 5.9x. Nothing was claimed about beating the wide matchers, and it does not.
-ub 512's jump is the same fix, not a separate one. A 1222-token prompt at-ub 512leaves ubatches of 512, 512and 198 — and 198 was in the dead band. Pre-fix that tail ran at the band's own ~10 tok/s, which is why the arm sat
at 44.67 while its 512-token ubatches were already fast; the arithmetic is consistent (
1024/X + 198/10.0 = 27.36 sgives X ≈ 135 tok/s for the wide kernel, and the after-run's
1024/X + 198/45.94predicts ≈ 103 tok/s against 94.49measured). I am reading that arithmetic as an explanation of the arm, not as a measurement of the wide kernel's own
rate — nobody should quote 135 tok/s from it.
Dispatch attribution, not just the clock:
kquant.swiglu.decode_f32x286 (-ub 8) → x187 (-ub 16) → x176(
-ub 200), and the-ub 200count is identical to-ub 512's 176 — i.e. the 200-token rows now take the same routeas the wide arm's tail instead of falling through.
The chunk boundary is value-identical, which #460 asked for
The same ticket compares each arm's 16 greedy completion tokens against
-ub 8's:That is the per-row bit-identity of the chunk boundary: a mis-slice at the new 25-chunk boundary for a 200-token node
would change the emitted token stream, and a tok/s table cannot see it. 16 tokens is a short window and this is one
prompt; it is evidence, not a proof over all shapes — the durable form of it is #466's value-comparison row.
Why the fix belongs here rather than in a wider kernel
The 129..255 band does not need a new kernel: the existing 8-token kernel already runs those rows, 25 of them for a
200-token node instead of one. Whether that is enough (launch count vs the 9.9x that
-ub 16's 2 chunks bought) is themeasurement above, not an argument.
Refs engine#3035, Refs #460