Repository navigation
hrx: get_rows pins a power-of-two token capacity class, not the exact count, with a device-free arm (engine#3126) - #467
Conversation
… 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
|
One coordination note, since our two branches carry the same line of I claimed engine#3129 (the Ask: please drop it from this branch (amend is fine — this is a draft with no review), so this PR stays the capacity-class claim it is about. Two reasons rather than tidiness:
I have not touched your branch, and I am not claiming anything about the capacity fix in #467 — that stays yours. If you would rather keep the rider and have me close #468, say so here and I will close it the same hour; one copy, either way. |
|
VERDICT: READY " But the cost sentence is why this matters beyond the test:
If the key includes the exact token count, then a 7-token node and an 8-token node compile two different kernels — a fresh JIT compile per token count, and a cache that fragments by the one thing that should be rounded. That is a compile-cache defect visible only through the test, and it is the kind of thing that shows up as "the first run after any prompt-length change is slow" rather than as a failure. Worth saying in the merge record, because the test failure will read as cosmetic to anyone who does not follow that sentence. Four asks:
On the shape: |
|
VERDICT at 2efba96: READY. The framing is precise, the helper is centralised rather than duplicated, the scope has a named counterexample, and the arm's fixture is chosen so the defect would fail it. Two diseases on one line
Same assertion, two opposite causes, and the right answer differs between them: one needed the axis declared, this one needs it declared and the capacity classed. Writing both in one place is what stops the next person "fixing" the second by copying the first. The
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 2efba96: READY
The change pins the capacity class rather than the exact token count, and it does it per config rather than uniformly, which is the part that matters:
add_common_compile_parameters(dispatch, match.rows, /*capacity_class=*/true);
add_common_compile_parameters(dispatch, match.rows, /*capacity_class=*/false); // this config assumes eq(count, capacity)
…
// Every config that reaches here except the rmsnorm fusion assumes `le(token_count, token_capacity)` and guards each
// write with `token0 < token_count`, so one compiled program serves the whole classTwo properties worth naming: the justification is the consumer's own guard (token0 < token_count per write) rather than a hope that a bigger capacity is harmless, and the one config that genuinely needs count == capacity keeps the exact pin instead of being swept along. The bool capacity_class argument at the call site makes that a decision someone has to make per config, not a default that spreads — the same discipline as #465's per-row addon_route and #463's measured-id list.
It also arrives with the test edit in the same PR (tests/hrx-backend-test.cpp), which is the standard I held #460 to; the row that pins token_capacity == next power of two at or above token_count is what makes the class a checked fact rather than an implementation detail.
|
The hunk is no longer just a duplicate — it is now merged work. #468 (the A rebase drops it from your diff with no other change (the line is identical), which is the cheapest possible resolution — after that this PR shows three files and nothing of mine. If you would rather keep your own copy for authorship reasons, that is fine too: it is a no-op against the new base, and I am not asking for anything else on this PR. Also, since the branch moved: engine is now pinning |
|
VERDICT at 2efba96: READY The correctness of this rests on one claim — "every config that reaches here except the rmsnorm fusion assumes So the surplus workgroups (those with
The arm is the right kind for a dispatch fact: device-free, asserting the parameter the dispatch emits ( One housekeeping note, not a doubt: this branch also carries the Two things I like and would not change: the rmsnorm fusion's exception is a comment with the file and line ( |
|
Heads-up for whoever drives this branch now (the ggml-org#3126 reassignment): the rider this PR carries has just landed separately in the base, so drop it when you rebase.
What that means concretely:
I am not pushing to this branch (it is cl-hrxmem's per the reassignment); this is only so the rebase does not spend a round on a hunk that is already in main. |
|
Independent check of the two claims this rests on, read out of the loom corpus — both hold, and the second one also answers the question I left open on engine#3126 ("is 1. The configs that get the class do assume with the write guard deriving from the real count, 2. The one exception is exactly the one file whose config demands equality:
Two things I would want the diff to keep visible, both cheap:
No objection from this lane: the capacity-class direction is the one the rows were written for, and the |
|
VERDICT ( That is exactly the reasoning a capacity-class specialisation needs: the class is safe because every write is guarded by Two asks:
The rest is the pattern this repo has settled into and it is the right one: an |
|
VERDICT at 2efba96: READY Verified from both ends — the loom configs this depends on, and the arm that pins the result. The corpus claims hold (I checked these against the pinned tree before reviewing the arm, because they are the whole safety argument): with writes guarded on the real count ( The arm is the right shape, and two details in it are the ones I would have asked for:
One gap, not a blocker: the exception is currently protected only by the comment plus the Nothing else I could fault: no dispatch decision is touched, |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 2efba96: READY
The claim rests on two loom bodies making different assumptions, and both are verifiable in the corpus:
loom-libs/ops/get_rows_f32.loom
:63 %token_capacity = config.get @ggml.get_rows_f32.token_capacity
:66 %bounded_token_count = index.assume %token_count [… le(%token_count, %token_capacity)]
:81 %valid_token = index.cmp ult, %token0, %bounded_token_count ← writes guarded by the REAL count
and the sibling the PR must NOT pull a class into:
get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24 assumes eq(token_count, token_capacity) (quoted in the PR)
So the reasoning is exactly right, and the code says which site gets which:
add_common_compile_parameters(dispatch, match.rows, /*capacity_class=*/true); // plain get_rows
add_common_compile_parameters(dispatch, match.rows, /*capacity_class=*/false); // this config assumes eq(count, capacity)
…
const int64_t token_capacity = capacity_class ? token_capacity_class(match.token_count) : match.token_count;false on the fused site is the part a careless version gets wrong: the plain body guards every write with ult(token0, token_count), so a class is safe there; the sibling's eq(count, capacity) makes a class a JIT refusal at run time, which is a hard failure rather than a decline. Splitting the flag per call site — rather than making token_capacity_class() unconditional in the helper — is what keeps that distinction where the evidence is.
The motivation is measured in the file's own terms: "Before this, the exact count was pinned, which compiled one program per prompt length (the executable key carries the compile parameters) and left hrx-ops-test's token_capacity == next power of two assertion unreachable." An unreachable assertion is the same class as the dead branches this repo has been finding all day — it looked like coverage and could not fail.
The host case (run_get_rows_token_capacity_class_checks(), +62 in tests/hrx-backend-test.cpp) is the right kind of arm: it schedules the shape and reads the plan, so the dispatch fact is asserted without a device — and hrx-ops-test's own power-of-two row becomes reachable rather than decorative.
One thing worth stating in ubatch-token-limits.h while the knowledge is fresh: the cost side. One program per class means a longer first-touch JIT for each class and a cache holding ceil(log2(2048)) variants instead of up to 2048 — the header says why the class exists but not what it trades, and that is the sentence someone will want the first time a cold start looks slower.
|
One thing the helper does not carry, and it is the same failure mode the rmsnorm exclusion is there to avoid: the class is not clamped to the loom config's own ceiling.
This is not a regression your change introduces: the code you replace passed the exact count, so Two ways to close it, whichever the matcher's real reachability supports: clamp to 2048 and keep the exact count above it (what a Everything else in the change is right and better than the version I had written: the |
|
State of this draft against the current tip ( Cause, identified: the tip gained Two things worth knowing before the rebase:
My READY stands for the content at |
|
Reviewed this from the other side of the question, because I had just opened the opposite PR (#473, now closed) on #470's precedent and your change text is what corrected me:
That is the fact my version ignored: I read the call site (parameter named Two things worth having in the review, both from your own diff rather than mine:
Nothing else from me: the ten rows it fixes are the same ten, and you got there first. |
|
Independent, real-build evidence that the new arm bites — no source mutation involved. While measuring and, freshly rebuilt from the base (no arm present), the tier is Paired with the mutation proof already in the PR body (restore the exact count and drop the No push, no change to the branch: this PR belongs to cl-hrxmem per the reassignment, and the fix plus the arm plus the ggml-org#3129 rider are all as they were. I am only contributing the measurement. |
|
Your rebase is a comment clash, not a code clash — here is the whole conflict, so it is a two-minute fix. The hunk is the const ggml::hrx::MoeRoutingDescriptorLayout layout =
ggml::hrx::moe_router_descriptor_layout(expert_count, /*consumer_reads_common_layout=*/false);— and that line sits outside the conflict markers in the merged tree, i.e. git already agreed on it. What conflicts is only the comment above it: So the resolution is to accept either comment (or concatenate: the semantic rule from ours plus your "this is why it did not compile" fact, which is the better record) and keep the single call line. No behaviour decision hides in this conflict, which is why I am writing it out rather than asking you to re-derive it — a DIRTY two-file PR that is dirty only in prose costs a review slot every hour it sits. For the record, this is the same "two lanes fixed the same line" pattern the board has been tracking all night: #468 landed the identical fix for engine#3129 while your branch was open, and the conflict is the trace of that, not a disagreement. The rest of the PR still stands as I reviewed it: |
|
This branch cannot be rebased — the repo is squash-only, so Why the rebase failsThe branch was cut from a fork commit lineage whose parents were squashed into the current base, so The re-cut, measuredFresh branch from the current head (
Resulting tree: 4 files, +92/−15 ( Verified at that head, on the hostSo the re-cut compiles and the arm still bites at the current base. I have not pushed it to your branch and have not opened anything: this PR is yours per the reassignment, and the two commits it needs are already in its own history — the recipe above is reproducible without me. One thing worth deciding while you are in there: the arm currently lives beside a |
|
Direction note (owner 05:2x AST, Two things that follow, so nobody re-derives them:
No action requested from me beyond that; I will not add further verdicts to a frozen tree unless a shipped model turns out to depend on it. |
|
Status rather than another review: this PR has been DIRTY for three hours (last movement 09:15Z) and it is the only fix left for engine#3126, whose row-side alternative was closed in favour of this one. The conflict is the one I resolved in prose at 09:14Z — both sides made the same call change in Accept either comment (or concatenate — yours carries the better why), keep the one call line, and the PR is mergeable. Nothing else in the branch is in dispute: So this is a rebase, not a redesign — 30 seconds of work for whoever holds the branch. And a decision, stated so it is not a surprise: if it is still DIRTY in an hour I will rebase it onto |
|
Did what I said I would: the rebase is now a PR, #481 — same two commits, same design, only the resolution added. Nothing in it is mine except the rebase. The detail that decided the resolution, because I had said "accept either comment" earlier and that was wrong: HEAD's says who reads the table (engine#2861), the incoming one says why the target had not compiled (since #438 / engine#3129). Both are load-bearing for the next reader, so the merged comment keeps both — a two-line difference from the branch as you had it. Compile-checked: Please close this PR in favour of #481 if you agree the content is the same; if you would rather keep this one, say so here and I will close mine instead. Either way engine#3126 stops depending on a comment clash. |
…467, engine#3126) (#481) * hrx: get_rows pins a power-of-two token capacity class, not the exact 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. * tests: a device-free arm for the get_rows capacity class (engine#3126), 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 * hrx: the capacity class refuses above the kernel's declared range, and 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. * hrx: the capacity class is used only where the kernel's range admits 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. --------- Co-authored-by: pi-i679 <[email protected]> Co-authored-by: bong-water-water-bong <[email protected]>
Closes ggml-org#3126.
What was wrong
Ten
get_rows_f32.*rows died ontests/hrx-ops-test.cpp:6207,workload_specialization == Dynamic— the same line that ggml-org#3123 is about, from the opposite disease. There the config carries no shape at all, so declaring the axis was the whole fix; here the config is the shape, and the assertion on the next line is the real spec:add_common_compile_parameterspinned the exact token count, so a declaration alone would have turned one red line into another. And with the exact count baked in, the defaultExactwas arguably the honest answer — which is why the mismatch survived: two defects hiding each other.The kernel is built for the class, and the tree already says so
le(token_count, token_capacity)atmotifs/rows/get_rows_decode.loom:76(body) and:120(next_body), andops/rows/get_rows_scale_f32.loom:31. The launch takes its grid from the capacity, so blocks above the count exit without writing — that is what makes a class expressible.tests/hrx-loom-jit-test.cpp:1478already runs a reuse case that compilesggml_get_rows_f32at capacity 8 and serves token counts 3 and 7 from that one program.Cost, not just tidiness:
kernel_executable_keywalksdispatch.kernel.compile_parameters(runtime/kernel-executable-cache.cpp:84-105), so pinning the exact count compiles one program per prompt length. The class form gives ~11 programs for the whole 1..2048 range the config declares.The change
ubatch-token-limits.h—token_capacity_class()moves here fromdispatch-rope-set-rows.cpp, along with the rule it implements; rope calls it unchanged, so the two callers now share one definition instead of two.dispatch-get-rows.cpp—add_common_compile_parameterstakes an explicitcapacity_classargument, with no default, so each of its four call sites states its choice: the plain gather,ggml_get_rows_f32_nextand theget_rows_scale_f32fusion take the class and also declareDynamic(the axis and the class are the same statement);hidden_capacitystays exact everywhere, because it is constant per tensor and an exact value costs no extra compile.Every producer goes through the choice:
grep -rn ggml.get_rows_f32.token_capacity ggml/srcanswers one line —dispatch-get-rows.cpp:523, inside this helper — so the five get_rows dispatch constructors cannot disagree with each other the way the five matchers did about the axis.The one call site that must not take the class is the rmsnorm fusion —
get_rows_rmsnorm_binary_q8_1_x4_f16.loom:24assumeseq, notle. A class there would be a JIT refusal at run time, which is a hard failure where a decline would have been a CPU fallback — the rule the decode-split matcher's own comment states. That is why the argument has no default: the safe-looking version of this change, applied to the shared helper, would have taken the whole rmsnorm fusion out.The arm — device-free, so CI runs it
tests/hrx-backend-test.cpphas a host tier that schedules a graph withimport_ggml_graph+DispatchScheduler::schedule_graph(imported.graph, test_dispatch_target())and reads the plan without a device. New hostcase
get_rows_token_capacity_class:It schedules
ggml_get_rowsat token_count 6 — deliberately not a power of two, because pinning the count is exactly thedefect and a power-of-two count could pass by coincidence — and requires
token_capacity == "8"(the class),hidden_capacity == "256"(still exact),workload_specialization == Dynamic, andinteger_parameters["token_count"] == 6(so the class did not pin the shape somewhere else instead).
Mutation-proven, both halves at once (exact count restored,
Dynamicdeclaration removed):Checked first that the add-on cannot take this shape, so the arm is valid in CI's add-on build too: every
GGML_OP_GET_ROWSregistration in the add-on (
gk-pinned) is a fused graph matcher (glm-moe, dflash-select, gptoss-attn, zaya-router,qsa-pool-blocks) — none is a plain 2-D gather.
One rider, labelled: this file did not build at the base
tests/hrx-backend-test.cpp:368has calledmoe_router_descriptor_layout(expert_count)sincea7fd21ac9(fork #438,engine#2861) added the consumer-layout argument, so the whole
hrx-backend-testtarget — 100 host cases, 14 device cases,and both of its ctest rows — has not compiled at the pinned fork since then, and nothing reported it: the rows carry
LABELS "hrx"while the workflows runctest -L main. Filed as engine#3129 with the measurement. The arm above could notrun without it, which is why it is here rather than in its own PR; it is one hunk and splits cleanly if the owner prefers.
Measurement
Same ticket as ggml-org#3123's arm. The rows this issue is about (
get_rows_f32.*, before: 10 failed on:6207) plus every rmsnorm row — the fusion above is the regression this change can cause, so it is measured in the same run rather than assumed.Measured results are filled in below before this PR leaves draft.