Repository navigation
sched: an in-place node and its storage have to share one backend (engine #920) - #190
Conversation
…gine ggml-org#920) pass 4 adopts the view parent's backend only for a node that is still unassigned, so a node placed from src[] keeps its own backend. an in-place node (SET_ROWS, *_INPLACE) writes into its view object's buffer, so when that storage is device memory and the node is on the CPU, the CPU writes through a pointer it cannot map (HRX allocates device buffers at a fake base; the DeepSeek-V4.1 candidate mask is the measured case in engine ggml-org#920). new pass 3.5, before pass 4: for an assigned in-place node whose backend differs from its storage's, test what the storage actually is - an allocated buffer's type when there is one, the assignment's buffer type when there is not - and skip host-addressable memory, which any backend can address. device-local storage that is still unallocated moves to the node's backend; device-local storage that already exists and belongs to another backend aborts naming the buffer type and both backends instead of writing through an unmapped pointer.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
READY on the scheduler logic; what I can verify without a device is that it changes nothing on the host path, which is the property the pass has to have.
ggml/src/ggml-backend.cpp @ pr/190 (ed2731ee0): rc=0, then a CPU-only build of this head:
$ test-backend-ops -b CPU -o SET_ROWS,GET_ROWS,FILL -> Backend CPU: OK, 1/1 backends passed
$ llama-cli -m Qwen3-0.6B-Q4_K_M.gguf -c 256 -n 8 ... -> runs
Read:
- Host is a hard skip. Every host buffer type returns early (
ggml_backend_buft_is_host), so on a CPU-only graph pass 3.5 is a no-op — that is why the two runs above are unchanged, and it is also the reason this cannot regress a host-only build. - Unassigned storage is handled.
storage_backend_id == -1with no buffer givesstorage_buft == NULL→continue, so pass 4 still gets to place it from the view parent; and thesched->bufts[storage_backend_id]index is only taken after that guard, so there is nobufts[-1]. - The two aborts are the correct failure mode rather than a silent CPU write into device memory: an already-allocated foreign buffer cannot be moved, and a device that cannot produce the storage cannot host the in-place write.
- View root, not the immediate parent, is walked, so a chain of views is covered;
ggml_is_view_op(node->op)keeps genuine view ops out.
Nit, not a blocker: the storage_backend_id == node_backend_id test appears twice — once inside the allocated branch and once after it. Correct, just duplicated.
Not verified: the HRX case it exists for (engine ggml-org#920's SET_ROWS on an HRX-allocated bm). That needs the private HIP add-on claiming FILL and a GPU ticket, i.e. the issue's own reproducer.
…t on #190) Both branches continued on the same predicate: the allocated branch before its abort, and the unallocated path before the supports_op check. One guard ahead of the branch covers both and drops the duplicate. No behaviour change.
|
Nit taken — fixed, not argued: the double test was reachable from two mutually exclusive branches, both of which Re-proved after the rebuild rather than assumed, same model-free graph, three arms distinguished by Also checked your "not verified" line since it is the case the patch exists for: the HRX-side reproducer does not need One thing for the merge: the base moved under this PR — |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
61a7e312e, one file (ggml/src/ggml-backend.cpp +45): a new pass 3.5 in ggml_backend_sched_split_graph.
The assignment is valid — the thing I wanted to be sure of before calling this safe, because the pass mutates the
scheduler's placement table: tensor_backend_id is a macro over a hash-indexed array,
#define tensor_backend_id(tensor) sched->hv_tensor_backend_ids[hash_id(tensor)], so tensor_backend_id(storage) = node_backend_id; writes the table rather than failing to compile against an rvalue.
The pass's decisions, in the order they matter:
- view ops and unassigned nodes are skipped (unassigned is pass 4's job) — so this never fights the existing passes;
- a host buffer type (or no resolvable type) is skipped, because host memory is addressable from every backend;
- same backend id on both sides is skipped — nothing to move;
- allocated storage that sits on another backend aborts with both names, instead of silently writing through a
pointer the CPU cannot map. That is the engine#920 failure mode turned into a message, and aborting is right: once the
buffer exists there is no placement that works; - unallocated storage moves to the node's backend, but only after
ggml_backend_supports_op(..., storage)confirms that
backend can produce it — so the fix cannot create a placement that a later pass has to undo; SET_CAUSE(storage, "3.inpl")keeps the move visible in the schedule dump, which is how a future reader will find out
why their tensor moved.
Compile at this head: ggml/src/ggml-backend.cpp -> rc 0, 0 errors, 0 warnings.
One consequence worth stating rather than fixing: moving the storage to the in-place node's backend can push other
readers of that storage onto the other side of a backend boundary (a copy the scheduler then inserts), so the cost can
land on a node that is not in this diff. That is the correct trade against a wrong write, and it will show up as
graph splits in a placement report rather than silently — which is what #197's new line is for.
Not run by me: an HRX device run of a graph with an in-place node whose view parent sits on the CPU (engine#920's
shape). The abort path needs one to be sure the message fires; the reasoning above is why I am not withholding the
verdict on it.
sched: an in-place node and its storage have to share one backend (engine ggml-org#920)
Root cause
ggml_backend_sched_split_graphdecides placement in five passes. Pass 4 is the only pass thatconsults a node's view parent, and it does so only while the node is still unassigned:
An in-place node —
SET_ROWS, or any*_inplaceop, whichggml_set_rows()builds asggml_view_tensor(ctx, a)and then renames toGGML_OP_SET_ROWS(ggml.c:3956-3976) — is normallyassigned earlier, from its
src[]. So the node ends up on the CPU (no device matcher claimsSET_ROWS) while the buffer it writes in place lives on a device backend, and the CPU writes througha pointer it cannot map.
Engine ggml-org#920 is the measured instance: the private HIP add-on claims
GGML_OP_FILL(
hip_declare_eager_op(GGML_OP_FILL)), so DeepSeek-V4.1's candidate-block maskbm(
src/models/deepseek41.cpp:607) is allocated in HRX device memory, andggml_set_rows(ctx0, bm, ...)gets a CPU destination of
0x1a000=GGML_HRX_FAKE_PTR_BASE (0x1000)+0x19000. SIGSEGV in__memcpy_avx512_unaligned_ermsunderggml_compute_forward_set_rows.The class is not specific to HRX or to
SET_ROWS: it is reachable in shared scheduler code whenever abackend claims the producer of an in-place target, and upstream
masterhas the same conditionalview rule (no in-place rule exists there). It is latent upstream only because CUDA/Metal/Vulkan do not
claim
FILL.The change
One new pass between pass 3 and pass 4 (
ggml/src/ggml-backend.cpp, +48 lines, no other file). For everyin-place node (
view_src != nullptr, not a view op) whose assigned backend differs from the backend of itsstorage — the view root, walked up the chain:
storage->bufferwhen it is allocated (ggml_backend_buffer_get_type),and from
sched->bufts[assigned id]only when it is not. An id is a guess, a buffer is a fact — an earlierversion of this patch aborted on the id and was wrong;
FILLthen runs on the CPUand pass 5 inserts the copy back for its device consumers), provided the node's backend can produce it;
GGML_ABORTnaming the buffer type and bothbackends, instead of letting the node write through a pointer it cannot map.
Pass 4 is untouched, and all of this happens before pass 5 computes the splits and the copies, so the split logic
honours the move.
Scope note: this does not try to move the node onto the storage's backend even when that backend
supports the in-place op (it does not for
SET_ROWShere). Doing so would change placement of opsthat run on the CPU today, and nothing measures that; it is a separate decision.
Why the new abort cannot fire on a legal configuration
The failure mode of a patch like this is a backend whose device memory the CPU can reach — SVM, or host-visible
vidmem on an APU. The check is
ggml_backend_buft_is_host, which is the same predicateggml_backend_buffer_is_hostis built from (
ggml-backend.cpp:175-177) and the one the scheduler already uses elsewhere to decide CPU reachability(
ggml-backend.cpp:485,:2276), so a CPU-reachable buffer is skipped before any abort can be reached. Concretely:GGML_HRX_FAKE_PTR_BASE(0x1000) for a device buffer and a real mapped pointer only for a hostbuffer (
ggml-hrx.cpp:412-413); the two buffer types are created withhost_visible = falseandtruerespectively (
ggml-hrx.cpp:1485,:1487). Device buffers are therefore never CPU-dereferenceable, with SVM orwithout — it is the fake base, not the memory model, that makes Fails to run quantize command ggml-org/llama.cpp#920 a crash, and SVM does not turn the abort on.
is_host = NULLfor its device buffer type (ggml-vulkan.cpp:354), and the CPU never writestensor->dataon that backend, so the scheduler already treats those buffers as unreachable.So the abort is confined to memory no CPU op was ever allowed to write, and the case it catches — already allocated on
another backend, not host-addressable — is exactly the one that segfaulted before.
Before / after, on the issue's own reproducer
Reproducer unchanged:
~/lb/d3-setrows-ident.sh—-dev HRX0 -fit off -ngl 0 -c 256 -b 16 -ub 16,GGML_HRX_HOST_WEIGHT_LIMIT_MB=64, gdb onggml_compute_forward_set_rowsprintingdstper call.SET_ROWSexecutedd8bd0ff60,libggml-base.sosha2565a3cc818…__memcpy_avx512_unaligned_erms,dst=0x1a000=GGML_HRX_FAKE_PTR_BASE+0x19000libggml-base.sosha25626bfd55d…refusing to run: … a 32 MiB weight did not fit), which is a refusal, not a crashPlacement delta from
GGML_HRX_REPORT=1, same model, same shapes:+42
FILLnodes leave HRX, nothing else moves, and the split count is unchanged — one movedFILLperbm-like in-place target, and the copies the fix needs fit inside splits that already existed.Same issue shape as TDSV41's arm A (
-c 512 -b 32, 64 MiB host-weight budget, plainllama-cli, no gdb), which is theshape that actually lets this model generate — the crash-tuned
-c 256 -b 16run dies at #173's arena guard before anytoken is emitted, in both arms once the budget is raised to 2048 MiB (measured: the unpatched binary refuses at 94 s
with 0
SET_ROWS, so that wall is the budget's, not this patch's):> The capital of France is→Paris32.8 MiB wanted)Smaller, model-free form of the same defect (
~/lb/i920-mini, 20 lines, 2 s, no model):bm = FILL(base)+out = SET_ROWS(bm, val, ids)over[8,4]F32, read back and compared:-dev CPU-dev HRX0It is not shipped in the PR: no upstream CI backend claims
FILL, so the case cannot run there; it is attached toengine ggml-org#920 instead. Re-run after the 2026-11-04 reboot, on kernel
7.4.0-rc1-1bit(the earlier runs were on7.3.0-rc4-1bit-perfopt+): same result, before SIGSEGV (rc=139) / afterPASS 32/32on-dev HRX0, both armsPASS 32/32on-dev CPU.Both arms are private snapshots of
build/bin(~/wt/i920-bin-before,~/wt/i920-bin-after), hashed withsha256sumimmediately before and after each run (every hash prefix in this body is a sha256 prefix, not md5); onlylibggml-base.so.0.18.0differs between them, so the A/Bisolates this commit.
ggml/src/ggml-backend.cppis byte-identical between the two source trees at thepin, verified with
diff -q.Test matrix
test-backend-ops -o SET_ROWS,FILL -b CPU -j 8: 563/563 both arms.HRX0, both arms, same prompts: Qwen3-0.6Bmd5 abd8f61b…, Qwen3-4Bmd5 44bb0256…—identical before vs after, with no
ggml_backend_schedabort. Throughput is not compared across arms (the boxcarried two servers and other lanes' holds; 4B read 37 vs 64 tok/s in the same window — co-tenant drift).
-dev none, Qwen3-0.6B) clean in both arms.sha256sumofllama-cli,libggml-base,libggml-hrxbefore and after,and the snapshot is loaded through
LD_LIBRARY_PATHwithlddprinted into the log — the first attempt at this A/Bsilently loaded the shared build tree's
libggml-basethroughDT_RUNPATHand measured nothing, so the check isnow part of the instrument.
CI
This fork's Actions are not scheduled for branch pushes or PRs here (
actions/runs?branch=…→ 0 runs for thebranch, and
gh pr checksreports no checks), so the verification above is local and reproducible with the harnessesnamed in it.
ggml-basebuilds clean with-Wall -Wextraat this pin (no new warnings).Files
ggml/src/ggml-backend.cpp— pass 3.5 (only file).closes engine ggml-org#920
Review nit, addressed by deletion rather than by argument
pi-prs' review (2026-11-04 06:56) noted that
storage_backend_id == node_backend_idis tested twice: once inside theallocatedbranch, once after it. Both armscontinueon equality, so one guard ahead of the branch covers both. Thatis
61a7e312e, 3 insertions / 6 deletions, no behaviour change:All four cases are the same as before:
allocated && same→ continue,allocated && !same→ abort,!allocated && same→ continue,
!allocated && !same→supports_opthen adopt.storage_backend_id == -1is untouched:node_backend_id == -1already continued above, and an unallocated-1storage takes thestorage_buft == NULLcontinue before the hoist.Re-proved on the model-free graph after the rebuild (
libggml-base.sosha25676b8f997…, three distinct arms by hash):libggml-base.so(sha256)-dev CPU-dev HRX05a3cc818…rc=139)ed2731ee0)26bfd55d…61a7e312e)76b8f997…Run under
gpu-holdon this boot (kernel7.4.0-rc1-1bit), 3 s of GPU, die 45 °C, token released.Re-proved again after the 13:17 reboot of 2026-11-04 (
gpu-hold -l sched-i920-boot14, three arms, 3 s of GPU, die40-41 °C in-run):
beforesha2565a3cc818-> SIGSEGVrc=139on-dev HRX0,after + nit fixsha25676b8f997-> PASS 32/32, both arms
PASS 32/32on-dev CPU. Thebeforearm faulting inside the same hold is the negativecontrol, and
lddprinted per arm confirms each arm loaded its own snapshot'slibggml-base. Kernel build is unchanged(
7.4.0-rc1-1bit #1), so this is a fresh-boot confirmation, not a new kernel.Base moved since the review, checked and inert:
1bit/hrx-vulkan-patchedis nowa5c32fbf8— one commit,convert: restore --dspark … (engine #961) (#187), which touches onlyconvert_hf_to_gguf.py(+4 lines, an argparseflag). No compiled path changed, so the measurements above still describe the merged result, and no rebase is needed.