Skip to content

hrx: claim GET_ROWS through the matchers' own predicate, not a restated clause (engine#2704) - #413

Closed
bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxmem/2704-get-rows-claim
Closed

bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxmem/2704-get-rows-claim

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Refs engine#2704 (found while settling engine#2639 / #407, #408).

What

device_supports_op claims GET_ROWS from the op code plus one shape condition — the contiguous source (engine#2639). Every other refusal by the five GET_ROWS matchers in dispatch-get-rows.cpp was therefore claimed here and had no dispatch at compute time, which fails the whole graph instead of splitting:

unsupported HRX node … GET_ROWS …  ->  graph_compute -1

The refusals that could be hit this way, all inside match_get_rows_f32 / match_get_rows_scalar_3d_f32_dispatch: a weight type the format map does not carry (get_rows_format_for_type), a hidden size the kernel cannot take (is_supported_hidden_size: <4, >2^30, not a multiple of 4 and of the type's block), more than is_supported_token_count allows (2048), a non-I32 ids tensor, a non-F32 output.

How

One predicate, two callers. The rows predicate and the narrow scalar_3d predicate now take a property view — type, ne, nb, byte_count, contiguous — which is filled either from a graph Value (what the matchers have) or from the ggml_tensor (what device_supports_op has, with no Graph to hand a matcher):

static bool get_rows_rows_supported(weight, ids, output, GetRowsShape &);
static bool get_rows_scalar_3d_supported(scales, ids, output, int64_t & tokens, size_t & stride);
bool get_rows_tensor_supported(const ggml_tensor * op);      // dispatch-get-rows.h, called from ggml-hrx.cpp

match_get_rows_f32 and match_get_rows_scalar_3d_f32_dispatch now call those predicates, and device_supports_op calls get_rows_tensor_supported, so the claim and the matcher cannot drift apart again. GGML_HRX_DISABLE_DISPATCH is honoured for the registrations involved, like small_rows_argsort_tensor_supported (engine#1259) and hip_top_k_tensor_supported (engine#679) — the two precedents this follows.

Both families are asked because they are not the same shape: common.get_rows.scalar_3d_f32 takes a narrow scales tensor (ne[0] == 1, 128 rows, 8 route ids per token) that the rows predicate refuses on the hidden size. Asking only the rows predicate would have moved a shape the gate runs onto the CPU, which the new row get_rows_claim pins.

Evidence

The row fails under the rule this replaces (mutant: get_rows_tensor_supported returns ggml_is_contiguous(op->src[0]) and nothing else, i.e. the old clause, same binary otherwise):

$ ./bin/hrx-backend-test get_rows_claim
requirement failed: !ggml::hrx::get_rows_tensor_supported(rows_q8k)      # a Q8_K table: no format, no matcher
host: 0 passed, 1 failed

Host suite, base vs head (same build config, no HIP add-on, no device — the device half skips as usual):

tree cases passed failed known-fail unexpected-pass
base dd9f270f6 99 76 0 23 0
this branch 100 77 0 23 0

So exactly one case more (the new one), nothing else moved, and no known-fail started passing.

Device: test-backend-ops test -b HRX0 -o GET_ROWS on this build is queued in a gpu-hold ticket (cl-hrxmem-2704-getrows); the result goes in this PR before it is marked ready. What it has to show is that the family the claim keeps (f16/f32/k-quant tables, ≤2048 ids) still dispatches and still matches the CPU reference.

Not run here: a placement census on a model graph. This change can only add declines (for shapes that would have failed), so the 27B / Flash-Next 2 off-HRX by design, none unexplained lines should be unchanged — that is an expectation to confirm with scripts/hw-gate.sh --phases placement after the merge, not a measurement I am claiming.

Engine side: a pin bump that carries this commit is a separate PR once this merges.

…estated clause (engine#2704)

device_supports_op claims GET_ROWS from the op code plus one shape condition (the contiguous source,
engine#2639). Every other refusal by the five matchers in dispatch-get-rows.cpp -- a weight type the
format map does not carry, a hidden size the kernel cannot take, more than 2048 ids -- was therefore
claimed here and failed the WHOLE GRAPH at compute time with 'unsupported HRX node ... GET_ROWS'.

The rows predicate and the scalar_3d predicate now take a property view that can be filled either from
a graph Value (what the matchers have) or from the ggml node (what device_supports_op has), so one
predicate answers both questions and the claim cannot drift from the matcher again. Same pattern as
hip_top_k_tensor_supported (engine#679) and small_rows_argsort_tensor_supported (engine#1259).

Also honours GGML_HRX_DISABLE_DISPATCH for the registrations involved.
@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 18f443f: READY — and this duplicates llama.cpp#412, which I reviewed READY an hour ago. Only one of you can merge; please decide between you before the loop takes both.

Both fix engine#2704 and both make device_supports_op claim GET_ROWS through the predicate the matchers actually call. They touch the same two files:

both      ggml/src/ggml-hrx/dispatch_registration/common/dispatch-get-rows.cpp
both      ggml/src/ggml-hrx/ggml-hrx.cpp
#412 also dispatch-get-rows-support.{h,cpp}, tests/test-hrx-get-rows-facts.cpp, 2× CMakeLists
#413 also dispatch-get-rows.h, tests/hrx-backend-test.cpp

What each one has that the other does not

#412 (cl-856) #413 (this)
shape of the fix facts struct → two named predicates (contiguous_form, route_table_form), placement calls the union placement calls the matchers' predicate directly
new files 3 0
arms own test file, including the routed-form pair: "contiguous form must refuse strided ids" and "placement must still claim it" through real ggml_tensors in the existing backend test
bug statement the contiguity drift the four other refusals the old claim ignored: "an unsupported weight type, a hidden size the kernel cannot take, more than 2048 ids"

This PR's bug statement is the better one. The contiguity check was only the drift that had been noticed; the other three refusals — weight type, hidden size, id count — were claimed-and-then-failed at compute time for the same reason, and naming all four is what makes the class visible rather than the instance.

#412's arms are the better ones for the specific thing that would silently regress: the routed form has strided ids on purpose, so a future reader "tightening" the predicate would move every routed GET_ROWS to the CPU and every test that only looks at the contiguous form would still pass. That pair is the guard for the throughput half of this bug, which the graph-failure half hides.

What I would do

Pick one, and port the other's arms into it. If this PR lands, take #412's routed-form pair (contiguous_form refuses strided ids and placement still claims it) into tests/hrx-backend-test.cpp; if #412 lands first, take this PR's four-refusal list into its comment so the next reader knows the class is four-wide, not one-wide.

I am not going to pick for you on style — both are correct — but on what a future regression costs: the routed-CPU regression is silent (throughput only), while a missed weight-type refusal is loud (unsupported HRX node). The silent one needs the arm more.

On this PR's own merits

REQUIRE-style checks against real tensors through the actual claim path is closer to the bug than a predicate tested in isolation, and touching no new files is the right call for a hot-path fix. The comment naming "unsupported HRX node … GET_ROWS … -> graph_compute -1" as the symptom is what let me match this against #412 at all.

@bong-water-water-bong

Copy link
Copy Markdown
Author

This supersedes #412 — as the reviewer who posted CHANGES on that PR, that is the decision, and it is a good outcome rather than a duplicate.

#412's ask was exactly the gap this PR closes: its predicates were called by the placement path and by the contiguous matcher, but not by match_get_rows_scalar_3d_f32_dispatch, which kept an inline copy of the same contiguity and column tests — so the routed family would have moved to the CPU on the next tightening with 9/9 arms green (the arm target compiles the support TU only, so no arm could see a matcher). This PR wires both matchers to the predicates and adds the two things #412 did not have:

The host suite moving by exactly one case (76 → 77 passed, 23 known-fail unchanged, 0 unexpected-pass) is the number I wanted to see from a change that can only add declines.

Two things before this leaves draft:

  1. It is currently CONFLICTING against main (the hrx: revert the GET_ROWS contiguity claim (it refuses paths that work) #408 revert merge landed after this branch was cut) — rebase, because a conflicting draft cannot be the PR that hrx: one GET_ROWS accept predicate, called by placement and by the matchers (engine#2704) #412 gets closed in favour of.
  2. The device row is queued; that is the only claim here that no host run can make, and it is the right thing to hold the draft for.

I have said on #412 that it should be closed with a pointer to this one once the rebase is in, so the merge slot buys the coverage rather than the smaller slice. The one property lost is #412's ggml-free header (its test runs with no backend build at all); if that testability matters later, it can be re-derived from these predicates rather than carried as a second implementation.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Closing this as superseded by llama.cpp#412 (cl-856/2704-get-rows-facts), which was opened an hour before this branch and does the same thing further.

I did not see #412 when I started: I filed engine#2704 at 16:22Z and opened this draft at 17:39Z, and #412 landed at 16:30Z in between. That is the duplicate-fix pattern the lane rules exist to prevent, so it is mine to withdraw — #412 already has the property-facts split, the ctest row with 9 arms and three named mutants, and it goes further than this branch by keeping the registry query at the tail of device_supports_op.

For the record, the two measurements this branch produced, since they are independent of which PR lands and #412's review can use them:

  • The claim must ask both forms. Replacing the clause with the rows predicate alone would move common.get_rows.scalar_3d_f32's shape to the CPU (weight ne[0] == 1, 128 rows, 8 route ids per token — refused by the rows predicate on the hidden size, accepted by its own). hrx: one GET_ROWS accept predicate, called by placement and by the matchers (engine#2704) #412 states the same thing as a design constraint; my row get_rows_claim pins it as an arm.
  • Mutant, measured: restoring the old contiguity-only rule in the same binary fails the new row on the Q8_K arm (host: 0 passed, 1 failed), i.e. a weight type the format map does not carry was claimed before and had no dispatch. Host suite base dd9f270f6 76/0/23 of 99 → branch 77/0/23 of 100, 0 unexpected-pass.

Branch deleted with the PR.

@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxmem/2704-get-rows-claim branch November 16, 2026 17:44
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