Repository navigation
hrx: a TOP_K claim requires the registration, not only the shape (engine#2704) - #415
Conversation
…tchers (engine#2704)
device_supports_op decided placement from the op code while the decision that matters at compute
time was made by the registered matcher, so every disagreement became another hand-written clause in
the placement path: a batched IQ3_S source (llama.cpp#407) and a strided VIEW source (engine#2639)
each cost one. The second was also narrower than the family it stood for -- it checked the source's
contiguity and not the ids' or the output's, so a GET_ROWS with a strided ids tensor was claimed
here and executed by nobody.
The family has two forms with different conditions, so the fix is not one conjunction:
* the contiguous form (match_get_rows_f32 and the scale_f32 / rmsnorm_binary forms that call it)
needs weight, ids and output contiguous;
* the route-table form (match_get_rows_scalar_3d_f32, the qwen3.6-35b routed experts) reads the
ids through a row stride, so its ids are deliberately NOT contiguous.
A conjunctive "ids contiguous" in the placement predicate would therefore have moved every routed
GET_ROWS to the CPU while every per-matcher test stayed green. So the facts are written once
(dispatch-get-rows-support.h), the two forms are two named predicates that their own matchers call,
and placement asks the union: "can SOME form execute this node".
The new test is host-only (no device, no graph, no libhrx) because the defect is two callers
disagreeing, which neither caller's own test can catch; 9 arms, including the routed shape that a
conjunctive predicate would break and the two shapes that each cost a decline.
Refs engine#2704
#408 and this branch rewrite the same GET_ROWS block, so the resolution keeps #408's derivation (source contiguity is what every matcher gates; ids must not be constrained as a conjunction, because match_get_rows_scalar_3d_f32 admits strided ids on purpose) and states it in the new place instead of repeating it: the facts carry a per-form predicate, so the ids constraint lives with the form that has it and the union still claims the routed shape. The batched-IQ3_S clause folded into the same predicate, so the placement path no longer carries two hand-written GET_ROWS clauses. Rebuilt at bb71f1b: test-hrx-get-rows-facts 9/9, ctest #75 Passed.
#412) Three text corrections after the review at d273fb3, no behaviour change: 1. The direction was inverted. An over-approximation in PLACEMENT is the unsafe direction -- it is engine#2639 itself, a claimed node executed by nobody. Said so plainly. 2. The header claimed "a condition cannot be in one caller and not the other". That is true of the conditions moved into the facts (contiguity, type, batch) and false of the ones that need the graph. Narrowed to what the code does, and recorded WHY the rest is not a hole: the tail of device_supports_op asks the registry (can_execute_standalone_op_as_graph -> DispatchScheduler::supports_node), measured on the box at this pin -- an F16 destination gets no standalone dispatch (so the tail refuses it) while a 3-D destination gets one (so declining it here would be the #407 error of refusing a path that works). 3. The same two facts are recorded next to the comment that says GET_ROWS is "no longer stated here at all", so a reader cannot conclude the un-moved conditions are unguarded. test-hrx-get-rows-facts 9/9 after the edit (comments only, but the row is the PR's proof and it runs in the same target).
…ine#2704)
device_supports_op answered TOP_K with hip_top_k_tensor_supported(op) alone, and that
predicate says nothing about whether the op is registered: register_hip_top_k_dispatch
returns BEFORE hip_declare_eager_op when the hip_top_k_f32 code object is not embedded.
On such a build every well-shaped TOP_K was claimed with no matcher to execute it --
engine#2639's class, "unsupported HRX node ... TOP_K", graph_compute -1, nothing
generated, instead of a CPU fallback.
Measured on a build constructed for it (same commit, hip/kernels/hip_top_k_f32.hip moved
aside, so the embedded table has no object; 0 entries against 1 in the shipped table),
one TOP_K node, no device, target gfx1151:
shape eager_declared registry | before after
no-object build yes no no | CLAIM decline
shipped build yes yes yes | CLAIM CLAIM
eager_capability_declared is the flag hip_declare_eager_op sets, i.e. exactly the call the
registration path skips when the object is missing, so it is the half of the question the
early return was missing. The alternative -- deleting the early return and letting the
generic tail decide -- was rejected: that tail ends in can_execute_standalone_op_as_graph,
a one-node graph build plus a registry match per node, which the MoE router pays once per
layer. GGML_HRX_HIP_TENSOR_CLAIM=0 builds are unaffected (hip_eager_op_declared is not
under that macro) and GGML_HRX_DISABLE_DISPATCH=hip.top_k_f32 was already handled by the
predicate's own dispatch_name_disabled check.
No unit arm: the line is inside a static function, and an arm on the conjunction would be
tautological. The two-build probe is the instrument that distinguishes them and it is in the
PR text with the recipe.
Refs engine#2704
|
VERDICT at The measurement is the strongest form: build the absence
Three predicates disagreeing in one row is the whole bug, and constructing the missing-object build is how you find out that The structural finding, which is worth more than the TOP_K patch
With that lens, the audit is one pass:
The ask, and it is two lines plus a clauseEither guard them the same way ( That converts this PR from "the third instance fixed" into "the class closed", and it is the difference between a sequence of patches ( Credit where the sequence deserves itThe comment measures the GET_ROWS registry too ("8 GET_ROWS registrations … an F16 destination"), so this PR is written with its siblings in view rather than in isolation — the three of them now describe one defect from three ops. |
|
Two more rows for the table, both measured on the builds already at this commit — the The middle row is the one worth reading: the registration is disabled, so the shape predicate itself returns
|
|
The last unmeasured sentence in the body, now a row — Rows 1 and 2 are identical, which is what the body asserted and had not checked: That is every environment the diff touches: default, the macro mutant, the env-disabled registration, and a build without the code object. The remaining row is the device one ( |
|
The sibling question this change invites: are the other early returns in
Measured for the ARGSORT row (placement predicate vs registry, three shapes): contiguous So |
|
Promoted from draft: ready for review at 9a4d320. The reason it was a draft is gone — Summary of what a reviewer should weigh, in one place:
|
device_supports_opanswered TOP_K with the shape predicate alone:and that predicate says nothing about whether the op is registered.
register_hip_top_k_dispatchreturns beforehip_declare_eager_opwhen thehip_top_k_f32code object is not embedded, so on such a build every well-shaped TOP_K is claimed while no matcher can execute it — engine#2639's class again (claimed, thenunsupported HRX node … TOP_K,graph_compute -1, nothing generated) instead of a CPU fallback.Measured, on a build constructed for it
The fork compiles the code objects from its own
hip/kernels/*.hipglob, so "the object is absent" is a configuration anyone can reproduce: same commit, kernel source moved aside, embedded table has nohip_top_k_f32entry (0 vs 1 in the shipped table).The
shapepredicate isyeson both, so before this change the early return claimed the node in the first row, whereregistry=nomeans nothing dispatches it.eager_declaredis the flaghip_declare_eager_opsets — the very call the registration path skips when the object is missing — so it is exactly the missing half of the question.The change
One conjunction, and deliberately not the alternative of deleting the early return and letting the generic tail decide: the tail ends in
can_execute_standalone_op_as_graph, which builds a one-node graph and runs a registry match — a per-node cost that the MoE router pays once per layer, to answer a question this flag answers in a load.GGML_HRX_HIP_TENSOR_CLAIM=0builds are unaffected (hip_eager_op_declaredis not under that macro), andGGML_HRX_DISABLE_DISPATCH=hip.top_k_f32was already handled by the predicate's owndispatch_name_disabledcheck.Before / after, same two builds
Row 1 is the defect and its closure: the claim now agrees with the registry instead of asserting the opposite. Row 2 is the
control — on the build that ships, before and after are identical, so this costs nothing where the object exists.
Reproducing the second build (six commands, no device)
Then link any small program against that
bin/libggml-hrx.soand printhip_top_k_tensor_supported(op),hip_eager_op_declared(GGML_OP_TOP_K)andcan_execute_standalone_op_as_graph(op, "<arch>")for one TOP_K node. Thearch string matters:
find_dispatch_registryonly answers for the architectures it builds, so a wrong one makes theregistry column say
nofor a reason that has nothing to do with this change (it cost me one wrong reading).Rebuilt both
libggml-hrxat this commit to take the numbers (~/wt/cl-856-notopk-band the shipped build), probe source in thePR text above: one node (
f32in,i32out, cols 1024, k 8, rows 512), no device, targetgfx1151.Why there is no unit arm
The line is inside a
staticfunction (device_supports_op), so a host test cannot call it, and an arm on the conjunction would be tautological. The instrument that can tell the difference is the two-build probe above, which is why it is in the PR text with the exact configuration that reproduces it. If a reviewer wants it in-tree, the natural home is a smalltools/probe with the kernel-omission recipe documented, not a ctest.Refs engine#2704