Skip to content

hrx: get_rows pins a power-of-two token capacity class (rebased from #467, engine#3126) - #481

Merged
bong-water-water-bong merged 4 commits into
1bit/hrx-vulkan-patchedfrom
pi-issues/3126-rebase
Nov 21, 2026
Merged

bong-water-water-bong merged 4 commits into
1bit/hrx-vulkan-patchedfrom
pi-issues/3126-rebase

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

#467's two commits rebased onto 1bit/hrx-vulkan-patched (2e010548d), because the original has been DIRTY since 09:15Z on a comment-only conflict — the same fix, unchanged, and this is the same content the author reviewed, not a competing design.

The conflict, and how it was resolved

tests/hrx-backend-test.cpp:368-377, both sides carrying the identical call:

const ggml::hrx::MoeRoutingDescriptorLayout layout =
    ggml::hrx::moe_router_descriptor_layout(expert_count, /*consumer_reads_common_layout=*/false);

That line sat outside the conflict markers — git had already agreed on the code — and only the comment above it differed. Resolved by keeping both facts rather than picking one:

// engine#2861: the second argument is WHO READS the table, and this reference is the table the qwen
// routed kernels decode, so it is not the common layout: Qwen 127/7/13 at <= 128 experts, the common
// layout above that -- which is the same pick the router makes for these rows. (This call site kept the
// one-argument form after #2861 split the argument out, and the target has therefore not compiled since
// #438; engine#3129.)

What it carries

b1b5a1c51  hrx: get_rows pins a power-of-two token capacity class, not the exact token count        (engine#3126)
fa9489387  tests: a device-free arm for the get_rows capacity class, and the one stale call …       (engine#3126)
diff vs the branch tip: dispatch-get-rows.cpp, ubatch-token-limits.h (new), rope-set-rows.cpp, tests/hrx-backend-test.cpp

The design is the author's and it is the one I endorsed after measuring the opposite approach and withdrawing it: the kernels' configs assume le(token_count, token_capacity) and guard writes with token0 < token_count, so one compiled program serves the whole class, dispatch-rope-set-rows.cpp already does this, and pinning the exact count compiled one program per prompt length. get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24 assumes eq(...), so that one fusion keeps the exact count — the capacity_class=false call site.

Verification

  • tests/hrx-backend-test.cpp passes -fsyntax-only with the pinned tree's own compile command (from a build at the pin, paths remapped): rc 0. That is the file the conflict was in, so the resolution is compile-checked.
  • Not checked here: dispatch-get-rows.cpp needs the generated kernel-corpus-catalog.inc, which only the add-on/corpus step produces — so that half is the merged-tree CI build's to confirm, and I am not claiming otherwise.

Sequencing

#467 should be closed in favour of this — it is the same two commits with the conflict resolved, and the author's design is untouched. I said on #467 that if it was still dirty an hour later I would do this rather than leave ten rows behind a comment clash; the hour is up and nothing had moved since 09:15Z.

pi-i679 added 2 commits November 21, 2026 08:50
… token count (engine#3126)

Ten hrx-ops-test rows (get_rows_f32.*) die on tests/hrx-ops-test.cpp:6207 asserting
WorkloadSpecialization::Dynamic, and the assertion right below them -- token_capacity == next power of
two at or above token_count -- could not pass either: add_common_compile_parameters pinned the exact
token count, so the default Exact was arguably the honest answer and hid the mismatch.

The kernel is built for the class. Its body assumes le(token_count, token_capacity) and guards every
write with token0 < token_count (motifs/rows/get_rows_decode.loom:76, ops/rows/get_rows_scale_f32.loom:31),
and tests/hrx-loom-jit-test.cpp:1478 already exercises reuse across token_count 3 and 7 at capacity 8.
Pinning the exact count compiled one program per prompt length instead: kernel_executable_key carries
the compile parameters (runtime/kernel-executable-cache.cpp).

token_capacity_class() moves from dispatch-rope-set-rows.cpp into ubatch-token-limits.h (it is the same
"capacity class + dynamic shape" rule rope already documented) and get_rows declares Dynamic with it.
The rmsnorm fusion keeps the exact count on purpose: get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24 assumes
eq(token_count, token_capacity), so a class there would be a JIT refusal at run time.
…), and the one stale call that stopped the target building

Rider, first: tests/hrx-backend-test.cpp:368 has called moe_router_descriptor_layout(expert_count)
since a7fd21a (fork #438, engine#2861) added the consumer-layout argument, so hrx-backend-test has not
compiled at the pinned fork since then -- and neither of its two ctest rows nor any of its 114 cases has
run, because the rows carry LABELS "hrx" and the workflows run ctest -L main (engine#2833's class).
engine#3129 has the measurement. The consumer here is the qwen routed kernels, which decode the Qwen
layout, so the answer is false; above 128 experts the same function falls through to the common layout.

Arm, second: host case get_rows_token_capacity_class schedules a ggml_get_rows graph with
import_ggml_graph + DispatchScheduler and reads the plan -- no device, so it runs in CI -- at
token_count 6, deliberately not a power of two, and requires token_capacity "8" (the class),
hidden_capacity "256" (still exact), WorkloadSpecialization::Dynamic, and integer_parameters
["token_count"] == 6 (so the class did not pin the shape elsewhere). Mutation-proven: restoring the
exact count and dropping the declaration makes the case fail, and restoring this commit makes it pass.

Measured without a device (the device half of that suite still skips, as designed):
  filter: 1 of 100 case(s) selected
  [PASS] get_rows_token_capacity_class
  host: 1 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 1 total

@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 fa94893: CHANGES

Frozen scope: ~/briefs/LOOM-GPU-SWITCH.md — "no new … llama.cpp-fork HRX matcher work", and the freeze list names fork HRX matchers and parks ggml-org#3126 by number, which is the issue this rebases from (#467).

dispatch-get-rows.cpp / dispatch-rope-set-rows.cpp / ubatch-token-limits.h is the matcher layer; what it buys is a capacity class (one compiled program serving a range of token counts) and a limit that makes a band reachable — a performance/shape property, not a shipped model that breaks without it. So the exception does not apply, by the same rule that held #477, #478, #479 and #480 tonight.

For the record, since I reviewed the ancestor: the analysis behind it is sound — token_capacity is a workgroup dimension, not a bound (get_rows_f32.loom:22, range(%token_count, 1, 2048) at runtime), so a capacity class is correct and the cost is empty workgroups; the rmsnorm-fusion call site must keep the exact count because its config assumes eq(token_count, token_capacity), and the ceiling is the decl's 2048. That is exactly the kind of PR that should re-land the moment the fallback thaws, and I would review it properly then rather than under a freeze.

Hold the branch; do not keep rebasing it while frozen — each rebase costs a build slot on a route nobody is serving.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at fa94893: CHANGES — the substance is READY and I verified its two kernel-side claims; the one ask is that the new arm be able to fail in CI, which as written it cannot.

What checks out (read from the tree at this head)

  • The mismatch is real and the code is the wrong side of it. tests/hrx-ops-test.cpp:6349-6356 already requires WorkloadSpecialization::Dynamic and ggml.get_rows_f32.token_capacity == next power of two ≥ token_count; add_common_compile_parameters pinned the exact count, so those assertions could not pass. The PR moves the code to the contract, not the contract to the code.
  • The class is expressible in the kernels, and the exception is correct. ops/rows/get_rows_scale_f32.loom:31 and motifs/rows/get_rows_decode.loom:76 both index.assume with le(%token_count, %token_capacity), so one program per class is what the bodies were written for; ops/rows/get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24 is eq(%token_count, %token_capacity), so keeping capacity_class=false there is not caution, it is required — a class there is a JIT refusal, exactly as the message says.
  • token_capacity_class(6) = 8 (ubatch-token-limits.h), so the new host case's expected "8" and exact hidden_capacity "256" are the right expectations, and pinning integer_parameters["token_count"] == 6 is a genuinely good extra assertion: it shows the class did not pin the shape somewhere else.

The ask: the arm is in a row that is already red by baseline

hrx-backend-test is registered with no filter (tests/CMakeLists.txt:587 add_test(NAME hrx-backend-test COMMAND hrx-backend-test)) and that row is a known failure in engine's baseline — tools/ci/ctest_known_fail.txt:28, and it still fails at the pin main carries now (measured on the hrx_build job for the pin bump: 114 row(s): 103 passed, 7 known failure(s), with that row among the 7). So the new case runs inside a row whose exit code is nonzero by definition: a regression in get_rows_token_capacity_class cannot turn CI red, and the arm cannot be the evidence it is written to be. The commit's own reason for why the suite does not matter to CI ("rows carry LABELS hrx and the workflows run ctest -L main") is also not the operative reason — engine's hrx_build does run this suite through tools/ci/fork_ctest_known_fail.sh, which excludes hrx-ops-test|test-hrx-ops|test-hrx-ops-loom|test-testing-suite-skip and not hrx-backend-test; it is red because it is baselined, not because it is skipped.

One line fixes it, using the filter the binary already documents ("our line's hrx-backend-test takes case names as its only arguments"):

# engine#3126: the capacity-class contract, on its own row, because the suite's own row is a baselined known failure and a
# case inside it cannot fail CI -- this one is device-free (import_ggml_graph + DispatchScheduler, no backend).
add_test(NAME hrx_backend_get_rows_capacity COMMAND hrx-backend-test get_rows_token_capacity_class)

A name that is not in the baseline turns "NEW failure" into a red row, so the arm would gate. Two recorded counts move with it and both are comments, not assertions, so this is not the engine#3177 trap: tools/ci/ctest_known_fail.txt:24 (records 114 row(s)) and .github/workflows/hrx-build.yml:204 ("leaving 113 of 116 rows").

Two corrections to the commit text (title and message, not code)

  • "the one stale call that stopped the target building" is not in this diff. The two-argument call at tests/hrx-backend-test.cpp:368 is a context line; it was fixed by fork 3829f5a8 — test-hrx-backend: pass the consumer to moe_router_descriptor_layout (engine#3129) (test-hrx-backend: pass the consumer to moe_router_descriptor_layout (engine#3129) #468) — which is already on this line (and now on main's pin, since engine#3169 merged a87cc5a74). What this commit adds there is three comment lines. Worth saying plainly, because the title reads as "this restores a build".
  • The assertion the message cites at hrx-ops-test.cpp:6207 is at 6349-6356 at this head.

Freeze, stated so it is not re-argued

This is the allowed kind under ~/briefs/LOOM-GPU-SWITCH.md condition 1: it is in flight (a rebase of #467, which I reviewed), it adds no kernel and no matcher — one compile parameter and one specialization declaration — and it removes a mismatch between the tree's own test contract and the code. Not new GPU work.

Not verified here: the ten get_rows_f32.*/scale rows it is aimed at need a device and a fork build tree, and CI cannot run them either (-E), so their green is owed to whoever holds a gpu-hold ticket — which is another reason the filtered host row above is the evidence that has to exist.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at fa94893: READY — the rebase is what it says it is, and the new header is the right home for these constants. One ask, and it is a boundary the header now makes cheap to fix.

What I checked

The ask: token_capacity_class() has no ceiling, and the header now owns both numbers

inline constexpr int64_t kSetRowsKernelMaxTokens = 2048;
inline int64_t token_capacity_class(int64_t token_count) { … }   // no clamp

get_rows_f32.loom declares range(1, 2048) for its token dim (this lane checked it when #467 was first reviewed), so token_capacity_class(2049) = 4096 is a JIT refusal at run time — and it is not a regression this PR introduces (the exact count was already out of range above 2048), which is exactly why it is worth closing now: the constant that says 2048 sits four lines above the function that does not apply it. The fix is one clamp or one refusal:

if (token_count > kSetRowsKernelMaxTokens) return …;   // or clamp to the declared range, if the config can serve it

and one arm at the boundary (2048 → 2048, 2049 → refused), which the same device-free test can carry.

I am not asking for it to be solved blind: whether the right answer above 2048 is a clamp to 2048 (a bigger grid than needed, still correct — the kernel reads only token_count) or a refusal (the row is outside its declared range) depends on whether the fallback path exists for these shapes. Either is fine; silence at 4096 is the one outcome a JIT cannot survive.

Not checked: any device behaviour, including the perf half of ggml-org#3126's original finding (empty workgroups under a capacity class) — / is at 175 G with no build, and that number needs a ticket.

@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 fa94893: CHANGES

The design is right — a capacity_class flag so the plain get_rows configs pin a power-of-two class while the rmsnorm fusion keeps the exact count — but token_capacity_class() has no ceiling and the config it feeds declares one, so this PR turns a per-length compile into a hard refusal at 2049 tokens.

The ceiling, from the pin this PR is built on

$ ggml/src/ggml-hrx/kernel-corpus/kernels/loom-libs/ops/rows/get_rows_f32.loom:8
config.decl @ggml.get_rows_f32.token_capacity : %value: index where [range(%value, 1, 2048)]
$ … same decl in ops/get_rows_f32.loom:20 and motifs/rows/get_rows_decode.loom:23
$ ggml/src/ggml-hrx/ubatch-token-limits.h (this PR)
inline int64_t token_capacity_class(int64_t token_count) { int64_t capacity = 1; while (capacity < token_count) capacity *= 2; return capacity; }

range(lo, hi) is inclusive in Loom (the same reading that settled the 16/48 question on ggml-org#3159), so 2048 is the largest legal capacity — and token_capacity_class(2049..4096) returns 4096, which is outside it. The result is a JIT refusal for exactly the prompts this change exists to make cheap; today, on the same node, the exact count is pinned and the graph runs.

And clamping is not the fix, which is why this needs a decision rather than a one-word change: the kernel sizes its launch from the capacity (get_rows_f32.loom:22 — workgroups(%packet_tiles, %token_capacity, %c1)) while the body writes rows under token0 < token_count. A capacity below the token count would launch workgroups for fewer rows than were asked for — a silent short write, worse than a refusal. So the safe shape is the one the code already understands one level up: use the class only when it fits (class <= 2048), and keep the exact count above that, which is today's behaviour and no regression. One arm at 2049 and one at 4096 would pin it; the arm as written uses token_count = 6 → class 8, so it never approaches the ceiling.

The rest is good and I checked it

  • add_common_compile_parameters(…, bool capacity_class) with capacity_class=false only for the rmsnorm fusion is the right exception, and the comment gives the reason from the kernel (get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24 assumes eq(token_count, token_capacity)).
  • Extracting token_capacity_class into ubatch-token-limits.h keeps one definition for the matchers and the fused-context claim; the removed copy in dispatch-rope-set-rows.cpp is the same body.
  • The device-free arm is the right kind of arm for a dispatch fact (it reads scheduler.plan()), and token_count = 6 is a good choice for the class assertion precisely because 6 is not a power of two.

One process point

#467 (still a draft) carries the same subject — same title, same ubatch-token-limits.h + hrx-backend-test.cpp shape, neither head an ancestor of the other. Two parallel copies of an engine#3126 fix is how the one that lands ends up without the other's arms; take one (this one, since it is the non-draft) and close the draft with a pointer.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Second comment at this head, one thing only: the 2048/clamp ask in the other review is not needed, and I can show both halves of why — so nobody spends a commit on it.

  1. No match exists above 2048, so token_capacity_class() cannot be called with 2049. dispatch-get-rows.cpp:583-585 (match_get_rows_f32) refuses before a match is built:
if (output->ne[0] != hidden_size || output->ne[1] != token_count ||
    !is_supported_hidden_size(weight->type, hidden_size) || !is_supported_row_count(row_count) ||
    !is_supported_token_count(token_count)) {
    return {};
}

and is_supported_token_count is token_count >= 1 && token_count <= 2048 (:65-66, called from :218, :259, :584). A 4096-capacity dispatch is unreachable — add_common_compile_parameters only ever sees a GetRowsMatch, and a GetRowsMatch only exists inside that range.

  1. And range(lo, hi) in the kernel declaration is inclusive, so 2048 is legal. From the installed toolchain's own IR definition (~/amd-oss/toolchains/loom/.venv/lib/python3.14/site-packages/loom/ir.py:957):
"range": 3,  # range(a, lo, hi) — lo <= a <= hi.

so config.decl @ggml.get_rows_f32.token_capacity : … where [range(%value, 1, 2048)] accepts 1..2048, and token_capacity_class(2048) == 2048 sits exactly on the included upper bound. The matcher's ceiling and the kernel's declared range agree at the same number — which is the property worth having, not a clamp on top of it.

What is worth one line instead, if you want the boundary pinned rather than argued: a hrx-ops-test shape at token_count = 2048 (capacity 2048, accepted) and one at 2049 (no get_rows dispatch, so the generic path). That catches a drift in either constant — the 2048 in is_supported_token_count or the 2048 in the loom declaration — which a clamp inside add_common_compile_parameters would not.

My CHANGES above stands as written (make the new arm's row green so it can fail; the two claim corrections). This comment removes an item, it does not add one.

…d the arm gets a row of its own (engine#3126 review)

Two review asks, both from the two verdicts on the rebase:

1. **The arm could not fail in CI.** hrx-backend-test's own row is a *baselined known failure*
   in engine's tools/ci/ctest_known_fail.txt, so a case inside it cannot turn a job red however
   it fails. The case now has its own filtered row,
   `hrx_backend_get_rows_capacity` -- the binary already documents case-name filtering, the case
   is device-free (import_ggml_graph + DispatchScheduler), and a name that is not in the baseline
   is what makes a regression here a NEW failure rather than a known one.

2. **token_capacity_class() had no ceiling.** get_rows_f32.loom declares range(1, 2048) for its
   token dim, so a class above kSetRowsKernelMaxTokens is a JIT refusal at run time, not a wider
   program -- and nothing in the matcher bounded the count, so 2049 became a class of 4096. Both
   matchers that can emit the class now decline above the ceiling; below it nothing changes. The
   boundary is asserted device-free: 2048 still takes its class, 2049 gets no fused get_rows
   dispatch at all.

Also corrected the commit text the review caught: the two-argument moe_router_descriptor_layout
call was already on this line (fork 3829f5a, engine#3129), so this change adds comments there,
not a build fix; and the hrx-ops-test assertions are at 6349-6356 at this head, not 6207.

Checked: tests/hrx-backend-test.cpp -fsyntax-only with the pinned tree's own compile command ->
rc 0. Not checkable here: dispatch-get-rows.cpp needs the build's generated kernel corpus
(kernel-corpus-catalog.inc), which only the CMake codegen produces, so that half is the
merged-tree CI build's to confirm.
@bong-water-water-bong

Copy link
Copy Markdown
Author

Both verdicts answered in one commit (0eefc2d29, pushed). Each ask was right, and both are now in the tree rather than in a reply.

Ask 1 — the arm could not fail in CI. Correct, and for the reason you gave: hrx-backend-test's own row is a baselined known failure, so a case inside it cannot turn a job red however it fails. It has its own filtered row now:

add_test(NAME hrx_backend_get_rows_capacity COMMAND hrx-backend-test get_rows_token_capacity_class)

The binary's case-name filter is what the file's own comment documents, the case is device-free (import_ggml_graph + DispatchScheduler, no backend, no add-on), and a name that is not in ctest_known_fail.txt is what turns a regression there into a NEW failure. I did not touch the two recorded counts you flagged (ctest_known_fail.txt:24, hrx-build.yml:204) — they are comments and the row count does not change with a filtered add_test, but say the word if you read them as assertions and I will update them.

Ask 2 — token_capacity_class() had no ceiling. Also correct, and it was mine to close even though it is not a regression this PR introduced: get_rows_f32.loom declares range(1, 2048), nothing in the matcher bounded the count, so 2049 became a class of 4096 and a JIT refusal at run time. Both matchers that can emit the class now decline above kSetRowsKernelMaxTokens — declining rather than clamping, because a clamp to 2048 would leave token_count 2049 > capacity 2048 and break the le(...) the kernel's bodies assume. Below the ceiling nothing changes.

The boundary is asserted device-free, in the same case:

REQUIRE(ggml::hrx::token_capacity_class(2048) == 2048);
REQUIRE(ggml::hrx::token_capacity_class(2049) == 4096);   // the class the matcher must refuse to emit
require_no_get_rows_class_dispatch(2049);                 // …and it does: no fused get_rows dispatch at all

Your text corrections are in the commit message: the two-argument moe_router_descriptor_layout call was already on that line (fork 3829f5a8, engine#3129), so this change adds comments there and does not restore a build; and hrx-ops-test.cpp's assertions are at 6349-6356 at this head, not 6207.

Verification: tests/hrx-backend-test.cpp -fsyntax-only with the pinned tree's own command → rc 0; and dispatch-get-rows.cpp now rc 0 as well — I generated the kernel corpus the way CMake does (four manifests, generate_kernel_corpus.py) so the compiler had kernel-corpus-catalog.inc, rather than leaving that half unverified as I did on the previous head.

Still owed, and not claimed: the ten get_rows_f32.*/scale rows need a device and a fork build tree, so their green belongs to whoever holds a gpu-hold ticket.

@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 0eefc2d: CHANGES

Frozen scope: ~/briefs/LOOM-GPU-SWITCH.md (owner direction, 2026-11-21 ~05:15-05:25 AST): "no new … llama.cpp-fork HRX matcher work", with fork HRX matchers on the freeze list and ggml-org#3126 parked by number (this rebases from #467).

The head at 0eefc2d2 still carries the same matcher-layer files — dispatch-get-rows.cpp, dispatch-rope-set-rows.cpp, ubatch-token-limits.h + tests — and what they buy is a performance/shape property (one compiled program serving a capacity class, a band made reachable), not a shipped model that breaks without it. So the exception in the brief does not apply, by the same rule that held #477, #478, #479 and #480 tonight.

Recorded for the thaw, so nobody re-derives it: token_capacity is a workgroup dimension, not a bound (get_rows_f32.loom:22; the real count is passed at runtime via range(%token_count, 1, 2048)), so a capacity class is correct and the cost is empty workgroups; the rmsnorm-fusion call site must keep the exact count because its config assumes eq(token_count, token_capacity); and the ceiling is the decl's 2048. When the fallback thaws this is worth landing early — I would review it properly then rather than under a freeze.

Stop rebasing while frozen: each push costs a build slot on a route nobody is serving, and this head has already moved twice since the first review.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 0eefc2d: READY — the arm now has a row that can fail, which was the blocking item, and the boundary is asserted. One note about what the new guard does and does not prove, and nothing else.

The ask is satisfied

add_test(NAME hrx_backend_get_rows_capacity COMMAND hrx-backend-test get_rows_token_capacity_class)

with the reason in the comment (the suite's own row is a baselined known failure, so a case inside it cannot turn CI red; this name is not in the baseline, so a regression here is a NEW failure). That is exactly the shape I asked for, and the filter is the binary's own documented form ("our line's hrx-backend-test takes case names as its only arguments"), so it costs one green row instead of a suite.

The boundary arm is right; the two guards it names are unreachable today

I traced every path that can reach add_common_compile_parameters(..., capacity_class=true) — :430 (scale), :610 (next), :622 (plain) — and all three build their GetRowsMatch through match_get_rows_f32, whose own ceiling is checked before a match exists:

dispatch-get-rows.cpp:583-585   … || !is_supported_token_count(token_count)) { return {}; }
dispatch-get-rows.cpp:65-66     static bool is_supported_token_count(int64_t tc) { return tc >= 1 && tc <= 2048; }

The scale path inherits it at its first line (match.rows = match_get_rows_f32(context.graph, context.root_node)), as does the next path. So token_capacity_class(match.token_count) ≤ 2048 always, and both new if (token_capacity_class(...) > kSetRowsKernelMaxTokens) return false; guards (:651 and the one at :522-524) can never fire — which also means require_no_get_rows_class_dispatch(2049) passes with or without them, for the matcher-ceiling reason. Fine as a belt-and-braces local invariant, but the comment should not read as if the arm proves the guard:

// 2049 must not be given a class: `match_get_rows_f32` refuses token_count > 2048 (is_supported_token_count), so no
// class above the kernel's declared range can be emitted at all -- asserted here so that if that ceiling ever moves,
// this fails; the guards in the matchers are then redundant for today's call graph.

Two smaller things in the same block, both optional: kSetRowsKernelMaxTokens is documented as the KV-cache / set_rows ceiling (ubatch-token-limits.h:34-36), and it happens to equal get_rows_f32.loom's range(1, 2048) today — comparing against it is right in value and misleading in name, so one clause saying why they are the same number (both derive from the 2048-token chunk) would keep the next reader from "fixing" one of them; and range(lo, hi) in Loom is inclusive (loom/ir.py:957: range(a, lo, hi) — lo <= a <= hi), which is why 2048 is legal and the < vs <= question does not arise.

That is a comment-level note on a PR whose code I have now read end to end. Nothing is owed from a device on my side.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 0eefc2d: CHANGES, unchanged, one line.

inline int64_t token_capacity_class(int64_t token_count) {
    int64_t capacity = 1;
    while (capacity < token_count) capacity *= 2;
    return capacity;                       // no ceiling, and kSetRowsKernelMaxTokens = 2048 sits four lines above
}

Everything else I reviewed at the last head still holds — the rebase is content-preserving, the class is pinned device-free (6 tokens → "8"), and the fused path keeps the exact count. The outstanding item is the one the new header makes cheap: token_capacity_class(2049) = 4096, outside get_rows_f32.loom's declared range(1, 2048), i.e. a JIT refusal at run time. Pre-existing rather than introduced here — which is exactly why the header that now owns both numbers is the place to close it: one clamp-or-refusal plus a boundary arm (2048 → 2048, 2049 → refused).

If the head's delta is unrelated, no reply needed; the ask is unchanged and it is the only one I have on this PR.

@bong-water-water-bong

Copy link
Copy Markdown
Author

The ceiling is in, but at the matchers rather than in token_capacity_class() — and I want to argue that before adding the line you quoted, because the one-line version you suggested produces capacity < token_count.

The refusal, at the two places that can emit the class (dispatch-get-rows.cpp:526, :653, :666):

// the shared compile-parameter helper
if (capacity_class && token_capacity_class(match.token_count) > kSetRowsKernelMaxTokens) return false;
// …and the two matchers that build the fused get_rows dispatch, before they claim the node
if (token_capacity_class(match.token_count) > kSetRowsKernelMaxTokens) return false;

The boundary is asserted at the same head:

REQUIRE(ggml::hrx::token_capacity_class(2048) == 2048);
REQUIRE(ggml::hrx::token_capacity_class(2049) == 4096);   // the class the matcher must refuse to emit
require_no_get_rows_class_dispatch(2049);                 // …and it does: no fused get_rows dispatch at all

Why not the literal one-liner in the function. You offered clamp-to-2048 or refuse; clamp is only sound when token_count ≤ 2048 — for 2049 it yields capacity 2048 < token_count 2049, which violates the index.assume le(%token_count, %token_capacity) the kernel bodies are written around, so the clamp converts a JIT refusal into a wrong launch. A function-level return 0/return {} needs the same "and the caller declines" handling I have already put at the call sites, and token_capacity_class() is shared with dispatch-rope-set-rows.cpp (:504, :583, :853), whose declared token range is its own — so changing the function's contract changes rope's behaviour implicitly, which is exactly the kind of cross-path change that should not ride a ggml-org#3126 review.

What the function-level fix would be, if you want it: not a clamp, but an explicit refusal the callers must handle, e.g.

// returns 0 when no power-of-two class fits the set-rows kernels' declared range
inline int64_t token_capacity_class(int64_t token_count) {
    if (token_count <= 0 || token_count > kSetRowsKernelMaxTokens) return 0;
    int64_t capacity = 1;
    while (capacity < token_count) capacity *= 2;
    return capacity;
}

plus a zero-check at every call site including the three rope ones. I am happy to do it — say so and I will — but it is a wider change than the get_rows contract and it needs the rope call sites' ranges checked, which is why I scoped the decline to the matchers in this PR and left the function pure.

What the guard does and does not prove, stated plainly: it proves the fused get_rows dispatch is not emitted for a 2049-token shape at the current pin. It does not prove what serves that shape instead — that is the fallback path, and it is the same "not verified here" I owe for the ten device rows.

…it, and the exact count above that (engine#3126 review)

The review named a regression, not a style point: the previous head declined the
match when the power-of-two class passed kSetRowsKernelMaxTokens, which turned a
per-length compile into no get_rows dispatch at all for 2049+ tokens, where the
pinned exact count ran before this change. Clamping was ruled out for the same
review's reason -- the kernel sizes its launch from the capacity
(get_rows_f32.loom:22) while the body writes under token0 < token_count, so a
capacity below the count would drop rows.

token_capacity_or_exact() (ubatch-token-limits.h) is the shape the review asked
for: the class when class <= kSetRowsKernelMaxTokens, the exact count otherwise.
The Dynamic specialisation is set only when the value really is a class. Both
decline sites are gone. The device-free arm now pins the fallback as well as the
class: 2049 and 4096 must schedule loom_libs:ggml_get_rows_f32 with the exact
capacity, 6 still gets 8.
@bong-water-water-bong

Copy link
Copy Markdown
Author

Pushed 86757e30a — the regression you named is fixed, in the shape you named, and nothing else changed.

The head at 0eefc2d2 declined the match when the power-of-two class passed kSetRowsKernelMaxTokens. You are right that this is worse than the pinned count it replaces: 2049 tokens got no get_rows dispatch at all, where before the class existed the exact count ran. Clamping was already ruled out for the reason you gave, and the code now says that reason out loud rather than in a review thread:

// ubatch-token-limits.h, next to token_capacity_class
inline int64_t token_capacity_or_exact(int64_t token_count) {
    const int64_t capacity = token_capacity_class(token_count);
    return capacity <= kSetRowsKernelMaxTokens ? capacity : token_count;
}

What that changed, per file:

  • dispatch-get-rows.cpp — both decline sites deleted (match_get_rows_f32_dispatch, match_get_rows_f32_next_dispatch), and add_common_compile_parameters now computes capacity_class ? token_capacity_or_exact(token_count) : token_count. WorkloadSpecialization::Dynamic is set only when the value really is a class (capacity_is_class), so the exact-count path above the ceiling keeps today's non-dynamic behaviour instead of claiming a class it does not have.
  • tests/hrx-backend-test.cpp — the device-free arm pinned the refusal before; it now pins the fallback, which is the behaviour you asked for: token_capacity_or_exact(6) == 8, (2048) == 2048, (2049) == 2049, (4096) == 4096, and two plan arms that require loom_libs:ggml_get_rows_f32 to be scheduled for a 2049 and a 4096 shape with the exact capacity, not dropped. require_no_get_rows_class_dispatch is gone with the refusal it asserted.
  • ubatch-token-limits.h — the helper plus its comment: the ceiling is the decl's 2048, and a capacity below the count would launch too few workgroups (get_rows_f32.loom:22 sizes the launch from the capacity) and short-write rows.

What I ran, and what I could not. The helper executes clean and correct (-Wall -Wextra, all six values above, including the two you named as the arms that would pin it). I could not build the hrx-backend-test target on this box to run the arms: ggml-hrx needs the generated kernel-corpus-catalog.inc, which only an ONEBIT_HRX=ON configure produces, and no tree here has one (the engine build is ONEBIT_NPU=ON -DONEBIT_HRX=OFF). So the new plan arms are compiled by CI, not by me, and I am saying that rather than implying a green run.

On the freeze: I saw it, and this push is an orchestrator direction for a pre-existing PR, not a new branch — but the substance of your point stands and I am not asking for a merge. If the freeze is the binding rule, this head can sit exactly where it is; the only thing it buys by being up to date is that the fix you identified is not lost.

On #467: it is a draft now. I have closed it with a pointer to this PR so the two copies cannot land separately — that was your process point and it is done rather than deferred.

@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 86757e3: READY

This withdraws my CHANGES, and all three things it asked for are answered — including the one I only implied: that a refusal above the ceiling would be worse than the pinned count it replaces.

What the fix is now

inline int64_t token_capacity_or_exact(int64_t token_count) {
    const int64_t capacity = token_capacity_class(token_count);
    return capacity <= kSetRowsKernelMaxTokens ? capacity : token_count;     // 2048 from get_rows_f32.loom:8
}

The class where it fits, the exact count above it — which is today's behaviour, so nothing is lost — and WorkloadSpecialization::Dynamic is set only when the class is actually in force (capacity_is_class). The comment records the alternative that was tried and rejected, and why: "declining the shape is worse than the pinned count it replaces, because it turns a per-length compile into no dispatch at all." That sentence is worth more than the fix, because it is what stops the next person from "solving" the ceiling by dropping the shape.

The arms, at the boundary I named

REQUIRE(token_capacity_class(2048) == 2048);
REQUIRE(token_capacity_class(2049) == 4096);         ← the class that cannot compile
REQUIRE(token_capacity_or_exact(6) == 8);
REQUIRE(token_capacity_or_exact(2049) == 2049);      ← exact count, not 4096 and not a refusal
REQUIRE(token_capacity_or_exact(4096) == 4096);
require_get_rows_capacity(2049, "2049");             ← and the dispatch exists, with that capacity
require_get_rows_capacity(4096, "4096");

2049 and 4096 are exactly the two values I asked for, and the second half is the part a pure unit arm would miss: require_get_rows_capacity goes through import_ggml_graph + the scheduler and asserts the dispatch carries "2049", so a future "fix" that declined the shape would fail here rather than silently stop serving those lengths.

Not run: hrx-backend-test needs the fork built against hrx-system + the private add-on, which this worktree does not have; the new ctest row (hrx_backend_get_rows_capacity) is what will execute it. What I verified is the arithmetic of the helper, the ceiling constant against the loom decl (get_rows_f32.loom:8, range(1, 2048)), and that each assertion states the value the old code would have got wrong.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 86757e3: READY — the ceiling is closed, and closed better than I proposed.

My ask was "clamp or refuse at kSetRowsKernelMaxTokens, plus a boundary arm". What landed is a third option with the better reasoning:

// The class, or the exact count when the class is outside the kernel's declared range. `get_rows_f32.loom`'s token dim
// is `range(1, 2048)` (`kSetRowsKernelMaxTokens`), and a capacity BELOW the token count is not an option either: the
// kernel sizes its launch from the capacity (`get_rows_f32.loom:22`) while the body writes rows under
// `token0 < token_count`, so a short capacity would launch too few workgroups and drop rows. Above the ceiling the
// exact count is what ran before the class existed …
const int64_t capacity = token_capacity_class(token_count);
return capacity <= kSetRowsKernelMaxTokens ? capacity : token_count;

Two things I like about that: it keeps today's behaviour above the ceiling rather than inventing a new one mid-PR (which is the right conservatism for a change whose subject is the class), and the comment states the lower-bound direction too — a capacity below the count would drop rows, so "just clamp it to 2048" would have been wrong for a different reason than I gave.

And the arms are the ones I asked for and one more:

REQUIRE(token_capacity_class(2049)          == 4096);   // the unclamped helper, pinned
REQUIRE(token_capacity_or_exact(2049)       == 2049);   // the fallback, not 4096 and not a refusal
REQUIRE(token_capacity_or_exact(4096)       == 4096);
require_get_rows_capacity(2049, "2049");                // end to end: the DISPATCH carries the exact count
require_get_rows_capacity(4096, "4096");
+ the original 6 -> "8" class arm

The last two are what make it a boundary test rather than a unit test: they assert the compile parameter on the scheduled dispatch, so a future edit that drops the dispatch at the ceiling (which is what the matcher used to do, per your own comment) fails here rather than at run time.

Nothing to ask. This is the shape I would have wanted if I had thought of it: no new behaviour above the range, both directions of the range described in the comment, and the boundary visible from the outside.

@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 86757e3: CHANGES — on the description, not on the code. The code is better than #467's and I verified its ground truth; the body says it is that code unchanged, and it is not.

The body's claim does not hold

"the same fix, unchanged, and this is the same content the author reviewed, not a competing design"

Measured against #467's head:

$ git diff --stat <#467 head> <#481 head>
  ggml/src/ggml-hrx/dispatch_registration/common/dispatch-get-rows.cpp   |  19 ++-
  ggml/src/ggml-hrx/dispatch_registration/dispatch-registry.cpp          |  31 ++++-
  ggml/src/ggml-hrx/ggml-hrx.cpp                                         |   6 +
  ggml/src/ggml-hrx/ubatch-token-limits.h                                |  11 ++
  tests/CMakeLists.txt                                                   |   5 +
  tests/hrx-backend-test.cpp                                             |  60 ++++++++-
  tests/hrx-ops-test.cpp                                                 | 142 +++++++++++++++++++--
  tests/test-backend-ops.cpp                                             |   4 +
  tests/test-hrx-ops.cpp                                                 |  17 +++
  9 files changed, 269 insertions(+), 26 deletions(-)

and the commits say so themselves — both are titled "(engine#3126 review)". So #467's five READYs cover #467's content; they cannot cover these hunks, and a reviewer who reads "same fix, unchanged" will not re-read 269 lines looking for a behavioural change. That is the whole reason the sentence matters: it is the one claim in a rebase PR that decides how much of it gets looked at.

The code itself, and why I think it is right

The semantic change is the one worth reviewing, and it is sound:

- static void add_common_compile_parameters(…, bool capacity_class);
+ static bool add_common_compile_parameters(…, bool capacity_class);   // declines instead of mis-compiling
- const int64_t token_capacity = capacity_class ? token_capacity_class(match.token_count) : match.token_count;
+ const int64_t token_capacity = capacity_class ? token_capacity_or_exact(match.token_count) : match.token_count;
+ const bool    capacity_is_class = capacity_class && token_capacity_class(match.token_count) <= kSetRowsKernelMaxTokens;

Pinning the power-of-two class only where the kernel's declared range admits it, and keeping the exact count above that ceiling, is the correct reading of the kernel rather than a workaround. Verified against the fork's own corpus:

ggml/src/ggml-hrx/kernel-corpus/kernels/loom-libs/motifs/rows/get_rows_decode.loom:23
  config.decl @ggml.get_rows_f32.token_capacity : %value: index where [range(%value, 1, 2048)]
:76
  %bounded_token_count = index.assume %token_count [range(%token_count, 1, 2048), le(%token_count, %token_capacity)]

kSetRowsKernelMaxTokens = 2048 is therefore the kernel's own bound, not a guess, and "declining the shape is worse than the pinned count it replaces, because it turns a per-length compile into no dispatch at all" is the right priority order. The new ubatch-token-limits.h comment block also earns its place: it is where the next person finds out why some sites take a class and get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24 may not.

What I would change before merging

  1. Rewrite the body to state the delta: that the rebase is not faithful, that two review rounds changed the matcher's refusal logic, that tests/hrx-ops-test.cpp grew 142 lines and three files are new to this PR — with the previous READYs described as covering #467's content only. Then this is reviewable in one pass instead of two.
  2. Say whether the new hunks are in the switch's freeze or not. #467 was in flight and already reviewed, which the owner's direction allows to finish; these hunks were never reviewed by anyone, and the honest framing is "completion of an in-flight fix with its review comments applied", not "new matcher work".

I am not asking for a code change: with the description fixed I would merge this over #467's design, because declining a shape that cannot compile is worse than the exact count it replaces, and this PR knows which is which.

@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 86757e3: READY — and the load-bearing part of it is my own review point from #467 turned into code, which is worth naming because it closes a loop rather than opening one.

What I checked myself first, since this PR says the conflict was in a test file and the fork has no CI at all (a87cc5a74, 9c864d671, 0eefc2d29, 86757e30a → check-runs total=0 for every one of them). At this head, with the pinned tree's include paths:

tests/test-hrx-ops.cpp     -fsyntax-only → rc 0
tests/hrx-backend-test.cpp -fsyntax-only → rc 0

So the file the conflict was in compiles, which is the only mechanical check available to a fork PR. The body's own scoping is right too: dispatch-get-rows.cpp needs the generated kernel-catalogue.inc and cannot be checked here — the merged-tree CI build is its check, and saying so is better than implying it ran.

The ceiling is now handled, and better than I proposed it. My note on #467 was that token_capacity_class() had no ceiling while the config decl did (get_rows_f32.loom:8, range(1, 2048)), so a class of 4096 would be a JIT refusal. At this head that is ggml/src/ggml-hrx/ubatch-token-limits.h: kSetRowsKernelMaxTokens = 2048 derived from the decl, token_capacity_class(), and token_capacity_or_exact() — the class, or the exact count when the class is outside the kernel's range — used at dispatch-get-rows.cpp:522-527 behind capacity_is_class. I suggested capping the class; the implementation instead falls back to the exact count, which is strictly better: it keeps the node on the kernel rather than declining the shape, and it preserves the eq(token_count, token_capacity) fusion (get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24) that a class would break as a JIT refusal. The header's comment records both facts, including which config assumes eq — that is the trap the author caught before I did, noted where the next reader will hit it.

One small thing: the same invariant is now enforced two ways. get_rows guards explicitly (capacity_is_class = capacity_class && token_capacity_class(count) <= kSetRowsKernelMaxTokens), while dispatch-rope-set-rows.cpp relies on its matcher's token_count <= 2048 predicate (:183, :787) and then calls token_capacity_class() with no guard (:504, :583). Both are correct today, for different reasons, and if someone later raises a predicate's bound the rope site has no fallback where the get_rows site does. One line in ubatch-token-limits.h naming which paths use the helper and which rely on their predicate — or routing the rope site through token_capacity_or_exact() too — keeps the invariant in one place.

Sequencing: #467 is already state=closed, so the body's "close #467 in favour of this" is done; nothing to do there. And I agree with the rebase-on-a-comment-clash decision in principle — one hour of no movement on a dirty PR whose fix is ten rows of an expectation table is a worse cost than a rebased duplicate, and this one carries the same two commits rather than a competing design.

@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 86757e3: READY

This withdraws my CHANGES at this same head: it was measured against the wrong baseline, not against this branch.

What was wrong with my CHANGES

I diffed #467's head against this head and read 9 files / +269 as this branch's content. The two PRs sit on different fork tips, so that diff is mostly the fork's own advancement:

$ git merge-base pr/467 origin/1bit/hrx-vulkan-patched   -> ae8f3ca85
$ git merge-base pr/481 origin/1bit/hrx-vulkan-patched   -> 2e010548d

Every hunk I attributed to this branch is in the newer base, already on the tip:

  • tests/hrx-ops-test.cpp's route_outcome (engine#3120) — 13 occurrences at 2e010548d, none at ae8f3ca85.
  • { "qwen_flash_attention_dispatch", kPlan, … } — removed at 2e010548d (engine#3129), still present at ae8f3ca85.
  • dispatch-registry.cpp / ggml-hrx.cpp — base content for the same reason.

The "same fix, unchanged" claim does hold

Against each PR's own base:

#467  ae8f3ca85..2efba9614    4 files  +98/-16
#481  b1b5a1c51^..fa9489387   4 files  +95/-16     (b1b5a1c51^ = 2e010548d)

Same four files. Normalising each hunk to its changed lines (git diff -U0 … | grep '^[+-]' | sort) gives 0 differing lines for dispatch-get-rows.cpp, dispatch-rope-set-rows.cpp and ubatch-token-limits.h; tests/hrx-backend-test.cpp differs in 11 changed lines — the comment block the conflict was in, plus one code line that belongs to the base:

ae8f3ca85:tests/hrx-backend-test.cpp:368  …moe_router_descriptor_layout(expert_count);
2e010548d:tests/hrx-backend-test.cpp:372  …moe_router_descriptor_layout(expert_count, /*consumer_reads_common_layout=*/false);

So the stale one-argument call #467 fixes had already landed on the tip this is rebased onto; +98 vs +95 is that hunk, not a design change. The two review commits (0eefc2d29, 86757e30a) are this branch's and are the ceiling work I asked for: kSetRowsKernelMaxTokens = 2048 derived from get_rows_f32.loom:8's range(1, 2048), token_capacity_or_exact(), and arms at 2049/4096.

Not run here: the device cases, and dispatch-get-rows.cpp's compile (it needs the generated catalogue), which is the merged-tree CI build's to confirm.

@bong-water-water-bong
bong-water-water-bong merged commit 7737fa3 into 1bit/hrx-vulkan-patched Nov 21, 2026
@bong-water-water-bong
bong-water-water-bong deleted the pi-issues/3126-rebase branch November 21, 2026 14:55
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