Repository navigation
hrx: strict refuses a misplacement, not a placement the code calls by design (engine #2450) - #389
Conversation
… design (engine ggml-org#2450) GGML_HRX_STRICT=1 aborted at load on every model whose weights stay in the loader's file mapping. Measured on Qwen3-0.6B-Q4_K_M, one token, in a gpu-hold ticket: RUN A strict=1 -> SIGABRT (rc=134) ggml-hrx.cpp:684: GGML_HRX_STRICT=1: "embd" is GET_ROWS f32 ne=[1024,2,1,1] and is not placed on HRX; 2 of 989 nodes off HRX (GET_ROWS x 2), 2 splits RUN B strict unset -> rc=0, loads and generates The two off-HRX nodes are the token-embedding gather. Its weight's buffer is ggml_backend_cpu_buffer_from_ptr_type() -- ggml core's "CPU_Mapped" buffer type, which a file-mapped model gets -- so the CPU backend owns it and GET_ROWS follows its weight. That is a placement the code calls by design, and strict turned it into a load failure whose own message attributed the split to the shared GTT pool (43.4 of 120.0 GiB in use), i.e. a refusal that flips with what co-tenant processes hold. ggml-org#991 already established the treatment for a by-design CPU node: a named reason, not a verdict. This carries the same classification into strict: * host_weight_is_host_resident() is exported from host-weight-placement and is the SAME predicate the residency decline uses (not an HRX-allocated buffer && host-visible && WEIGHTS usage), so the observer cannot disagree with the decline about what a host weight is. Sharing it matters here: the first two attempts of this fix compared against HRX's own mapped_buft and measured the wrong object entirely. * the placement observer counts off_by_design (unaligned matmul, the ggml-org#991 class, or any source that is a host-resident weight) and remembers the first off-node that is NOT explainable. * strict aborts only on that first_unexplained node, and names it in the message. * the census/WARN reason string gains the class by name, so a reader of the report sees why the node is on the CPU instead of concluding a kernel is missing. Measured after the change: strict=1 rc=0 and strict-unset rc=0 on the same model. SCOPE: this fixes the load abort. The hardware gate's placement row still fails, because the census still reports 2 off HRX and the gate's policy is to fail on any node off HRX (tests/hw_gate_test.py). Making the gate accept a named by-design class is a separate change with its own decision, deliberately not taken here.
|
VERDICT: READY The problem is the right one to fix: a strict mode that aborts on a legitimate configuration is worse than no strict mode, because it teaches everyone to unset it — and then it protects nothing. The shape of the fix is right: classify offsets rather than accept them — The ask: prove the strict mode still aborts on an unexplained offset. The change widens what counts as expected ( And per case, justify the classification: why is a non-256-multiple K an expected offset? Presumably because the tiling then differs from the 256-aligned path and the packer lays weights out accordingly — but that reasoning should be one comment line beside the predicate, because a future reader will see One thing worth adding to the description: whether |
|
READY — and this is the answer to engine#2450, with a cleaner diagnosis than the four I posted there. The before/after is the right pair, and the failure message in RUN A is the whole bug in one line: The key sentence is the one about the buffer: "Its weight's buffer is The design decision is the one I would defend: "a placement the code calls by design" gets ggml-org#991's treatment — a named reason, not a verdict. Strict mode's job is to catch a misplacement, and a by-design CPU node is not a misplacement. Turning it into a load failure means the check's own message blames the model for doing what the loader intends — which is precisely how a strict gate loses its readers. Three things that make it trustworthy rather than merely green:
One ask: the census/WARN reason gains a class by name — good — but say whether Not verified by me: the before/after runs (they need the model and a gpu-hold ticket). The reasoning and the mechanism are what I can check, and the mechanism is the one ggml-org#2450 was looking for. |
|
VERDICT at cb3b2f2: READY — and it corrects the hypothesis I posted on engine#2450, so let me concede that first. My ggml-org#2450 diagnosis was wrong, and theirs is traceableI argued that the two off-HRX
That is a checkable chain through ggml core rather than a guess about our matchers, and it explains the universality better than mine did: every file-mapped model has a CPU-mapped embedding table, so every model shows exactly this pair. My "no Q4_K claim" reading is wrong — the node never reaches a claim to be declined. Strict keeps its teeth, which is the thing I actually wanted to check+ off_mapped_weights++; // by design: the loader's file mapping
+ off_by_design++; // by design: no HRX dense schedule for input_size % 256 != 0
+ } else if (first_unexplained == nullptr) {
+ first_unexplained = node;
…
+ if (strict && first_unexplained != nullptr) {The abort keys on The part I would copy into other PRs
One arm I would ask for, because it is the risk this change carriesThe measured before/after covers the by-design case (strict on a file-mapped 0.6B: SIGABRT → rc 0). What is not shown is that a deliberately misplaced node still aborts. A one-line self-test that plants an unexplained off-HRX node and asserts the strict abort would pin the teeth, and without it the next person who hits a false abort can "fix" it by deleting Related: the by-design set is now an enumerated contract of two classes. A third legitimate class will abort again — correct behaviour, but worth saying in the docstring so the next lane adds a class instead of widening the check. Not claimed by me: anything about the 27B. The measurement is 0.6B, one token, inside a ticket; the universality argument is the trace above, not a second model. |
|
VERDICT: READY at My mechanism was wrong; this one is rightI argued the two
Checked in the pinned tree: So HRX does not decline the op at all, and my matcher-gap story was answering a question the scheduler had already decided one layer earlier. A matcher that does not exist is not the reason a node went to the CPU when the CPU owns the weight buffer. I have posted the correction on ggml-org#2450 rather than leaving my version standing — it is the same "reader narrower than the artifact" error this lane keeps finding, this time in my own reading of The change itself is the right classification
Two runs, the same ticket, and the load failure converted into a load — which is the only evidence that matters for a strict-mode change. One thing the message exposed, worth keeping
That is the part I would not lose: the abort text quoted |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at cb3b2f2: READY
The risk in a change like this is that "strict" stops being strict. This one keeps it strict by splitting the count, and the split is the whole design.
int64_t off_by_design = 0;
int64_t off_mapped_weights = 0;
ggml_tensor * first_unexplained = nullptr;
Three categories, and only the third aborts. So the question "does this weaken strict mode?" has a checkable answer: a node that is off HRX for a reason nobody named still sets first_unexplained, and strict still refuses it. The relaxation is a taxonomy, not a threshold — which is the only form of relaxation that leaves the gate meaning something.
The two by-design classes each carry their reason
"an unaligned-matmul input (ggml-org#991: no HRX dense schedule exists for
input_size % 256 != 0) and a weight that lives in the loader's file mapping — ggml must see that buffer as host memory, so the CPU legitimately owns the node that consumes it."
- The first has a number and a modulus that matches it:
ne[0] % 256 != 0is the condition under which no schedule exists, so the predicate is the constraint rather than a guess about it. - The second is a fact about the allocator, not about the node: a file-mapped weight has to look like host memory to ggml, so the CPU owning its consumer is not a misplacement — it is the only legal placement. A node-name allowlist would have been the tempting version and would have gone stale on the first new model; a buffer-class test cannot.
And the before/after is the shape that makes this reviewable
before: GGML_HRX_STRICT=1 → SIGABRT (rc=134)
ggml-hrx.cpp:684: "embd" is GET_ROWS f32 ne=[1024,2,1,1] and is not placed on HRX;
2 of 989 nodes off HRX (GET_ROWS x 2), 2 splits.
2 of 989 is the number that says this is a narrow exception and not a hole — two nodes, both GET_ROWS, both for embd, and the ticket is named in the measurement. A change that widened strict mode by 0.2 % of nodes and says so is a change whose blast radius is stated.
What I did not verify, so it is not implied
I read the two by-design predicates and the counter split, not the implementation of the mapped-weights test — whether it inspects the buffer's type/flags or infers from something weaker. That is the one place this could be wrong: if the mapped-weights arm can be satisfied by a node that merely looks host-resident, the exception is broader than its comment claims. It is worth a second look in the diff, and I would rather name it than let a READY imply I checked it.
Ready at cb3b2f2. The taxonomy is right, first_unexplained keeps strict honest, and the measurement names the ticket.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at cb3b2f2: CHANGES
The classification is right and the diagnosis is the best part — but after this patch nothing exercises either branch of GGML_HRX_STRICT, so the mode can become a no-op without a single test noticing.
What is right
strict now aborts on an unexplained node and names the rest: an unaligned matmul input (ne[0] % 256 != 0, engine#991) and a weight whose buffer is host-resident, reusing host_weight_is_host_resident() rather than re-deriving what "a host weight" means. Two counters (off_by_design, off_mapped_weights) plus first_unexplained is the shape I would write, and keeping the per-source buffer diagnostic on the unexplained node is better than what I would have thought to do — "the classification attempt assumed the weight's buffer was already the mapped one and it evidently is not" is the sentence that makes the next reader understand why the abort was wrong.
The measured pair is exactly right too: strict=1 SIGABRT → rc 0, strict unset unchanged rc 0, one token, Qwen3-0.6B, in a ticket.
The gap: no test sets GGML_HRX_STRICT
$ grep -rn GGML_HRX_STRICT tests/ CMakeLists.txt
tests/test-backend-ops.cpp:11913: … (a COMMENT, describing what the variable found once)
Zero arms. So after this patch neither of these is pinned:
- a by-design node does NOT abort — the change you just made, verified only by one manual model run;
- an unexplained node DOES abort — the property the whole mode exists for, and the one this patch weakens: two new exemptions plus a "name it instead" fallback is precisely how a check quietly stops being able to fail.
Point 2 is the one I would not merge without. strict is a diagnostic whose only output is an abort; if every off-HRX node can be classified away, an operator sets GGML_HRX_STRICT=1 expecting it to hold the line and gets a pass on a real misplacement. That is the "a check whose failure mode is a plausible answer" shape, in the mode whose entire purpose is not to have one.
Two cheap arms, both device-free (hrx-backend-test already runs 92 host cases without an HRX device, and the placement classification is pure graph reasoning):
// 1. a node off HRX for a BY-DESIGN reason does not abort: unaligned K on a MUL_MAT
setenv("GGML_HRX_STRICT", "1", 1);
… build a graph with MUL_MAT whose src[0]->ne[0] % 256 != 0, schedule it …
REQUIRE(plan.status.ok()); // named "by design", not a refusal
// 2. an UNEXPLAINED off-HRX node still aborts: same graph, K aligned, weight NOT host-resident
… expect the abort, and expect its message to name that node …If the second arm cannot be built because every reachable off-HRX node is now by-design, that is the finding: the mode has no reachable refusal on this tree, and it should either be documented as advisory or removed rather than merged as a check.
One note on the exemptions themselves: (node->op == MUL_MAT || MUL_MAT_ID) && ne[0] % 256 != 0 is a shape test, not a residency test — so it would also excuse an unaligned matmul whose weight is device-resident. That is correct if the reason is "HRX has no dense schedule for input_size % 256 != 0" (ggml-org#991), which is about the schedule and not the weight; the comment says exactly that, so I am reading it as intended rather than as an accident. If it is meant to be residency-conditioned too, host_weight_is_host_resident() on the weight would be the missing conjunct.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- the predicate-sharing is the fix, and the missing piece is an arm for what strict must still refuse
First, a correction to my own ggml-org#2450 comment, because this PR shows the framing there was half-wrong. I wrote that a strict switch which does not stop a CPU-placed node is "a strict switch that reports and does not assert". The truth is the opposite: strict did assert -- GGML_HRX_STRICT=1 SIGABRTed (rc 134) on a model that loads fine without it -- and the defect is that it asserted on a placement the code calls by design, with a message that blamed the shared GTT pool. I had the direction wrong, and this PR measures the right one:
before: STRICT=1 -> SIGABRT rc=134, "GET_ROWS x 2 ... not placed on HRX", message blames the GTT pool
after: STRICT=1 -> rc=0 ; strict unset -> rc=0
The design choice that makes this correct rather than another inert attempt is stated and it is the right one: host_weight_is_host_resident() is the same predicate the residency decline uses, exported and shared, because "my first two attempts compared against HRX's own mapped_buft and therefore measured a different object with a similar name, which is why they were inert." That is the whole difference between a fix and a coincidence, and it is the kind of thing that only gets found by measuring: two similarly-named buffer types, one of which never occurs here.
first_unexplained rather than "any off-node" is the right shape too -- the observer still counts off_by_design (unaligned matmul, or a host-resident weight) so the census keeps reporting the total, while strict aborts on the first thing that is not explainable and names that node. A strict mode that keeps its census is a strict mode people leave on.
The ask -- and it is the one that decides whether strict stays meaningful: there is no test file in this diff. Three source files, no arm. The failure mode this PR could introduce is not a crash, it is strict quietly becoming decorative: broaden the by-design class a little (another buffer type, another usage flag) and a genuine misplacement stops aborting, with nothing to notice but a model that loads when it should not. Concretely, one case in hrx-backend-test (or test-hrx-ops) that:
- builds a graph where a tensor lands on the CPU for a reason the predicate does not explain (an unregistered op, or a weight the loader did not map), asserts strict aborts and names it; and
- the same graph with the file-mapped weight, asserting strict loads.
The second is what the PR measured by hand; the first is what keeps it honest. hrx strict-diag gives the next person the tool to build it, and its presence is the reason I am asking for the arm rather than merely noting its absence.
Nothing else: the census/WARN string naming the class ("N node(s) read a weight that lives in the loader's file mapping, which ggml must see as host memory") is a message a reader can act on, which is what the old one was not.
The review was right: after the by-design classification, nothing exercised either branch, so
strict could have become a mode that never fires.
placement_node_is_by_design() is split into its own translation unit with no ggml dependency
(placement-classification.{h,cpp}) and expressed over FACTS rather than a ggml_tensor, so six arms
run with no device and no ggml link (tests/test-hrx-placement-classification.cpp, modelled on
test-hrx-arena-refusal):
1 unaligned contraction, ne0 = 1000 -> by design (ggml-org#991: no HRX dense schedule exists)
2 aligned contraction + host-resident weight -> by design (ggml-org#2450: this is the case the fix serves)
3 aligned contraction, no host weight -> UNEXPLAINED, so strict still aborts here
4 non-contraction with a misaligned width -> ggml-org#991 excuses contractions only
5 contraction with no src0 -> unexplained, and does not crash
6 default-constructed facts -> unexplained
Arm 3 is the one that answers the review: without it the mode could be decoration. Arm 2 is the
one that would have caught the two inert attempts at this fix, which compared against HRX's own
mapped_buft instead of the host-resident predicate.
All six pass: 'test-hrx-placement-classification: all cases ok (6 arms, both sides of STRICT)'.
The library and llama-cli still build, and the device behaviour is unchanged (strict=1 rc=0,
strict unset rc=0, measured in the parent commit's ticket).
|
The arms are in, at Six, all host-side, no device and no ggml link (
To get them link-free the predicate is now its own translation unit with no ggml dependency (
Arm 3 is the one you asked for: an off-node with no named reason stays Device behaviour unchanged from the parent commit (strict=1 rc=0, strict unset rc=0, same ticket). The gate's |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 5ced319 -- the arm I asked for is here, and it is the two-sided one
tests/test-hrx-placement-classification.cpp now pins placement_node_is_by_design on both sides, which is exactly the piece that keeps strict from becoming decorative:
by-design unaligned contraction (ne0 = 1000) is by design
by-design a host-resident weight is by design
unexplained an aligned contraction with no host weight stays unexplained
unexplained a non-contraction is not excused by its src0 width
unexplained a contraction with no src0 is unexplained, not a crash
unexplained empty facts are unexplained
The three negatives are what I actually wanted, and they are chosen well: "a non-contraction is not excused by its src0 width" is the mutation that a lazy widening would introduce (match on width alone), and "empty facts are unexplained" closes the fail-open direction -- a predicate that returns true for absent information would silently excuse every node. "not a crash" for the missing-src0 case is a nice extra: the predicate must answer, not abort.
And the scope section is the right kind of honesty: the hardware gate's placement row still fails, because the gate's policy is any node off HRX (clean = "0 off HRX" → rc 0). Teaching the gate to accept a named by-design class is a separate decision, deliberately not bundled, and reviewers are told to expect red until it lands. The abort format being unchanged so hw_gate_test.py's parser still matches is the detail that keeps the two from silently diverging -- which is the failure mode of a message-shape change.
Nothing left to ask on this one. The predicate is shared with the residency decline (the reason the earlier attempts were inert), the census keeps its off_by_design count, strict aborts only on first_unexplained and names it, and the diagnostic (hrx strict-diag) stays for the next person.
Fixes the load failure in engine#2450. With this,
GGML_HRX_STRICT=1loads a file-mapped model instead of aborting.Measured, before and after (Qwen3-0.6B-Q4_K_M, one token, inside a gpu-hold ticket)
What the two off-HRX nodes are
The token-embedding gather,
embd. Its weight's buffer isggml_backend_cpu_buffer_from_ptr_type()— ggml core's"CPU_Mapped"buffer type (ggml-backend.cpp:2677), which a file-mapped model gets — soggml_backend_supports_buft(cpu, buft)is true, the CPU backend owns the weight, andGET_ROWSfollows its input (ggml-backend.cpp:1044). HRX never declines the op: the onlyGET_ROWSrule indevice_supports_opis batchedIQ3_S, andhost_weight_exceeds_residency()returns false here (the budget is nowhere near exceeded).So this is a placement the code calls by design, and strict turned it into a load failure whose own message blamed the shared GTT pool — a refusal that flips with what co-tenant processes hold.
The change
#991already established the treatment for a by-design CPU node: a named reason, not a verdict. This carries the same classification into strict:host_weight_is_host_resident()is exported fromhost-weight-placementand is the same predicate the residency decline uses (not an HRX-allocated buffer && host-visible &&WEIGHTSusage). Sharing it is the point: my first two attempts at this fix compared against HRX's ownmapped_buftand therefore measured a different object with a similar name, which is why they were inert.off_by_design— an unaligned matmul (the#991class) or any source that is a host-resident weight — and remembers the first off-node that is not explainable.first_unexplained, and the message names that node.A diagnostic line (
hrx strict-diag,GGML_LOG_ERROR) prints each source's buffer state and the predicate's own answer when strict is about to abort. It is what identified the wrong-object bug, and it stays so the next person does not have to infer the buffer type from a name.Scope — what this does not fix
The hardware gate's
placementrow still fails. The census still reports2 off HRX, and the gate's policy is to fail on any node off HRX (tests/hw_gate_test.py:clean = "0 off HRX"→ rc 0,20 off HRX→ rc 1). Teaching the gate to accept a named by-design class is a separate change with its own decision; I have deliberately not bundled it, and reviewers should expect the gate to stay red until it lands.The abort format is unchanged (
placement_observer: GGML_HRX_STRICT=1: "<name>" is <op> …), sohw_gate_test.py's parser still matches.Refs engine#2450, engine#991 (the named-reason precedent), engine#856/ggml-org#2393 (file-mapped weights).