Repository navigation
hrx: a write retargeted to its external storage keeps its own offset once (engine #679) - #336
Conversation
…once (engine ggml-org#679) storage_binding_target() moves a write through a transient view onto the external value that covers the written range (the scheduler's split output, when the consumer runs on another backend). That retarget offset already folds in the binding's own offset (storage_offset + binding_offset - external->storage_offset), but append_command() added it to command_binding.offset again. Every binding with a non-zero offset on that path landed at twice its place. qwen4exp's sparse-attention mask hits it whenever hip.fill_f16 is on and the mask ADD stays on the CPU: the batched SET_ROWS writes one slice per query row at i02 * 5120, the second half of the slices went past the 2,621,440-byte mask, and the 18.8k prefill's second ubatch was refused ("outside runtime binding length"). Decode has one slice at offset 0 and never showed it. The retarget now marks its offset absolute and the caller assigns it; the root-alias path keeps adding its storage offset as before. hrx-backend-test external_write_retarget_offset pins a write at byte 128 of a transient view that an external view of the same storage covers: it passes with this change and fails without it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
VERDICT: READY at The arithmetic, spelled out
That is the clearest statement of this bug class I have read: the offset is a sum of three terms computed in one place, and a second place adds one of them again. The fix is to make the fold happen once — which is the same rule as ggml-org#2271's "one resolution, shared", ggml-org#2333's single seam, and every "second set of rules" in this queue. And it explains why it only bites in one configuration: "the scheduler's split output, when the consumer runs on another backend" — a retargeted write is the only path where the transient view exists, so a test that writes into a plain output never sees the double-add. Two asks
And the arm needs the configuration, not just the caseThe bug requires a split output whose consumer is on another backend. A test that constructs the retarget by hand proves the arithmetic; a test that runs a graph that actually splits proves the wiring. If only the first exists, say so — it is the difference between testing the formula and testing that the scheduler produces it. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 1cb48cc
The arithmetic in the comment is the arithmetic in the code, and the arm asserts the one number that distinguishes the two behaviours.
- target.offset = graph_value->storage_offset + binding_offset - external_target->storage_offset;
+ target.offset = graph_value->storage_offset + binding_offset - external_target->storage_offset;
+ target.absolute = true;
…
- if (binding_target.offset > 0) {
+ if (binding_target.absolute) {
+ command_binding.offset = binding_target.offset; // already includes binding_offset: assign
+ } else if (binding_target.offset > 0) {
command_binding.offset += binding_target.offset; // the alias path still addsREQUIRE(output.offset == 128) is the assertion I would have asked for, and it is exact rather than relational: the bug makes it 256 (128 from the retarget plus the binding's own 128), so a test that checked "the write lands inside the binding" would pass at both values -- the binding is 2621440 bytes wide, which is why the real failure was a range overrun 256 times over rather than an immediate abort.
The two-path design is the right one and it is explicit: absolute defaults false, so the alias-into-storage-root case keeps its additive offset, and only the retarget sets it. That is exactly the distinction the comment states, and it is the reason a blanket "assign instead of add" would have broken the other path.
The symptom is measured where it happened, not reconstructed: "the second prefill ubatch was refused with binding value=674 … range=[5232640, 52…] outside runtime binding length 2621440 (256 such ranges), then llama_decode returned -3", and "decode has one slice at offset 0, so it never showed" -- which is the sentence that explains why this survived: the single-slice case is the one every earlier test used.
One thing bundled in this diff that the body does not name, and it is not wrong just unannounced: the SET_ROWS matcher now accepts q4_0 as well as q8_0 (output->type != GGML_TYPE_Q8_0 && output->type != GGML_TYPE_Q4_0), and the comment above it changed from "q8_0: the quantized KV cache" to "q8_0 / q4_0". If that is part of the same fix it belongs in the body; if it rode along, it needs its own line, because it widens what HRX claims to dispatch and the table's arms are all about the mask chain.
Not run: the new hrx-backend-test arm and the maskchain rows -- -DGGML_HRX=ON needs the private runtime, which this worktree does not have (same constraint as the other HRX PRs I reviewed tonight). So this verdict rests on the code, the arithmetic, and the assertion being the discriminating number rather than on my execution of it.
Ran it, and mutated it -- the arm passes on your head and fails on the bug
Two things worth knowing, since they are the difference between a test that runs and one that does not:
Still not run by me: anything on the device tier (needs the |
Refs engine ggml-org#679 (the QSA mask chain; item 4 of the lead's list, and cl-npuperf's
hip.add_f16audit).The bug
storage_binding_target()(dispatch/command-program.cpp) moves a write through a Transient view onto the External value that covers the written range. That External is the split output the scheduler owns when the consumer runs on another backend. The retarget offset isso it already includes the binding's own offset.
append_command()then didcommand_binding.offset += binding_target.offset, which counts the binding offset twice. Any binding with a non-zero offset on that path lands at twice its place.Where it showed up
qwen4exp's sparse-attention mask with
GGML_HRX_HIP_F16_FILL=1and the maskADDon the CPU. That makes theSET_ROWSresult a split output, and the batchedSET_ROWSwrites one slice per query row ati02 * 5120.binding value=674 … range=[5232640, 5237760) is outside runtime binding length 2621440(256 such ranges), thenllama_decodereturned -3. Windowcl-hrxmem-679-fill-fn, 11-13 09:47Z.GraphValue) against 0, 5120, 10240 (Transient) with the add also on HRX.match_hip_set_rowsshowed both arms hand over the same cacheValue:nb=[2,2,5120,2621440]. The doubling happened after the matcher, in this lowering.The change
The retarget marks its offset
absolute, and the caller assigns it instead of adding it. The root-alias path (offset = the alias's offset into its root, to which the binding offset still adds) is unchanged.Verified (Strix Halo gfx1151, gpu-hold tickets; add-on at gpu-kernels
d37fa7a)hrx-backend-test external_write_retarget_offset(write at byte 128 of a Transient view an External view covers; expects offset 128)maskchain, fill only,512 2048 2560/512 2051 5120/1 2051 18944maskchain, fill+addmaskchain, add only / neitherhrx-backend-test, no add-onhrx-backend-test, add-on compiled intest-backend-ops -b HRX0SET_ROWS / CPY / GET_ROWSNot run: a model-level 18.8k arm with this build and
GGML_HRX_HIP_F16_FILL=1. The windows needed for it were skipped twice (MemAvailable 79G and 72G after stopping coder-llm). That run is the model gate, so the flag's default isn't touched here.🤖 Generated with Claude Code