Skip to content

hrx: the routed GET_ROWS matcher asks the shared predicate too (engine#2704, follow-up to #412) - #414

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxmem/412-routed-matcher-predicate
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxmem/412-routed-matcher-predicate

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 16, 2026 •

Copy link
Copy Markdown

Follows llama.cpp#412 (engine#2704), which merged as 5450c8054. This branch is now based on that commit and targets 1bit/hrx-vulkan-patched directly (head 743704fb0); no stack, nothing to merge first.

What

#412 gave the placement path and match_get_rows_f32 one predicate, built from get_rows_tensor_facts. The routed form's matcher kept its own copy of the two conditions that predicate owns:

// match_get_rows_scalar_3d_f32_dispatch, before this commit
const bool has_contiguous_values = scales->contiguous && output->contiguous;
const bool has_id_columns = ids->nb[0] == sizeof(int32_t) && ids->nb[1] % sizeof(int32_t) == 0;

Those are exactly get_rows_route_table_form_supported's src_contiguous && out_contiguous && ids_column_table. So the one copy in the file that nothing compiled against the predicate was the routed one — the drift #412 exists to prevent, left in the half of the family that a conjunctive placement predicate would silently break.

This asks the predicate:

ggml::hrx::get_rows_tensor_facts facts;
facts.src_contiguous   = scales->contiguous;
facts.ids_contiguous   = ids->contiguous;
facts.ids_column_table = ids->nb[0] == sizeof(int32_t) && ids->nb[1] % sizeof(int32_t) == 0;
facts.out_contiguous   = output->contiguous;
facts.src_type         = static_cast<int32_t>(scales->type);
facts.src_ne2          = scales->ne[2];
facts.src_ne3          = scales->ne[3];
if (!ggml::hrx::get_rows_route_table_form_supported(facts)) return false;

The matcher-specific conditions stay where they were: the narrow scale/id/output shapes, is_supported_token_count, the exact id span and the route-stride bounds — these need the graph, which is the rule #412's header states.

Behaviour is unchanged by construction: the route-table form is src_contiguous && out_contiguous && ids_column_table plus the batched-IQ3_S rule, and that rule cannot fire for the GGML_TYPE_F32 scales this matcher requires (has_types still gates it). Nothing is added or removed from what the matcher accepts.

Measured

Same build config as #412's review run (fork head + no HIP add-on, no device):

$ ./bin/test-hrx-get-rows-facts
ok: 12 arms                     # was 9: three arms pin the routed form's own two conditions
$ ./bin/hrx-backend-test        # host half
host: 76 passed, 0 failed, 23 known-fail, 0 unexpected-pass, 99 total

The host suite is identical to #412's head and to the base tree (dd9f270f6), which is the point: this moves a condition, it does not change a decision.

Not run: device test-backend-ops -o GET_ROWS. The routed (scalar_3d) graph is a qwen3.6-35b routed-expert shape, so the honest device check is the hw-gate placement phase on that model after both PRs are pinned — the expectation being the same 2 off-HRX by design, none unexplained line, since no accepted shape changes.

Engine side: the pin bump that carries #412 carries this too.

@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 b41e06f: READY

This is the 5-line move the CHANGES on #412 asked for, placed exactly where it belongs, and I ran the arms. It also makes the "no decision changes" claim explainable rather than asserted.

What I ran

The predicate side compiles and runs with no device and no graph, so I could exercise the new arms directly:

$ g++ -std=c++17 -I ggml/include -I ggml/src/ggml-hrx tests/test-hrx-get-rows-facts.cpp \
      …/common/dispatch-get-rows-support.cpp  && ./a.out
ok: 12 arms

Why "a condition moves, no decision changes" is true here, not just stated

The one thing that could have moved a decision is the predicate's iq3s_batch_is_executable() conjunct, which the routed matcher did not previously apply. It cannot fire on this path: the matcher's own has_types requires scales->type == GGML_TYPE_F32, and facts.src_type = scales->type, so src_type == kGetRowsIq3sType is false by construction and the conjunct is vacuously true. That is worth having in the commit message, because the next reader of get_rows_route_table_form_supported will otherwise assume this PR tightened the routed form.

Everything else is where the review said it should be: the graph-shaped conditions (shapes, types, route_stride bounds, exact id span) stay in the matcher, and only the four tensor facts move behind the predicate.

Order: after #412, which is where this is stacked. #412 gets a READY that names this PR as its condition of merging, so the residual cannot be orphaned by a merge.

@bong-water-water-bong

bong-water-water-bong commented Nov 16, 2026 •

Copy link
Copy Markdown
Author

Pre-flight for the engine pin that will carry this pair, measured now so the bump is a two-line change and not a surprise: at fork b41e06f (this PR's head = #412 + the routed-matcher commit) the engine's own f16-narrowing ratchet passes unchanged.

$ git -C third_party/llama.cpp checkout b41e06f     # same worktree, engine tree at main's baselines
$ python3 tools/ci/hrx_f16_narrowing.py --check --root .
CORPUS       …/third_party/llama.cpp/ggml/src/ggml-hrx/kernel-corpus/kernels
FINGERPRINT  af73a19b122857bb (326 .loom file(s))
hrx_f16_narrowing: 84 narrowing body(ies), none new, none stale; 22 f16 accumulator body(ies), none new, none stale;
                   11 of the narrowing bodies carry a guard marker
rc=0

and the corpus itself is untouched between the current pin and this head:

$ git -C third_party/llama.cpp diff --stat dd9f270f6 b41e06f -- ggml/src/ggml-hrx/kernel-corpus
(no output)

So the bump needs the gitlink and the registry's source sha, and no tools/ci/hrx_f16_narrowing.txt line — unlike ggml-org#2692, which moved a baseline because #410 added a narrowing site. The gpu-kernels pin does not move with this pair. I will open that bump once both PRs are in the fork's main, and the expected device row there is the hw-gate placement phase unchanged (2 off-HRX by design, none unexplained) on 27B and 35B-A3B.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Rehearsed the landing this PR will actually get: #412 squash-merged onto current fork main (bb71f1be0), then this commit, and it applies clean, builds, and passes — with a five-shape check that the claim and the registry agree on the NEW base.

Two things changed under us since this PR was opened, and neither breaks it:

The rehearsal, run

$ git checkout -b rehearsal-414 origin/1bit/hrx-vulkan-patched      # bb71f1be0
$ git merge --no-ff origin/cl-856/2704-get-rows-facts                # clean, #412 as the loop will land it
$ git cherry-pick b41e06f                                            # clean -> f41c903
$ ./bin/test-hrx-get-rows-facts
ok: 12 arms
$ ./bin/hrx-backend-test                                             # host half
host: 76 passed, 0 failed, 23 known-fail, 0 unexpected-pass, 99 total     # identical to the base tree

And the property this pair exists for, re-measured on that base

can_execute_standalone_op_as_graph(op,"gfx1151") (what the tail of device_supports_op asks) against the placement predicate, on the rehearsal tree:

shape registry standalone placement predicate
q6_K table, 4 ids, f32 dest 1 1
same, f16 destination 0 0
routed (scalar_3d) shape, dest [1,8,2,1] 1 1
4096 ids 0 1
Q8_K source 0 1

The f16 row is the one that changed for me: on the earlier base the predicate said 1 for an f16 destination while the registry said 0; on this base it says 0, so the two agree. The last two rows are the intended asymmetry — the predicate is a veto, and the tail is what refuses a shape the facts cannot express (an over-long id list, a source type outside the format map).

Rehearsal branch deleted; nothing was pushed for it. This PR's head is unchanged (b41e06f), still stacked on #412, and it will not need a rebase when #412 lands.

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

This closes the sentence I could not accept in #412. #412 wired the contiguous form and left the route-table matcher with its own copy of has_contiguous_values / has_id_columns, so the claim "a condition cannot be in one caller and not the other" was true for one of the two forms. Here the last private copy in the file goes: facts built from the graph's values, get_rows_route_table_form_supported(facts) consulted, has_contiguous_values and has_id_columns deleted. has_output_shape && has_types remaining outside the predicate is correct, not an oversight — those are the matcher's shape/type questions that the facts struct genuinely does not carry, and the comment says so.

The bit that matters most is that the routed form keeps its deliberate strided ids. This is the form a conjunction would have broken: match_get_rows_scalar_3d_f32 reads ids through route_strided on purpose. Facts built with ids_contiguous = ids->contiguous (which is false for the route table) and then asked through the route predicate leaves it claimed — so the PR shares the condition without importing the contiguous form's requirement into the routed one. That is the distinction #412 established and this PR respects it, rather than collapsing two forms into one predicate for tidiness.

Two things I would want, both cheap:

  1. An arm that fails if the routed form's facts are built with the wrong predicate — i.e. call get_rows_contiguous_form_supported on route-table facts and assert false (it must decline, ids are strided), while get_rows_route_table_form_supported on the same facts asserts true. That pair is what stops a future "one predicate is simpler" refactor from silently moving every routed GET_ROWS to the CPU, and it is the exact mutation the family has already suffered once (#407).
  2. Say in the body that the three pre-facts locals are now dead by construction, not merely unused — has_contiguous_values, has_id_columns and the conjunction they fed were the drift surface, and "deleted rather than renamed" is the sentence a future reader needs when they wonder why the matcher no longer has an opinion about contiguity.

With #412 and this together, engine#2704's claim holds at both forms for the contiguity and id-column conditions — the four remaining conditions (output->type, the two is_2d questions, is_1d_or_2d_column) are still matcher-only, and that is the honest remainder rather than a silent one.

Base automatically changed from cl-856/2704-get-rows-facts to 1bit/hrx-vulkan-patched November 16, 2026 18:47
@bong-water-water-bong

Copy link
Copy Markdown
Author

#412 merged as 5450c8054, so this branch now shows #412's content as its own diff (+363/−31 over 7 files). The one-command fix, verified on a copy of your head:

$ git checkout <your branch>
$ git rebase --onto 5450c8054 2f5693b64      # drop #412's pre-squash commits, replay only yours
$ git push --force-with-lease

after which

$ git diff --stat 1bit/hrx-vulkan-patched HEAD
 .../common/dispatch-get-rows.cpp  | 20 +++++++++++++---
 tests/test-hrx-get-rows-facts.cpp | 25 +++++++++++++++++++++-
 2 files changed, 41 insertions(+), 4 deletions(-)

— one commit, two files, no conflicts, which is what this PR actually is. The 2f5693b64 in the command is #412's pre-squash head; everything up to and including it is now in the base.

Nothing about the change itself: my READY at 2f5693b-based head stands, and the routing argument is unchanged — the routed matcher asks get_rows_route_table_form_supported, and the one predicate conjunct it did not previously apply (iq3s_batch_is_executable) is vacuous there because has_types forces scales->type == F32. I will re-verdict at the rebased head; the arms I ran (ok: 12 arms) are unaffected by where the branch was cut from.

@bong-water-water-bong

Copy link
Copy Markdown
Author

The device row this PR listed as "not run" is now measured on this head, and it is green: test-backend-ops -o GET_ROWS on HRX0 passes 130/130, with the refusals landing exactly where the claim says they should.

Build: fork b41e06f (= #412 + this commit), no HIP add-on, git status clean. Run inside a gpu-hold ticket (cl-hrxmem-414-getrows), 4 s of device time, 0 amdgpu faults:

$ ./bin/test-backend-ops test -b HRX0 -o GET_ROWS
  …
  GET_ROWS(type=i32,n=256,m=5,r=4,be1=7,be2=1,v=1,vs0=0,offset_cols=0): OK
  GET_ROWS(type=i32,n=256,m=5,r=4,be1=7,be2=1,v=1,vs0=1,offset_cols=0): not supported [HRX0]
  GET_ROWS(type=f32,n=256,m=8,r=2,be1=1,be2=1,v=0,vs0=1,offset_cols=3): not supported [HRX0]
  130/130 tests passed
  Backend HRX0: OK
2/2 backends passed

and the rows that were not claimed, by source type (these are the graded skips test-backend-ops reports for an unsupported shape, not failures — zero FAIL/MISMATCH lines in the run):

      1 type=f32
      2 type=i32
      2 type=iq3_s      # the single-row IQ3_S kernels; the batched form is the #407 rule
      4 type=iq4_xs

That is the shape of a claim that is a veto and not an answer: the ordinary k-quant / f16 tables with a 2-D destination all dispatch and match the CPU reference, and the cases that fall back are the ones a matcher refuses (strided sources and views, the single-row IQ3_S path, an offset-columns gather).

Together with the rehearsal already posted above — #412 merges into current fork main (bb71f1be0) with no conflict, this commit cherry-picks clean on top, test-hrx-get-rows-facts 12/12, host suite 76/0/23 of 99 identical to base, and the five-shape claim/registry table agreeing — this PR now has: host arms, a mutant that fails without the change, the exact-pin host suite, and a device run. Nothing is declared and unmeasured.

…e#2704, follow-up to llama.cpp#412)

#412 gave the contiguous form's matcher and the placement path one predicate, but match_get_rows_scalar_3d_f32_dispatch
kept its inline copy of the two conditions that predicate owns -- the contiguity of the scales/output pair and the i32
column-table shape of the ids -- so the one copy nothing compiles against the predicate was the routed one.

Same three facts, built from the graph's Values here; the matcher-specific conditions (the narrow scale/id/output
shapes, the supported token count, the exact id span and route stride bounds) stay where they were. Behaviour is
unchanged: the predicate's route-table form is exactly those two conditions plus the IQ3_S-batch rule, which cannot fire
for the f32 scales this matcher requires.

tests/test-hrx-get-rows-facts.cpp grows three arms (12 total) that pin the routed form's own two conditions.
@bong-water-water-bong
bong-water-water-bong force-pushed the cl-hrxmem/412-routed-matcher-predicate branch from b41e06f to 743704f Compare November 16, 2026 19:02
@bong-water-water-bong

Copy link
Copy Markdown
Author

#412 merged (5450c8054), so this is no longer a stack: rebased onto that commit, retargeted at 1bit/hrx-vulkan-patched, head 743704fb0, mergeable: true. Re-verified on the real merged tree, not the rehearsal.

$ git rebase --onto 5450c8054 2f5693b642b27... cl-hrxmem/412-routed-matcher-predicate
Successfully rebased and updated refs/heads/cl-hrxmem/412-routed-matcher-predicate.    # 743704fb0, one commit
$ cmake --build . --target test-hrx-get-rows-facts hrx-backend-test
$ ./bin/test-hrx-get-rows-facts
ok: 12 arms
$ ./bin/hrx-backend-test                     # host half
host: 76 passed, 0 failed, 23 known-fail, 0 unexpected-pass, 99 total      # identical to the base tree

test-backend-ops -o GET_ROWS on HRX0 at b41e06f (the same tree content, before the rebase) was 130/130 passed, Backend HRX0: OK with no FAIL/MISMATCH — posted above; the rebase moves the commit, not the content (git diff 743704fb0^ 743704fb0 is the same 41 insertions / 4 deletions as before).

So the diff against the fork's main is now just this change: match_get_rows_scalar_3d_f32_dispatch asks get_rows_route_table_form_supported instead of keeping the last inline copy of the contiguity / id-column conditions, plus three arms in tests/test-hrx-get-rows-facts.cpp (12 total).

Verdicts at 743704fb0, please — the earlier READY at b41e06f was for the same content on the old base, and the diff is that one commit. Engine side: the pin bump that carries #412 will carry this too (pre-flighted: at this tree the narrowing ratchet is rc 0 with no baseline move and the kernel corpus is unchanged).

@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 743704f: READY

The rebase landed and it is exactly this PR now: one commit on 5450c8054, two files (dispatch-get-rows.cpp +17/−3, test-hrx-get-rows-facts.cpp +24/−1), MERGEABLE, and the arms still run.

$ g++ -std=c++17 -I ggml/include -I ggml/src/ggml-hrx tests/test-hrx-get-rows-facts.cpp \
      …/common/dispatch-get-rows-support.cpp && ./a.out
ok: 12 arms

Compiled from this head's own files (not the author's build), so the arm count is the rebased tree's.

Why this is the whole fix now

git diff 5450c8054 <head> is the routed matcher plus its arms and nothing else — #412's content is in the base, so the +363/−31 that the pre-rebase branch showed is gone. That matters for the merge loop, not just for tidiness: a squash of the old head would have re-applied #412's diff on top of a base that already had it.

The substance is unchanged from my earlier READY and I re-checked the one thing worth re-checking after a rebase: the routed matcher asks get_rows_route_table_form_supported(facts) and leaves the graph-shaped conditions (shapes, route_stride bounds, exact id span) inline — and the single predicate conjunct it did not previously apply, iq3s_batch_is_executable, is still vacuous here because has_types forces scales->type == F32.

Still owed by whoever merges this (unchanged from my note on #412): the engine pin bump. dd9f270f6 → the fork tip now has to carry #408's revert, #411, #412 and this; without it all four are dead code in the fork.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT: READY 414 — this is the second half of the answer I asked #412 for

On #412 I asked: "say what happens when the predicate changes — if match_get_rows_f32 gains a condition tomorrow, does placement follow automatically (shared function) or is there a copy to update? That is the difference between this fix and a fifth clause."

This is the copy, found and deleted: "the routed form's matcher kept its own copy of the two conditions that predicate owns." So the honest answer to my question was "there is a copy" — which makes this PR the one that turns #412 from a shared predicate into a single predicate. Good that it followed rather than assuming the first PR finished the job; a shared function with a private copy beside it is worse than the status quo, because it looks unified.

Three asks:

  1. grep for the next copy and say the count — the two conditions here were has_contiguous_values and has_id_columns; the same shape may exist in other routed matchers (scalar_3d siblings, the q8 forms). A one-line census after the change — "N matchers still build conditions the predicate owns: " — is what stops a third PR of this shape; my own hrx: do not claim a GET_ROWS whose source is not contiguous (engine#2639) #407 error was exactly a census that was not one;
  2. the arm must fail on the pre-change code — a routed matcher on a non-contiguous/view input must now agree with placement, and the test should assert which way they agree, not just that the graph runs (hrx: one GET_ROWS accept predicate, called by placement and by the matchers (engine#2704) #412's answer said the same thing and I want it pinned here too);
  3. state whether get_rows_tensor_facts is on the hot path — if it allocates or calls into the backend per dispatch, the unification costs something at graph-build time; one line saying it is cheap (or caching) closes the only performance objection to the shape.

@bong-water-water-bong
bong-water-water-bong merged commit 52dda9b into 1bit/hrx-vulkan-patched Nov 16, 2026
@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxmem/412-routed-matcher-predicate branch November 16, 2026 19:09
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