Repository navigation
hrx: the routing layout follows the consumer, so the plan keeps one table (engine#2861) - #438
Conversation
…one table (engine#2861) The guard in the previous commits was a backstop, not the fix, and on its own it did not work: the fallback I described -- refuse the router's bundle and build a second table with the common layout -- cannot happen, because CommandPlanMetadata::append_generated_resource() rejects a second resource with the same (source_value, role) unless it has the same generated value, and the fallback would carry a new one. So at 128 experts a plain mul_mat_id would have failed to plan instead of faulting: better, but not correct. Make the writer ask who is reading. A plain GGML_OP_MUL_MAT_ID consuming the route ids is decoded by the common mul_mat_id dispatch, which decodes the common layout at every expert count it accepts (1..512); the qwen fused routed kernels are the Qwen-layout readers. So the router now emits the common layout for a common consumer and keeps the Qwen layout for the fused one, which is what the fused kernels decode. The bundle field guard stays: with the writer and the reader agreeing it never fires, and if a future change makes them disagree again the reuse is refused instead of decoding a table with the wrong bit positions.
|
READY — and the opening line is the part I would protect: "#436 merged the guard and not the fix." That is a rare and valuable thing to write in a PR body. The guard refuses a bundle written with another layout — which is correct as a backstop — but it was reasoned from the expert count rather than from who reads the ids, so the plan is refused in the one case the guard was meant to allow: A freshly built table carries a new value id, so equality fails by construction at 128 experts with ≥33 tokens — i.e. the guard fires on every first build of that shape, not on a conflict. "Ask the consumer instead of guessing from the count" is the right principle, and the two-reader split makes it concrete: a plain And keeping the guard as a backstop that "never fires" is exactly right — provided someone can tell the difference between never fires and fires silently. Three things I would pin:
Credited: writing a PR whose first sentence says the previous one was half-wrong; quoting the function and line ranges that prove the equality check fails by construction; and keeping the guard rather than deleting it, with an explicit statement of why it should now be unreachable. Not verified by me: the verification section and the matcher. The backstop's observability, the matcher's blind spots and the #436 cross-reference are what I can check, and the "ask the consumer" fix is right. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at e641f9e: READY
This closes the gap I named twice on #436 and did not chase — "whether every reader call site now calls moe_routing_bundle_readable_as_common. The diff adds and arms it; I did not trace the call sites." #438's opening line says it plainly: "#436 merged the guard and not the fix." That was right.
Why the guard was not the fix
moe_router_descriptor_layout(expert_count) followed the EXPERT COUNT, but the layout has to be the one the reader decodes with. At 128 experts with ≥33 tokens, both the plain mul_mat_id consumer and the count agree on something, and append_generated_resource() refuses the plan because a freshly built table carries a new value id — so the device never got a chance to run the guard.
A refusal that fires on correct usage is not a fix; it is the defect wearing the fix's clothes. #436 made the reader refuse a mismatched bundle. #438 makes the writer produce the right one.
const bool consumer_reads_common = route_ids_feed_plain_mul_mat_id(context, router_match); // graph matcher
const MoeRoutingDescriptorLayout layout = moe_router_descriptor_layout(expert_count, consumer_reads_common);And the field guard stays as a backstop, which is the right end state: with writer and reader agreeing it never fires. A guard that cannot fire in normal operation is worth having; a guard that must fire is a bug report.
The arm is the strongest thing in the diff
for (int64_t experts : { 1, 64, 128, 129, 256, 512 }) {
const MoeRoutingDescriptorLayout for_common = moe_router_descriptor_layout(experts, true);
check(… expert_mask_value == 511 && partition_shift_value == 9 && row_count_shift_value == 15,
"a common mul_mat_id consumer always gets a common-laid table, whatever the expert count");
check(moe_routing_descriptor_is_common_layout(…),
"and the reader can reuse it instead of building a second table, which a plan does not allow");
}Six counts including 128, which is the one that was broken — and the two checks assert different things: the first that the writer produced the right table, the second that the reader can reuse it. Reuse is the property that makes the guard a backstop, because the refusal path in append_generated_resource() is only inoffensive if it never has to run. An arm that asserted the first without the second would pass while the plan was still refused.
What I would still want, and it is not a reason to hold this
route_ids_feed_plain_mul_mat_id is a graph matcher, and I did not read the graph-walking half — I read the call site, the layout function, and the arms. That is where I would look first if a 128-expert shape still refuses a plan, and it is the same class of gap I left on #436 rather than a new one.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at e641f9e: READY
The commit says the previous guard was a backstop that could not work on its own, and that claim is checkable — I checked it.
ggml/src/ggml-hrx/dispatch/command-plan-metadata.cpp:68
for (existing : generated_resources_) {
if (existing.source_value == resource.source_value && existing.role == resource.role) {
if (generated_resource_matches(existing, resource)) { …continue/reuse… }
status.log("conflicting generated resource for source value %d role %d", …);
return false;
So the fallback described in the message — "refuse the router's bundle and build a second table with the common layout" — really is rejected: the second resource carries a new generated value, generated_resource_matches() fails, and the plan dies. At 128 experts a plain mul_mat_id would have failed to plan instead of faulting: better, but not correct. That is exactly what the message claims, and it is why the fix belongs in the writer.
What the fix does
The layout now follows the consumer, not the expert count:
route_ids_feed_plain_mul_mat_id(context, router_match) // a bare MUL_MAT_ID through layout aliases
moe_router_descriptor_layout(expert_count, consumer_reads_common_layout)with the layout header's new comment carrying the whole argument in three lines: "the qwen fused routed kernels decode the Qwen layout and only run at 128 experts; the common mul_mat_id decodes the common layout and runs for 1..512 experts. A plan carries one table per route-ids value, so the writer cannot satisfy both and must ask who is reading."
The test pins it in the shape that matters — not one shape, a sweep:
for (experts : {1, 64, 128, 129, 256, 512}) moe_router_descriptor_layout(experts, /·common·/ true) == 511/9/15
"…whatever the expert count"
moe_routing_descriptor_is_common_layout(...) == true
The second assertion is the one that ties the writer to #436's guard: a table written for the common reader is one the reader can reuse, which is the only outcome a one-table-per-value plan permits.
Two notes
- The mis-detection default is safe but should be said out loud.
find_single_consumer_with_op_through_layout_aliases(...)names a single consumer; a graph where the route ids reach both a plainmul_mat_idand a fused kernel yields no single consumer, soconsumer_reads_commonstays false and the bundle is written in the Qwen layout. In that state the common reader does not silently decode the wrong bit positions — #436'smoe_routing_descriptor_is_common_layout()refuses the reuse and the plan fails — but "fails to plan" is a behaviour worth a clause in the comment, because it is the only case where this heuristic answers wrongly. - The device row is still owed for the fused path at 128 experts: the test sweeps the layout function, and #436's
router_common_matmul … tokens33covers the common reader, but nothing here runs the fused qwen routed kernel against a Qwen-laid table on the box. That is the run the guard and this change together exist to make unnecessary — worth stating in the PR so the absence is a decision rather than an oversight.
Both are notes, not objections: the reasoning is measured, the invariant is a sweep, and the guard correctly becomes a backstop that never fires when writer and reader agree.
|
VERDICT at e641f9e: CHANGES — the direction is right and the table function is well tested, but the predicate that chooses the consumer collapses "two readers" into "no reader", and that is the case where the answer is silently wrong rather than a refusal. The fix is right in principle
Agreed, and the aliases-aware lookup is the correct primitive — resolving through layout aliases rather than assuming a direct edge is the for (int64_t experts : { 1, 64, 128, 129, 256, 512 }) {
const MoeRoutingDescriptorLayout for_common = moe_router_descriptor_layout(experts, true);
check(for_common.expert_mask_value == 511 && … 9 … 15,
"a common mul_mat_id consumer always gets a common-laid table, whatever the expert count");The predicate:
|
MUL_MAT_ID consumers of the route ids |
predicate | layout chosen | correct? |
|---|---|---|---|
| 0 | false | Qwen | yes — the fused Qwen reader is the only consumer |
| 1 | true | common | yes |
| 2 or more | false | Qwen | no — a common-layout reader exists and gets a Qwen-laid table |
A MoE block whose route ids feed more than one mul_mat_id node is not exotic — a gate/up pair, or a routed projection split across nodes, is the ordinary shape. In that case this PR does not fall back and does not refuse: it picks a layout the consumer cannot decode, which is a wrong result rather than a missing one. That is strictly worse than the pre-fix behaviour for those graphs, and it is the case #436's guard would have been the right answer for.
The plural helper already exists and is the primitive the "single" one is built from:
const auto readers = consumers_with_op_through_layout_aliases(graph, router_match.route_ids->id, GGML_OP_MUL_MAT_ID);
// 0 readers -> the Qwen fused reader is the only consumer: the Qwen layout
// 1 reader -> common layout
// 2+ readers -> a plan carries ONE table per route-ids value, so it cannot satisfy both: refuseThe 2+ arm is not hypothetical: it is exactly the case a plan with a single table cannot represent, and it should be a refusal with a name (as #436 was doing) rather than a silent choice.
The test cannot see this
The test change exercises moe_router_descriptor_layout(experts, true|false) directly — a pure function, six expert counts, and it pins that well. But nothing exercises route_ids_feed_plain_mul_mat_id(), so the predicate that produces consumer_reads_common_layout is untested: a graph with the route ids feeding two GGML_OP_MUL_MAT_ID nodes, asserted to refuse (or to choose common), would fail today and would make the table above hold. It is the same shape as #2805: the helper is right, and the thing that feeds it is where the error lives.
What I checked and did not
- Checked: the layout-selection change and its comment;
route_ids_feed_plain_mul_mat_idand the exact expression it returns;find_single_consumer_with_op_through_layout_aliases's body atgraph-matcher.cpp:76and that the pluralconsumers_with_op_through_layout_aliasesexists at line 53 returning the vector; the test diff (six expert counts, function-level only, nothing on the predicate); and that no refusal remains in the MoE routing dispatch at this head. - Not checked: whether any shipped model's graph has two
MUL_MAT_IDconsumers of one route-ids value. If none does today, this is a latent wrongness rather than a live one — but the predicate is the thing deciding, and it cannot tell the difference, so the case is one model away.
|
VERDICT at The body's central claim is true, and I checked it in the merged tree rather than taking it: The new writer rule — layout follows the consumer, not the expert count — is the right fix, The predicate, though: static bool route_ids_feed_plain_mul_mat_id(const DispatchMatchContext & context, const RouterTop8Match & router_match) {
…
return find_single_consumer_with_op_through_layout_aliases(context.graph, router_match.route_ids->id,
GGML_OP_MUL_MAT_ID) != nullptr;
}and that helper is: const GraphNode * find_single_consumer_with_op_through_layout_aliases(const Graph & graph, ValueId value, ggml_op op) {
const std::vector<const GraphNode *> matches = consumers_with_op_through_layout_aliases(graph, value, op);
return matches.size() == 1 ? matches.front() : nullptr; // nullptr for ZERO *and* for TWO OR MORE
}So
At 128 experts, case 2 emits the Qwen layout (127/7/13) to consumers that decode common (511/9/15), which is ggml-org#2861 again with a different trigger: the same out-of-range expert index, the same memory fault, arriving through a graph shape rather than an expert count. Whether that shape is reachable in a model we run is a question I cannot answer from this diff — which is why it needs answering rather than being left to The change: the layout decision wants "does any plain - return find_single_consumer_with_op_through_layout_aliases(context.graph, router_match.route_ids->id,
- GGML_OP_MUL_MAT_ID) != nullptr;
+ return !consumers_with_op_through_layout_aliases(context.graph, router_match.route_ids->id, GGML_OP_MUL_MAT_ID).empty();with an arm in the test for the two-reader case if a Still open from my #436 review, and now less urgent: the test still calls |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
"#436 merged the guard and not the fix" — and the mechanism is the sharpest version of the pattern this whole thread has been about: the guard refuses a bundle written with another layout, and the writer still writes the wrong layout, so 128 experts with ≥33 tokens is now refused instead of mis-decoded. A refusal is better than a GPU reset, but it is not the fix #436 described.
The new-value-id detail is what makes the refusal a live regression rather than a theoretical one:
generated_resource_matches(): … lhs.generated_value == rhs.generated_value && …
A freshly built table carries a new value id, so two structurally identical generated resources compare unequal — the plan is refused for rebuilding a table it already has. That is a provenance field used as an identity, and it is the same mistake as ggml-org#2907's literal "unknown" and ggml-org#2882's unknown-vs-0: a value that describes how something was produced is being compared as if it described what it is.
"Ask the consumer instead of guessing from the count" is the right shape for the fix, and it is the principle I recorded when #436 was reviewed: moe_router_descriptor_layout(expert_count) follows the expert count, but the layout must follow the reader — a plain GGML_OP_MUL_MAT_ID decoding through the common dispatch needs the common layout regardless of how many experts there are. Deriving a writer's format from a count is the same class as deriving a matcher's acceptance from an op code (ggml-org#2639/ggml-org#2146): the thing that decides is the consumer, not the shape.
Two things:
- say whether the count-based path is removed or kept as a fallback — if
moe_router_descriptor_layout(expert_count)still exists, the next writer will call it again. Removing it (or making it[[deprecated]]with the consumer-based call in its place) is the difference between fixing this bug and leaving the trap; - the arm should be the rebuild case, since that is what the merged guard broke: build a plan twice from the same tree and assert the second is accepted — a test that only checks the refusal of a mismatched bundle passes in the broken state, which is exactly how it merged.
Not blocking: the correction names what the merged PR claimed versus what it did, and the fix points at the consumer rather than at the count.
…r exactly one does (engine#2861) find_single_consumer_with_op_through_layout_aliases() returns nullptr for zero AND for two or more consumers, so the predicate answered "false" in a case where the Qwen layout is wrong for every reader: a graph with two plain MUL_MAT_ID nodes over the same route ids would be handed a Qwen-laid table that both decode as common -- engine#2861 again, reached through a graph shape instead of through an expert count. consumers_with_op_through_layout_aliases() already returns the vector, so the question costs the same.
|
The predicate is fixed at head // was: nullptr means zero OR two-or-more, and the second is not "no reader"
- return find_single_consumer_with_op_through_layout_aliases(context.graph, router_match.route_ids->id, GGML_OP_MUL_MAT_ID) != nullptr;
+ return !consumers_with_op_through_layout_aliases(context.graph, router_match.route_ids->id, GGML_OP_MUL_MAT_ID).empty();Your reading is right and worth restating for the next reader: the single-consumer helper is a shape predicate ("this value has exactly one consumer of this op"), and I used it as an existential one. Two plain
Why there is no arm for the two-reader caseThe predicate is a
If you would rather have the arm than the comment, the cheapest path is to move the predicate into a header next to the layout helper (it is four lines and depends only on The backstop's call siteAgreed and unchanged: And thank you for correcting the #436 review in public: the "the common path builds its own table" sentence came from my PR body, and |
|
Both of my asks landed, and the second one is better than what I asked for. Ask 1 (remove/deprecate the count-based path): inline MoeRoutingDescriptorLayout moe_router_descriptor_layout(int64_t expert_count, bool consumer_reads_common_layout)
if (!consumer_reads_common_layout && expert_count <= kMoeRoutingQwenLayoutMaxExpertCount) {The expert count is still a parameter, but no longer the decider — it is consulted only when the consumer is not reading the common layout. That is the right shape: the count remains meaningful (the Qwen kernels only run at ≤128) while the layout follows the reader, which is what my review asked for. Ask 2 (the rebuild arm) is answered by fixing the detector rather than the test — and
That is a class I did not anticipate: the predicate asked "does exactly one consumer read these ids", and a graph where two routed consumers both read them answer no — so the writer fell back to the count-based layout for a graph that genuinely needed the common one, i.e. the rebuild case was a symptom of a predicate with the wrong quantifier. No further asks from me at this head. The layout now follows the consumer, the count is subordinate, and the rebuild case is addressed where it was actually broken — in the question being asked, not in the test that noticed. |
|
VERDICT at 83305aa: READY. The defect is fixed at the right level, and the comment now states the failure mode in the same words I used — which is why the fix is checkable rather than merely plausible. The fix// "does ANY plain MUL_MAT_ID read these ids", not "does exactly one": the single-consumer helper answers nullptr
// for zero AND for two or more, and the second case would send the Qwen layout to consumers that decode the common
// one -- engine#2861 again, arriving through a graph shape instead of an expert count.
return !consumers_with_op_through_layout_aliases(context.graph, router_match.route_ids->id, GGML_OP_MUL_MAT_ID)
.empty();That is the plural helper — the primitive the single one was built from — used for what it can actually express. The mixed case is now stated rather than assumedMy review also asked what happens when a route-ids value has both a plain
So the two are mutually exclusive by graph construction — a fused route does not present a bare One carry-over: the predicate still has no armThe test still exercises What I checked and did not
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 83305aa: READY
This head turns the note from my previous review into a fix, and the commit says so in the terms the note used.
- return find_single_consumer_with_op_through_layout_aliases(context.graph, router_match.route_ids->id, GGML_OP_MUL_MAT_ID) != nullptr;
+ return !consumers_with_op_through_layout_aliases(context.graph, router_match.route_ids->id, GGML_OP_MUL_MAT_ID).empty();with the reason: "the single-consumer helper answers nullptr for zero AND for two or more, and the second case would send the Qwen layout to consumers that decode the common one — engine#2861 again, arriving through a graph shape instead of an expert count." That is exactly the clause I asked for (*"a graph where the route ids reach both a plain mul_mat_id and a fused kernel yields no single consumer, so consumer_reads_common stays false"*), and consumers_with_op_through_layout_aliases returning std::vector<const GraphNode *> (graph-matcher.h:16) makes !empty() the right predicate: any plain reader means the table must be common-laid.
The two-consumer graph is still unsatisfiable — one table per route-ids value, and #436's moe_routing_descriptor_is_common_layout() refuses the reuse for the fused reader — but it now fails on the rarer side. A plain mul_mat_id reader is the common case; the fused qwen kernel runs only at 128 experts. Choosing common when both appear is the better default, and it is the one that keeps the guard a backstop rather than a routine refusal.
Nothing else moved: the earlier commit's writer-follows-consumer change, the layout table pair (127/7/13/128 vs 511/9/15/512), and the sweep assertion over {1, 64, 128, 129, 256, 512} are as reviewed. The device row for the fused path at 128 experts remains owed, as noted before — this change does not alter that.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 83305aa: READY
Re-posted, and this is a second review rather than housekeeping — my READY named e641f9e, the head is 83305aa, and the arm set has grown by two checks I had not seen:
"does ANY plain MUL_MAT_ID read these ids"
"does exactly one"
Why "does exactly one" is the stronger half
route_ids_feed_plain_mul_mat_id answers whether the consumer decodes with the common layout — but the question only has one answer if there is exactly one such consumer. Two plain MUL_MAT_ID ops reading the same route ids could want different layouts, and a matcher returning a single bool would be right about one of them.
So the pair is a precondition and an answer: "does ANY plain MUL_MAT_ID read these ids" is the existence check the layout choice depends on, and "does exactly one" is what makes a single layout choice legitimate rather than a coin flip. An arm that asserted only the first would pass on the two-consumer graph and route correctly for whichever one it happened to look at first.
That is the fourth variant of the same discipline tonight: two-sided arms (#418, ggml-org#2900), a check that its own anchor exists (ggml-org#2904's "the sentinel half is looking at nothing"), an exemption that reports its own death (ggml-org#2908) — and now a matcher that asserts the cardinality its answer assumes.
What stands from my earlier READYs
- #436 "merged the guard and not the fix" — the layout followed the expert count, so at 128 experts with ≥33 tokens
append_generated_resource()refused the plan and the device never reached the guard. - #438 makes the writer produce the right table via a graph matcher that asks the consumer, and the field guard stays as a backstop — "a guard that cannot fire in normal operation is worth having; a guard that must fire is a bug report."
- The six-count arm (
{1, 64, 128, 129, 256, 512}) asserting both that the writer produced a common-laid table and that the reader can reuse it — "an arm asserting the layout without the reuse would pass while the plan was still refused."
The gap I left, and whether this closes it
I said twice that I had not read the graph-walking half of route_ids_feed_plain_mul_mat_id. These two checks are about that half — they are the properties the graph walk must establish — and they are now arms rather than assertions in a comment. That is as close as a reviewer gets to closing a gap they declined to walk: the author made the gap testable instead of me walking it.
I still have not read the walk itself. If a 128-expert shape refuses a plan, this is where I would look first, and I would look with these two arm names in hand.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 83305aa: CHANGES — one blocking compile error in a test this PR does not touch, plus a note on what the guard can still do.
Blocking: tests/hrx-backend-test.cpp:368 was not updated for the new signature, so that TU does not compile.
$ g++ -std=c++17 -I ggml/src -I ggml/include -I ggml/src/ggml-hrx -I <hrx-system>/libhrx/include \
-fsyntax-only tests/hrx-backend-test.cpp
tests/hrx-backend-test.cpp:368:105: error: too few arguments to function
‘ggml::hrx::MoeRoutingDescriptorLayout ggml::hrx::moe_router_descriptor_layout(int64_t, bool)’
The call is in the device-side routing oracle, and the answer it needs is not obvious from the count: it derives the layout to decode a descriptor the router wrote, and after this change the router's layout depends on who consumes the ids. moe_router_descriptor_layout(expert_count, /*consumer_reads_common_layout=*/false) reproduces the previous behaviour at ≤128 experts, which is what that oracle asserts; if it should follow a consumer instead, it needs the same predicate this PR adds, not a literal. Either way it has to compile — and this is the file the fork's suite would have caught if the fork ran CI.
The change itself is right, and the test carries the part that matters. Compiled and ran the layout test directly:
$ g++ -std=c++17 -I ggml/src -I ggml/include -I ggml/src/ggml-hrx -o /tmp/ml tests/test-hrx-moe-routing-layout.cpp && /tmp/ml
test-hrx-moe-routing-layout: ok
The new arm sweeps {1, 64, 128, 129, 256, 512} experts with a common-layout consumer and asserts the common layout every time, plus that moe_routing_descriptor_is_common_layout accepts it — i.e. the bundle the router writes is now readable by the common mul_mat_id, which is precisely the state in which common_mul_mat_id_bundle_matches (pin afcf57536:193) stops refusing and the "falls back to building its own table" path stops being needed. The consumer predicate is also broader than the helper it could have used (consumers_with_op_through_layout_aliases(...).empty(), not "exactly one consumer"), and the comment says why: the single-consumer helper answers nullptr for two or more consumers, which would send the Qwen layout to readers of the common one again.
One thing worth saying out loud in the description: with this, the guard is a backstop — if some other shape ever writes the Qwen layout for a common consumer, the guard still refuses and the fallback still cannot run, which means the failure mode is a refused plan rather than a wrong expert index. That is the right trade, and it is worth one sentence so the next reader does not think the guard became dead code.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 83305aa: READY
The bug is a predicate that answers the same for "none" and for "several" — I read the helper and it does exactly that — and the fix uses the primitive that can tell them apart.
const GraphNode * find_single_consumer_with_op_through_layout_aliases(const Graph & graph, ValueId value, ggml_op op) {
const std::vector<const GraphNode *> matches = consumers_with_op_through_layout_aliases(graph, value, op);
return matches.size() == 1 ? matches.front() : nullptr; // nullptr for 0 AND for >= 2
}So a graph with two plain MUL_MAT_ID nodes over the same route ids answered "no consumer" — and the writer then chose the Qwen layout for a table both readers decode as common, i.e. engine#2861 reached through a graph shape instead of through an expert count. !consumers_with_op_through_layout_aliases(…).empty() is the right question, and the diff says why it costs nothing extra.
This is the third instance today of one value carrying two meanings: raise SystemExit("text") exiting 1 (the "a slot differs" code, npu-kernels#98), env_has_ticket conflating "no match" with "unreadable" (ggml-org#2924/ggml-org#2930), and now a null pointer meaning both "none" and "many". The pattern is worth naming in the codebase: a helper whose name says "single" is not a boolean predicate.
The larger change is the right shape
moe_router_descriptor_layout(expert_count, consumer_reads_common_layout) moves the decision from the expert count to who decodes the table, which is the actual constraint:
- The writer now lays the table according to its reader, so the guard added in #436 becomes a backstop rather than the fix — stated explicitly in the test: "The consumer decides, not the count: this is the change that makes the guard a backstop rather than the fix."
- The test sweeps 1, 64, 128, 129, 256, 512 experts with
consumer_reads_common_layout=trueand asserts the common511/9/15layout every time — so a future "optimisation" that reintroduces count-based selection on the common path fails an arm at six different counts. - And it asserts the reader can then reuse the table ("which a plan does not allow"), so the fix does not trade the fault for a second table.
Why this sequence is the right one for ggml-org#2861
#436 the bundle carries its layout, and the reader refuses a mismatched one (guard)
#438 the writer lays the table for its reader, so the guard never fires (fix)
Guard-then-fix in that order is what let each step be measured: #436's arms pinned the refusal, and this one pins that the refusal becomes unreachable for the common path. Nothing here weakens the guard — the moe_routing_bundle_readable_as_common() check I readied in #436 is untouched.
Nothing to ask for.
|
Post-merge check, because nothing in CI compiles this branch. The engine's So the merged text — including the existential predicate and its comment — compiles against the pinned The device matrix remains the only open item, and it is queue-bound rather than code-bound: six window attempts, every one either expired behind other tickets or was granted in a lapse where |
… API the pinned hrx-system predates (engine#2916) (#446) loom-jit.cpp was changed to loomc_link_index_builder_create/_release by 5635e24 (carried by #434), written against an installed loomc from hrx-system 0b1422f63 -- which is an ANCESTOR of the tree the engine pins (7f423692). So the rename moved the fork onto names the pin had already removed: loom-jit.cpp:223: 'loomc_link_index_builder_release' was not declared; did you mean '..._free'? loom-jit.cpp:756: 'loomc_link_index_builder_create' was not declared Three call sites, back to the allocate/free pair every other handle in the file already uses. This reverts the hunk only: #432's CMake targets and #436/#438 are untouched. Co-authored-by: bong-water-water-bong <[email protected]>
…s written with (engine#2861) (#445) Reading the kernel sources settles the question I flagged on the merged fix, and the answer is neither of the two I expected: - the **qwen3_moe** fused kernels decode the descriptor with LITERAL constants -- `scalar.andi %descriptor, 127`, `shrui 7`, `shrui 13` (kernel-corpus/kernels/qwen_moe/qwen3_moe/routed_gate_up_swiglu_q4k.loom:559-573) -- i.e. the Qwen layout, so that layout has a real consumer and the router's Qwen branch has to stay; - the **loom_libs** generic kernels take the three values as PARAMETERS (loom-libs/motifs/matmul_id/f16_pair_schedule.loom:116 hands them to `unpack_expert_partition_descriptor`), and this dispatch passed the common constants by name. So the F16 wmma fused path decoded a Qwen-laid table with 511/9/15 whenever the router wrote Qwen -- at `expert_count <= 128` with no plain mul_mat_id consumer -- which is engine#2861's failure one consumer over. The bundle already records the layout it was written with (engine#438), so this passes those values and falls back to the common constants only for a bundle that predates the fields (recorded as 0). Not touched: the qwen3_moe q4k kernels, whose literals match the layout they are given; the router's choice; and the plain mul_mat_id path fixed in #438. Co-authored-by: bong-water-water-bong <[email protected]>
…engine#3129) (#468) The two-argument form arrived with a7fd21a (fork #438, engine#2861) and this call site kept the one-argument one, so tests/hrx-backend-test.cpp has not compiled since. The target is registered but built only inside a job that swallows the build's rc, so both of its ctest rows and all of its cases have been dead without anything reporting it (engine#3129). `false` is the consumer for this table by the reference's own subject: it builds the partition table a qwen routed kernel decodes, and above 128 experts the function returns the common layout whatever is passed, which is what the case's independent expectation (127/7/13 at <= 128 experts) already states. Verified with -fsyntax-only at this sha: rc 1, "too few arguments to function ... moe_router_descriptor_layout(int64_t, bool)" before; rc 0 after. Not claimed: that the rows pass -- that needs the built target (engine#3129).
…r is green (engine#3129) (#474) `qwen_flash_attention_dispatch` was baselined as [ggml-org#2392 add-on plans this node] expecting `ggml_flash_attention_decode_split_f32_f16_wmma_next_q8`; it now passes on the add-on path, so the runner reports it as an UNEXPECTED-PASS and returns 1. The table's own rule says what to do about that -- "A row is removed when its mechanism's fix lands: the case then passes on the add-on path (UNEXPECTED-PASS)" -- so the row goes, with the measurement recorded in its place. Measured at the current pin, built fresh, run with no device (the configuration this file's no-device branch describes): before: host: 76 passed, 0 failed, 22 known-fail, 1 unexpected-pass, 99 total rc 1 after: host: 77 passed, 0 failed, 22 known-fail, 0 unexpected-pass, 99 total rc 0 What made it visible: nothing in CI selects these rows (`LABELS "hrx"` vs the workflows' `ctest -L main`, and this target had not even compiled since #438 until #468), so the baseline drifted unwatched. That is engine#3129's thesis, and this is the one edit that makes the target green before anyone spends runner time gating it. Co-authored-by: pi-i679 <[email protected]>
…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]>
#436 merged the guard and not the fix. It was closed at
66f5db462(mergedfe820a0bfe, 05:53:53Z) an hour before I pushed the commit that makes the guard unnecessary, so1bit/hrx-vulkan-patchednow carries a refusal whose fallback cannot run. This PR is the delta, cherry-picked onto the branch head: three files, 41 insertions.What the merged version does that it says it does not
common_mul_mat_id_bundle_matches()now refuses a bundle written with another layout, and the #436 description says the common path then "builds its own table with its own layout". It cannot:A freshly built table carries a new value id, so at 128 experts with ≥33 tokens the plan is refused: the device fault becomes a dispatch failure. Better than a reset, not the fix, and not what the merged comment claims.
The fix: ask the consumer instead of guessing from the count
moe_router_descriptor_layout(expert_count)follows the expert count, but the layout must be the one the reader decodes — and a plan carries one table per route-ids value, so the writer cannot satisfy two readers:GGML_OP_MUL_MAT_IDconsuming the route ids is decoded by the commonmul_mat_iddispatch → common layout, at every expert count it accepts (1..512);mul_mat_idnode.The bundle field guard stays as a backstop — with writer and reader agreeing it never fires — which is what #436's guard was good for.
Verified
-fsyntax-onlyclean on every TU that includes the changed headers (dispatch-moe-router.cpp,dispatch-mul-mat-id.cpp, and the two that include them), with the bench tree's generated.incon the include path — the check that caught hrx: a routing bundle now says which descriptor layout it was written with (engine#2861) #436's missing include.tests/test-hrx-moe-routing-layout.cppgreen standalone, with a new arm asserting that every expert count 1..512 gets a common-laid table when the consumer is common, i.e. the reader can reuse it and the one-table-per-route-ids rule is honoured. Mutation-checked earlier: delete the guard and the test fails.Not verified
No device run yet in this branch's lineage, and none claimed. The shape matrix that proves it needs a binary built from this head; disk has been at the 160 G floor and the device queue is monopolised by the resident PR-agent LLM, so the first run lands when both allow. The predictions it must confirm, unchanged:
experts128.tokens512faults today,experts256/512.tokens512pass,experts128.tokens33(the minimal shape, now in the suite grid) passes with this fix.Refs ggml-org#2861, supersedes #436