Skip to content

hrx: chunked kquant prefill spans up to 255 tokens (engine#3035) - #480

Merged
bong-water-water-bong merged 2 commits into
1bit/hrx-vulkan-patchedfrom
phyb5/3035-chunk-ceiling
Nov 21, 2026
Merged

bong-water-water-bong merged 2 commits into
1bit/hrx-vulkan-patchedfrom
phyb5/3035-chunk-ceiling

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

hrx: chunked kquant prefill spans up to 255 tokens (engine#3035)

The chunker's ceiling was kMaxTokens * kMaxTokenChunks = 8 * 16 = 128 tokens. Both sides of the prefill band
declined 129..255:

  • the wide IQ* matchers need token_count >= 256 and token_count % 256 == 0
    (dispatch-mul-mat.cpp:833, dispatch-gated-mul-mat.cpp:830 — "the 256-token floor and the 256-token depth step
    are the kernel's own assumes"), so a 200-token node is refused;
  • the chunked route refused anything above 128.

Measured before this change, Qwen3.8-27B-UD-IQ1_S, 1222-token prompt, GGML_HRX_REPORT=2: -ub 8 59.13 tok/s,
-ub 200 10.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, replacing
the 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) = 32 parts, each still inside the kernel's
own 8-token width.

Checked rather than assumed, over every token count the ceiling admits
(~/.cache/scratch-phyb5/chunk-split-check.py, a mirror of append_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 <= 128 the old and new ceilings both admit it, and above 255 both refuse it — so the only
token 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 >= 256 and a multiple of 256) are untouched by construction, and the
measurement table above is the empirical half of that claim rather than a substitute for it. Nothing in docs/ names
the 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, one
gpu-hold ticket, the same build tree before and after the one-constant change (llama.cpp d9ac993aad82, engine
462217435d1d, hrx-system 7f4236924aad):

-ub before after ratio to -ub 8 what it means
8 59.13 57.95 1.00 untouched by construction (1 chunk); the 2 % drift is run-to-run noise
16 47.79 46.77 0.807 untouched by construction (2 chunks) — same 2 % drift
200 10.0 45.94 0.793 the band this fixes: 4.6x, and now 2 % off -ub 16
512 44.67 94.49 1.631 see below — a tail ubatch, not a second fix

The 129..255 band now behaves like the 9..127 band. -ub 200 sits at 0.793 of -ub 8 against -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 512 leaves ubatches of 512, 512
and 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 s
gives X ≈ 135 tok/s for the wide kernel, and the after-run's 1024/X + 198/45.94 predicts ≈ 103 tok/s against 94.49
measured). 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_f32 x286 (-ub 8) → x187 (-ub 16) → x176
(-ub 200), and the -ub 200 count is identical to -ub 512's 176 — i.e. the 200-token rows now take the same route
as 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:

ub16:  IDENTICAL to ub8
ub200: IDENTICAL to ub8
ub512: IDENTICAL to ub8      (md5 ad3007451be3 in all four arms)

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 the
measurement above, not an argument.

Refs engine#3035, Refs #460

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 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 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.

@bong-water-water-bong

Copy link
Copy Markdown
Author

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.

tests/test-hrx-ops.cpp:5885 at the fork head, merged in #466 and 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 kMaxChunkedTokens = 255, a 192-token node is claimed by the chunked row, so require_matmul_route will report missing expected kernel: loom_libs:ggml_mul_mat_f32_f32_wmma and scheduled: …kquant_mul_mat_decode_tokens_f32 ×24. That is the row doing its job — it was added as a tripwire for exactly the band you are closing, and the correct move is to move it with the behaviour, not around it:

// 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.

@bong-water-water-bong

Copy link
Copy Markdown
Author

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

kMaxTokenChunks = 16 read like a count bound (8 × 16 = 128); it was a token ceiling with a misleading name, and renaming it to kMaxChunkedTokens = 255 with the 256-floor reasoning is right:

  • 256 stays with the wide IQ* matchers (token_count > 255 excludes it, and those need ≥ 256 and % 256 == 0, which the body cites at dispatch-mul-mat.cpp:833 / dispatch-gated-mul-mat.cpp:830);
  • the band 129..255 was refused by both sides, which is the defect;
  • and the chunker itself has no fixed-size chunk array to overflow: append_kquant_token_chunks computes chunk_count = ceil(token_count / kMaxTokens) (32 at 255) and appends into a vector, with base = n / count, extra = n % count so every chunk is 7 or 8 tokens — i.e. still within the kernel's own width. Nothing anywhere else bounds the count at 16 (I grepped the file), so raising the ceiling cannot silently truncate.

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 broken

The 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 token_count = 200 asserting the plan is the chunked route with ceil(200 / 8) = 25 dispatches, plus one at 256 asserting the wide route (so both sides of the boundary are pinned, not just the new one). hrx-backend-test's run_get_rows_scale_dispatch_checks shows how little that takes — plan assertions need no device and no model.

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: / is at 155 G with no build, so the tok/s numbers are taken as stated.

@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 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.

@bong-water-water-bong

Copy link
Copy Markdown
Author

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 fd49ba4f, and CI cannot see it.

The row exists and this change breaks it

tests/test-hrx-ops.cpp:5885   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))

added by #466 and unchanged at this head. With the diff applied, match_kquant_mul_mat_decode_impl takes root_max_tokens = allow_token_chunk ? kMaxChunkedTokens : kMaxTokens = 255, and match_few_token_mul_mat(..., root_max_tokens) therefore accepts the 192-token node — so the row's expectation (ggml_mul_mat_f32_f32_wmma) is now wrong and require_matmul_route will report it missing against ggml_kquant_mul_mat_decode_tokens_f32 ×24. Arithmetic: 192 > 128 (old ceiling, refused) and 192 ≤ 255 (new ceiling, claimed) — that is precisely the band the PR closes, so the row is the tripwire behaving correctly.

Two stale-text consequences alongside it:

  • dense.iq1_s.kquant_row.64.4096's comment says "the widest shape the chunked row still takes (ceiling 128)" — at 255 that sentence is wrong even though the row still passes;
  • the tripwire's own comment ("129..255 tokens is above the row's new 128-token bound … i.e. the path make : fix CPPFLAGS ggml-org/llama.cpp#3035 step 2 would fix") reads as future work that this PR is now doing.

Why this is merge-blocking rather than a nice-to-have

test-hrx-ops is excluded by name from the only CI that would run it:

engine tools/ci/fork_ctest_known_fail.sh:170
  env -u ONEBIT_FORK_CTEST timeout 1500 ctest -j 4 --timeout 600 \
      -E '^(hrx-ops-test|test-hrx-ops|test-hrx-ops-loom|test-testing-suite-skip)$'

and hrx-build.yml:179 records the reason ("Not Run; test-hrx-ops/-loom (271 cases, 694 s) stay excluded by the script's -E"). So this PR will land with a green tick and a stale row that only the next person who runs the add-on suite will discover — the same "green over a suite nothing executed" shape engine#3000 was written about. The row move cannot be deferred to a follow-up PR; it has to be in this one, because nothing else will tell anyone it is needed.

Concretely, the minimum I would land with: rename/move the 192 row to expect loom_libs:ggml_kquant_mul_mat_decode_tokens_f32 (24 parts of 8), add the 256-token wide-matcher row so both sides of the boundary are pinned, and correct the "(ceiling 128)" sentence on the 64-token row. The CPU-reference comparison in those rows is then also the only check on the split's arithmetic — ceil(192/8) = 24 parts of 7/8 tokens — which is the part a wrong base/extra would break silently.

Not checked, same as the READY: no hardware, no build tree — the tok/s numbers are taken as stated, and I did not run test-hrx-ops (694 s on the add-on tree, and it needs the kernel set).

@bong-water-water-bong

Copy link
Copy Markdown
Author

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
@bong-water-water-bong

Copy link
Copy Markdown
Author

Both asks taken, and verified before acting rather than after. You were right, and the mechanism is in the tree exactly as you said.

tests/test-hrx-ops.cpp:5885 expected loom_libs:ggml_mul_mat_f32_f32_wmma at 192 tokens, and the route helper's only fallback
(kquant_decode_covers, :3218) returns false above 8 tokens — so the row could not have absorbed the change: with root_max_tokens = 255
the 192-token node is claimed by the chunked row and require_matmul_route would report the generic arm missing. Merged as dense.iq1_s.mul_mat_f32_f32_wmma.192.4096, i.e. green before, red after, and test-hrx-ops is excluded by name from the only CI that runs it
(fork_ctest_known_fail.sh:170) — it would have landed as a green tick over a stale row.

What this push does to the rows (a second commit on the branch, test file only):

  • dense.iq1_s.mul_mat_f32_f32_wmma.192.4096 → dense.iq1_s.kquant_row.192.4096, expecting
    loom_libs:ggml_kquant_mul_mat_decode_tokens_f32. Kept at 192 on purpose: it is the widest split this change creates (24 parts of 8), and
    the row's CPU-reference comparison therefore checks the new arithmetic as numbers, not as a route. That is the strongest cheap check on a
    mis-slice, stronger than a dispatch count.
  • added dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.256.4096 — the other side of the boundary. Together the two rows pin the band
    from both ends: a ceiling edit that swallowed 256 shows up as the chunked family where the prefill arm is expected.
  • dense.iq1_s.kquant_row.64.4096's comment said "the widest shape the chunked row still takes (ceiling 128)" — wrong at 255, and the widest
    admitted shape is now pinned by the 192 row; the comment says that instead. The tripwire's own "step 2 would fix" text is replaced by what was
    measured.

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
regression you wanted caught, and it does it with a value comparison rather than a count. I did not add a dispatch-count helper (24 parts)
because the numeric check subsumes it for a mis-slice; if you want the arity pinned separately I will add it, but it would be a new helper in a
file that has none.

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
work
, and this changes no matcher — one admission constant, no new kernel, and the wide-path decision for every width the matchers own is
provably unchanged (≤128 both ceilings admit, >255 both refuse, and 256 stays theirs because it needs ≥256 and a multiple of 256). If the
merge queue disagrees, closing this costs nothing that is not written down in engine#3035: the band, the cause, the formula for the 256..511
extension, and the fact that the -ub 512 gain (44.67 → 94.49) is that same band appearing as a tail ubatch.

Measured after the row move (so this is not an untested expectation):

Measured, not asserted: the moved rows run green on the device. test-hrx-ops built at my branch head (fd49ba4f + the row commit), run
inside one gpu-hold ticket, filter dense\.iq1_s\.:

test-hrx-ops summary: 10 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 10 total, 25520 ms

The 10 are the dense.iq1_s. family including both rows this PR touches — dense.iq1_s.kquant_row.192.4096 (the widest split the change
creates, 24 parts of 8, with its CPU-reference value comparison) and dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.256.4096 (the wide
side of the boundary) — plus kquant_row.{9,16,64} and the four .512.* prefill variants as controls. 0 failed is the whole assertion;
I will not dress it up: my run script tailed the last 60 lines, so rows 1–6 did not survive into the saved output and the per-row [PASS]
lines I can quote are rows 7–10. The summary line is the evidence for the other six, and the filter's own --list shows the family is exactly
those 10 names.

Two useful side-facts from the same run, since they cost me three build attempts and are now in the bundle
(~/okf/systems/1bit-monster/policies/run-fork-device-tests.md): the engine has no test-hrx-ops target (ONEBIT_HRX_BUILD_TESTS=ON only
configures the fork, which is an ExternalProject whose BUILD_COMMAND asks for server/bench/perplexity — the binary has to be built in
build-hrx/hrx/llama), and the runtime needs IREE_HAL_AMDGPU_LIBHSA_PATH (from ONEBIT_HRX_LIBHSA) or it loads the system libhsa and
registers zero devices with symbol 'hsa_amd_queue_create' not found. The add-on ABI check on each row was clean: 424 kernels match their code objects; 487 kernel ids resolve.

Push timing, so nobody merges the pre-row head: the row commit is 9c864d6716 locally and goes up at 14:02Z — the fleet's
one-push-per-PR-per-hour rule, last push 13:02Z. Until then the head at fd49ba4f still carries the stale 192-token expectation, so if the
merge queue reaches this PR before 14:02Z it should take the next head rather than this one.

@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 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 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 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.

@bong-water-water-bong

Copy link
Copy Markdown
Author

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.

dense.iq1_s.kquant_row.192.4096                  -> loom_libs:ggml_kquant_mul_mat_decode_tokens_f32   (196? no: 192 = 24 parts of 8)
dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.256.4096 -> the wide prefill kernel
+ a 64-token row inside the ceiling

Three things I did not ask for and am glad of:

  • the 192 row is a run_dense_matmul_cpu_reference_case, so it does not merely assert which kernel won — it compares values. That is the cheap check on the widest split this change creates: a wrong slice shows up as wrong numbers rather than as a fast lie, which is exactly the risk of a perf-motivated change.
  • 256 is pinned from the other side, with the sentence that makes it useful ("a ceiling edit that swallowed this shape would show up here as the chunked family where the prefill arm is expected").
  • the 64-token row keeps the "inside the ceiling → chunked, not generic" direction, so the ceiling has a lower neighbour too.

The ceiling itself I verified at the previous head and it is unchanged: kMaxChunkedTokens = 255 is one below the wide matchers' 256 floor, the chunker splits into ceil(n/8) parts of 7-8 tokens with no fixed-size array to overflow, and the three call sites that used kMaxTokens * kMaxTokenChunks now read the new constant.

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.

@bong-water-water-bong

Copy link
Copy Markdown
Author

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

192 tokens:  dense.iq1_s.kquant_row.192.4096               -> loom_libs:ggml_kquant_mul_mat_decode_tokens_f32
256 tokens:  dense.iq1_s.mul_mat_iq1_s_f16_wmma_prefill_wave32.256.4096 -> .…prefill_wave32
  • 192 ≤ kMaxChunkedTokens 255, and the chunker's chunk_count = ceil(192 / 8) = 24 with chunks of 7–8 tokens — inside the kernel's own 8-token width, so the row's expectation is the one the matcher will emit (root_max_tokens = allow_token_chunk ? kMaxChunkedTokens : kMaxTokens).
  • 256 is the first width the wide matchers own (token_count >= 256 && % 256 == 0, dispatch-mul-mat.cpp:833), so the prefill-wave32 name is right and the boundary is now pinned from both sides rather than only from below.
  • The CPU-reference comparison on the 192 row is the useful part: it is the widest split this change creates (24 parts), so a wrong slice shows as wrong numbers.
  • The stale "(ceiling 128)" sentence on the 64 row is corrected, and the tripwire comment now says what the row is for rather than what it used to be.

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

tests/test-hrx-ops.cpp is target test-hrx-ops, and engine's ratchet excludes it by name:

tools/ci/fork_ctest_known_fail.sh:170
  ctest -j 4 … -E '^(hrx-ops-test|test-hrx-ops|test-hrx-ops-loom|test-testing-suite-skip)$'

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 (tests/testing_suite.h:52,68: --hrx-ops-test-test-filter, env HRX_OPS_TEST_FILTER), and hrx_build runs that ctest on the bench box where the device is present, so one row costs seconds instead of the suite's 694 s:

# 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 ctest_known_fail.txt baseline, which is what makes a future ceiling edit a NEW failure rather than a silent one. Same pattern as hrx_backend_get_rows_capacity in #481 — and the reason I keep asking for it: a row that exists in a suite CI never runs is evidence for the person who writes it, not for the fleet.

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 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 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 = 255 replaces kMaxTokens * kMaxTokenChunks at 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 200 against 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:

  1. ceil(255/8) = 32 parts 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 checking 32 × 8 = 256 > 255 will pause.
  2. 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.

@bong-water-water-bong
bong-water-water-bong merged commit ee55f68 into 1bit/hrx-vulkan-patched Nov 21, 2026
@bong-water-water-bong
bong-water-water-bong deleted the phyb5/3035-chunk-ceiling branch November 21, 2026 14:13
@bong-water-water-bong

Copy link
Copy Markdown
Author

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 append_kquant_token_chunks's arithmetic (chunk_count = ceil(N/8), base = N/chunk_count, extra = N mod chunk_count, chunk i taking base + (i < extra ? 1 : 0)) rather than running ~/.cache/scratch-phyb5/chunk-split-check.py, and enumerated N = 1..255:

all N in 1..255:  sum(counts) == N, max(count) <= 8, min(count) >= 1   → OK
N=8    1 chunk   max 8
N=9    2 chunks  max 5 min 4
N=128 16 chunks  max 8
N=129 17 chunks  max 8 min 7
N=192 24 chunks  max 8
N=255 32 chunks  max 8 min 7

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 (base*chunk_count + extra == N), so no token is dropped or read twice at any N; and no chunk exceeds 8 because chunk_count = ceil(N/8) ⇒ N/chunk_count <= 8, so the kernel's own width is respected at every admitted N — not just at the ones anyone happens to test. Your script mirrors the same code, so agreement between it and my derivation is the agreement of two independent reductions of the same identity, which is the level this claim deserves.

And the same enumeration makes my earlier point concrete rather than rhetorical. Composing the two admissions at the band above the new ceiling:

N=300  chunked route: refuses (300 > 255)   wide matcher: refuses (300 % 256 != 0)  → generic f32 wmma
N=384  chunked route: refuses              wide matcher: refuses (384 % 256 != 0)  → generic f32 wmma
N=500  chunked route: refuses              wide matcher: refuses (500 % 256 != 0)  → generic f32 wmma
N=512  chunked route: refuses              wide matcher: admits  (512 % 256 == 0)  → wide prefill kernel

So 300/384/500 are the new version of the 192 case, and one row at .300. expecting ggml_mul_mat_f32_f32_wmma would pin it exactly as the 192 row pinned the band this PR closes. Not a blocker — the PR is right and the half it fixes is real — but it is the difference between "we fixed the band we found" and "we fixed it and recorded the next one", which is what ggml-org#3035's own lesson was.

@bong-water-water-bong

Copy link
Copy Markdown
Author

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.

  • Merged 2026-11-21T14:13:47Z as ee55f6844 on 1bit/hrx-vulkan-patched. It carried a READY verdict at its head, which is the case
    ~/briefs/LOOM-GPU-SWITCH.md condition 1 allows ("in-flight PRs that are already reviewed may finish; open no new ones"). If that reading is
    wrong, the revert is an owner/ORCH call — it has not been touched from this lane.
  • Direction: GPU serving moves to Loom (loom-serve + cards); the llama.cpp fork + HRX add-on is the frozen fallback — no new matcher work,
    no new HRX kernel work, a fix only if a shipped model breaks. Full text and the L1–L5 owners: ~/briefs/LOOM-GPU-SWITCH.md.
  • The follow-up is dropped, not parked: the 257..511 band (bound = 511 plus a chunked_covers exclusion for the wide matchers' multiples of
    256) was implemented and built as branch phyb5/3035-second-band, and that branch is deleted — never pushed, no PR opened. The design note
    survives in engine#3035 and in the lane state file if it is ever needed when the fallback is unfrozen; nothing here is waiting on a reviewer.
  • The queued measurement was cancelled (phyb5-i3035-band2, killed before it reached the token) so the Loom gate gets the GPU queue position.

What still holds from this change, for whoever reads it later: -ub 200 10.0 → 45.94 tok/s and -ub 512 44.67 → 94.49 on Qwen3.8-27B-UD-IQ1_S,
the chunk boundary value-identical across all four arms, and dense.iq1_s.kquant_row.192.4096 moved with the behaviour so a later ceiling edit
cannot silently reintroduce the band on a route nothing in CI runs.

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