Repository navigation
fix typo in chatLLaMa - #368
Merged
Merged
Conversation
The prompt contains a typo where 'alound' is used instead of 'aloud'.
Green-Sky
approved these changes
Mar 21, 2023
Deadsg
pushed a commit
to Deadsg/llama.cpp
that referenced
this pull request
Dec 19, 2023
Update README.md
Seunghhon
pushed a commit
to Seunghhon/llama.cpp
that referenced
this pull request
Apr 26, 2026
The prompt contains a typo where 'alound' is used instead of 'aloud'.
phuongncn
pushed a commit
to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4
that referenced
this pull request
Apr 28, 2026
The prompt contains a typo where 'alound' is used instead of 'aloud'.
phuongncn
pushed a commit
to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4
that referenced
this pull request
Apr 28, 2026
Co-authored-by: Iwan Kawrakow <[email protected]>
ljubomirj
pushed a commit
to ljubomirj/llama.cpp
that referenced
this pull request
May 6, 2026
The prompt contains a typo where 'alound' is used instead of 'aloud'.
AlexiAlp
pushed a commit
to minghaop/llama.cpp
that referenced
this pull request
Jun 2, 2026
The prompt contains a typo where 'alound' is used instead of 'aloud'.
ddvnguyen
added a commit
to ddvnguyen/llama.cpp
that referenced
this pull request
Jul 1, 2026
…ra_vortex ggml-org#368) (#23) * fork: bind-on-activation + registry epoch + ne-guard + fail-open (hydra_vortex ggml-org#368) Makes COMBINED zero-copy binding (llama.cpp#20) swap-safe and re-callable in preparation for dynamic quant swap (ggml-org#263, SWAP_QUANT 0x45). Also fixes the COMBINED startup race (hydra_vortex ggml-org#357) by binding on demand at SET_EXPERT_MODE("combined") instead of one-shot at startup. Forward-compatible slice per docs/dynamic-quant-swap-combined.md: this lands the protocol + binding + fail-open + tests now, so ggml-org#263 can plug in the actual model free/reload against a stable contract. ## What ### 1. Registry epoch (ggml-rpc.cpp) - rpc_msg_resolve_tensor_rsp gets a new uint32_t registry_epoch; the server returns its g_hydra_registry_epoch with every resolve. - g_hydra_registry_epoch (atomic<uint32_t>) is bumped on every ggml_backend_rpc_clear_local_tensors() call. A head re-checks ggml_backend_rpc_get_remote_registry_epoch() before each use of a binding; mismatch = stale = the head must rebind or stay solo. ### 2. ggml_backend_rpc_clear_local_tensors New public proc. Clears the local-tensor registry and bumps the epoch. Idempotent. Foreign-buffer clearing is a defense-in-depth follow-up (the head's epoch check is the primary safety). ### 3. ggml_backend_rpc_get_remote_registry_epoch New public proc. Probes the peer's current epoch over RPC (reuses RPC_CMD_RESOLVE_TENSOR with a sentinel name and reads back the epoch field of the response — single round trip). Returns 0 on any failure; callers must treat 0 as "couldn't verify" not "epoch is 0". ### 4. Fail-open in ggml_backend_rpc_bind_remote_tensor Replaced RPC_STATUS_ASSERT(status) (which calls GGML_ABORT) with "if (!status) { log; return nullptr; }" — peer drop, malformed response, or transient RPC error must NOT crash the engine. The bind result is still observable: nullptr means "fall back to solo". ### 5. ne-guard ggml_backend_rpc_bind_remote_tensor takes a new const uint32_t* expected_ne parameter (may be NULL to skip). After resolve, the response's ne[] is compared element-wise; mismatch = refuse the bind (return nullptr) — only type/nb (the quant layout) may differ between bindings; ne (the count along each axis) is structural. A head bound to a different peer's resident model fails loud, not by running on the wrong weights (which would corrupt the KV cache silently). ### 6. llama_hydra_rebind_combined_experts (new) Extracted from llama_hydra_load_combined_experts. Reuses the per-peer backend (which is registered once at startup), frees the previous binding's meta_ctx, allocates a new one, and re-runs the bind loop with the new epoch + ne-guard. Per-peer resource map (s_hydra_combined_bindings) owns the meta_ctx — replacing an entry drops the previous ctx (the per-rebind leak fix; old code pushed ctxs into a static vector and never freed). ### 7. llama_hydra_register_local_tensors_for_rpc re-callable Now calls ggml_backend_rpc_clear_local_tensors before the registration loop. First call: clear is a no-op (epoch 0 → 1). Subsequent calls (after a model swap / re-register on the peer) bump the epoch again, so any outstanding binding becomes observably stale. ### 8. SET_EXPERT_MODE(combined) handler now binds on activation server-context.cpp:3504. Replaces the implicit reliance on a startup-only binding. On each SET_EXPERT_MODE("combined") the head calls llama_hydra_rebind_combined_experts and degrades to solo if the rebind fails (peer unreachable, ne-guard, RPC error). This is the ggml-org#357 fix: the head binds on demand when the peer is reachable, every time. No abort path. ## Tests (test-hydra-rpc-bind.cpp) - original round-trip (zero-copy read of server's live tensor) - registry_epoch in resolve response - ne-guard: rejected bind with mismatched shape (returns null) - ne-guard: NULL expected_ne skips the check (legacy callers) - missing name: returns null - clear → epoch bumps; re-register → epoch unchanged (only clear bumps) - re-bind after clear+re-register succeeds and observes the new epoch - fail-open: bind to unreachable endpoint returns null (no abort) - re-callable register is monotonic (no spurious epoch bump) Run: `./bin/test-hydra-rpc-bind` → "OK: zero-copy RESOLVE_TENSOR/ bind_remote_tensor round-trips correctly (incl. ggml-org#368 epoch, ne-guard, fail-open, re-callable register)" ## Build verification - sm_120 (CUDA 13.2): `cmake --build build_sm120 --target llama-engine test-hydra-rpc-bind` — clean. Test runs and passes. - sm_60 build deferred to P100 host (the AGENTS.md note about the gcc-15 / cuda-12.9 toolchain incompatibility is unchanged). ## Out of scope (lands with ggml-org#263) The actual SWAP_QUANT model free/reload + re-register on the engine (0x45 handler body) — slots into this contract once built. The Core side (WorkerSchedulerService SWAPPING state) is in the parent repo (ddvnguyen/hydra_vortex#368 §3). ## Cross-repo - ddvnguyen/hydra_vortex#368 (parent issue) - ddvnguyen/hydra_vortex#366 (merged — the SOLO_BUSY/COMBINED_SERVING state machine foundation that ggml-org#368 §3 extends) - ddvnguyen/hydra_vortex#357 (startup race — fixed here by bind-on- activation) - #22 (fork-side tracker) AI assistance note: this commit was produced with AI assistance (Claude) under explicit owner direction. Per AGENTS.md the private fork ddvnguyen/llama.cpp is exempt from the upstream llama.cpp AI- submission policy. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(rpc): set registry_epoch on not-found path; bump RPC_PROTO_MINOR_VERSION to 1 P1: rpc_server::resolve_tensor left response.registry_epoch uninitialised on the not-found early return. ggml_backend_rpc_get_remote_registry_epoch probes with a sentinel name that is never found, so it was reading indeterminate stack bytes instead of the real epoch. Fix: populate registry_epoch before the not-found return, inside the lock where g_hydra_registry_epoch is already loaded for the found path. P2: rpc_msg_resolve_tensor_rsp gained a uint32_t registry_epoch field but RPC_PROTO_MINOR_VERSION was not bumped. A new RTX head talking to an old P100 server (not yet rebuilt) would size-mismatch on RESOLVE_TENSOR and silently fail-open to permanent solo with no diagnostic. Fix: bump minor to 1 and tighten negotiate_hello to require an exact minor match (reject both older AND newer peers) so the mismatch is diagnosed at hello, not buried in a silent fail-open. Fixes review findings P1 and P2 on #23. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Hydra Engineering <hydra-engineering@local> Co-authored-by: Claude Opus 4.8 <[email protected]>
ddvnguyen
pushed a commit
to ddvnguyen/llama.cpp
that referenced
this pull request
Jul 1, 2026
Two bugs prevented SET_EXPERT_MODE("combined") from ever activating when
the peer (RTX 3060) came up after the head (RTX 5060 Ti) had already started:
1. server-context.cpp: want_combined was gated on hydra_combined_head_attached,
which is only set true when the startup llama_hydra_load_combined_experts
call succeeds. If the peer was down at boot, the flag stayed false and the
entire bind-on-activation code path (ggml-org#368) was unreachable. Fixed by gating
on "is the engine configured as a combined head" (non-empty peer addr +
OT pattern) instead, which correctly reflects what the engine is configured
to do rather than an accident of startup ordering. Also latches
hydra_combined_head_attached=true on first successful rebind so INFO RPC
advertises combined capability.
2. llama-hydra.cpp: tensor_pattern from --combined-ot-pattern uses the
override-tensor format "<name_regex>=<backend>" (e.g.
"blk\.([0-9]+)\.ffn_.*_exps\.weight=CPU"), but the regex was matched
against raw tensor names which never contain "=CPU". Fixed by stripping
everything from the last '=' onward before compiling the regex.
With both fixes applied: 120/120 expert tensors across 40 layers are bound
to the peer on the first COMBINED request, and the engine reports
applied='combined' instead of falling back to solo.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
ddvnguyen
added a commit
to ddvnguyen/llama.cpp
that referenced
this pull request
Jul 1, 2026
* fork: bind-on-activation + registry epoch + ne-guard + fail-open (hydra_vortex ggml-org#368) Makes COMBINED zero-copy binding (llama.cpp#20) swap-safe and re-callable in preparation for dynamic quant swap (ggml-org#263, SWAP_QUANT 0x45). Also fixes the COMBINED startup race (hydra_vortex ggml-org#357) by binding on demand at SET_EXPERT_MODE("combined") instead of one-shot at startup. Forward-compatible slice per docs/dynamic-quant-swap-combined.md: this lands the protocol + binding + fail-open + tests now, so ggml-org#263 can plug in the actual model free/reload against a stable contract. ## What ### 1. Registry epoch (ggml-rpc.cpp) - rpc_msg_resolve_tensor_rsp gets a new uint32_t registry_epoch; the server returns its g_hydra_registry_epoch with every resolve. - g_hydra_registry_epoch (atomic<uint32_t>) is bumped on every ggml_backend_rpc_clear_local_tensors() call. A head re-checks ggml_backend_rpc_get_remote_registry_epoch() before each use of a binding; mismatch = stale = the head must rebind or stay solo. ### 2. ggml_backend_rpc_clear_local_tensors New public proc. Clears the local-tensor registry and bumps the epoch. Idempotent. Foreign-buffer clearing is a defense-in-depth follow-up (the head's epoch check is the primary safety). ### 3. ggml_backend_rpc_get_remote_registry_epoch New public proc. Probes the peer's current epoch over RPC (reuses RPC_CMD_RESOLVE_TENSOR with a sentinel name and reads back the epoch field of the response — single round trip). Returns 0 on any failure; callers must treat 0 as "couldn't verify" not "epoch is 0". ### 4. Fail-open in ggml_backend_rpc_bind_remote_tensor Replaced RPC_STATUS_ASSERT(status) (which calls GGML_ABORT) with "if (!status) { log; return nullptr; }" — peer drop, malformed response, or transient RPC error must NOT crash the engine. The bind result is still observable: nullptr means "fall back to solo". ### 5. ne-guard ggml_backend_rpc_bind_remote_tensor takes a new const uint32_t* expected_ne parameter (may be NULL to skip). After resolve, the response's ne[] is compared element-wise; mismatch = refuse the bind (return nullptr) — only type/nb (the quant layout) may differ between bindings; ne (the count along each axis) is structural. A head bound to a different peer's resident model fails loud, not by running on the wrong weights (which would corrupt the KV cache silently). ### 6. llama_hydra_rebind_combined_experts (new) Extracted from llama_hydra_load_combined_experts. Reuses the per-peer backend (which is registered once at startup), frees the previous binding's meta_ctx, allocates a new one, and re-runs the bind loop with the new epoch + ne-guard. Per-peer resource map (s_hydra_combined_bindings) owns the meta_ctx — replacing an entry drops the previous ctx (the per-rebind leak fix; old code pushed ctxs into a static vector and never freed). ### 7. llama_hydra_register_local_tensors_for_rpc re-callable Now calls ggml_backend_rpc_clear_local_tensors before the registration loop. First call: clear is a no-op (epoch 0 → 1). Subsequent calls (after a model swap / re-register on the peer) bump the epoch again, so any outstanding binding becomes observably stale. ### 8. SET_EXPERT_MODE(combined) handler now binds on activation server-context.cpp:3504. Replaces the implicit reliance on a startup-only binding. On each SET_EXPERT_MODE("combined") the head calls llama_hydra_rebind_combined_experts and degrades to solo if the rebind fails (peer unreachable, ne-guard, RPC error). This is the ggml-org#357 fix: the head binds on demand when the peer is reachable, every time. No abort path. ## Tests (test-hydra-rpc-bind.cpp) - original round-trip (zero-copy read of server's live tensor) - registry_epoch in resolve response - ne-guard: rejected bind with mismatched shape (returns null) - ne-guard: NULL expected_ne skips the check (legacy callers) - missing name: returns null - clear → epoch bumps; re-register → epoch unchanged (only clear bumps) - re-bind after clear+re-register succeeds and observes the new epoch - fail-open: bind to unreachable endpoint returns null (no abort) - re-callable register is monotonic (no spurious epoch bump) Run: `./bin/test-hydra-rpc-bind` → "OK: zero-copy RESOLVE_TENSOR/ bind_remote_tensor round-trips correctly (incl. ggml-org#368 epoch, ne-guard, fail-open, re-callable register)" ## Build verification - sm_120 (CUDA 13.2): `cmake --build build_sm120 --target llama-engine test-hydra-rpc-bind` — clean. Test runs and passes. - sm_60 build deferred to P100 host (the AGENTS.md note about the gcc-15 / cuda-12.9 toolchain incompatibility is unchanged). ## Out of scope (lands with ggml-org#263) The actual SWAP_QUANT model free/reload + re-register on the engine (0x45 handler body) — slots into this contract once built. The Core side (WorkerSchedulerService SWAPPING state) is in the parent repo (ddvnguyen/hydra_vortex#368 §3). ## Cross-repo - ddvnguyen/hydra_vortex#368 (parent issue) - ddvnguyen/hydra_vortex#366 (merged — the SOLO_BUSY/COMBINED_SERVING state machine foundation that ggml-org#368 §3 extends) - ddvnguyen/hydra_vortex#357 (startup race — fixed here by bind-on- activation) - #22 (fork-side tracker) AI assistance note: this commit was produced with AI assistance (Claude) under explicit owner direction. Per AGENTS.md the private fork ddvnguyen/llama.cpp is exempt from the upstream llama.cpp AI- submission policy. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(rpc): set registry_epoch on not-found path; bump RPC_PROTO_MINOR_VERSION to 1 P1: rpc_server::resolve_tensor left response.registry_epoch uninitialised on the not-found early return. ggml_backend_rpc_get_remote_registry_epoch probes with a sentinel name that is never found, so it was reading indeterminate stack bytes instead of the real epoch. Fix: populate registry_epoch before the not-found return, inside the lock where g_hydra_registry_epoch is already loaded for the found path. P2: rpc_msg_resolve_tensor_rsp gained a uint32_t registry_epoch field but RPC_PROTO_MINOR_VERSION was not bumped. A new RTX head talking to an old P100 server (not yet rebuilt) would size-mismatch on RESOLVE_TENSOR and silently fail-open to permanent solo with no diagnostic. Fix: bump minor to 1 and tighten negotiate_hello to require an exact minor match (reject both older AND newer peers) so the mismatch is diagnosed at hello, not buried in a silent fail-open. Fixes review findings P1 and P2 on #23. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * fix: fail-open on RPC handshake (HELLO) + advertise combined/pipeline in capabilities (hydra_vortex ggml-org#375 ggml-org#376) ## ggml-org#375 — advertise combined/pipeline in engine_info server-context.cpp: the engine_info (0x41) handler now lists 'combined' and 'pipeline' in the capabilities set. The build that ships this binary is always the llama-engine fork, which carries the COMBINED code path; this is the engine-side mirror of the static workers.json fields. ## ggml-org#376 — fail-open on RPC handshake ggml-rpc.cpp: RPC_STATUS_ASSERT in negotiate_hello (line 363) replaced with if(!status){log; return false;}. The TCP connection succeeds before the RPC server's HELLO handler is ready, especially under compose where two llama-engine instances start simultaneously. Aborting on a transient HELLO failure crashes the head for no reason — returning false lets the caller (get_socket -> get_device_count -> add_server) return 0 devs, which keeps the head alive and degrades to solo instead. Refs: ddvnguyen/hydra_vortex#375, ddvnguyen/hydra_vortex#376 Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix: bind-on-activation and OT-pattern stripping for COMBINED mode Two bugs prevented SET_EXPERT_MODE("combined") from ever activating when the peer (RTX 3060) came up after the head (RTX 5060 Ti) had already started: 1. server-context.cpp: want_combined was gated on hydra_combined_head_attached, which is only set true when the startup llama_hydra_load_combined_experts call succeeds. If the peer was down at boot, the flag stayed false and the entire bind-on-activation code path (ggml-org#368) was unreachable. Fixed by gating on "is the engine configured as a combined head" (non-empty peer addr + OT pattern) instead, which correctly reflects what the engine is configured to do rather than an accident of startup ordering. Also latches hydra_combined_head_attached=true on first successful rebind so INFO RPC advertises combined capability. 2. llama-hydra.cpp: tensor_pattern from --combined-ot-pattern uses the override-tensor format "<name_regex>=<backend>" (e.g. "blk\.([0-9]+)\.ffn_.*_exps\.weight=CPU"), but the regex was matched against raw tensor names which never contain "=CPU". Fixed by stripping everything from the last '=' onward before compiling the regex. With both fixes applied: 120/120 expert tensors across 40 layers are bound to the peer on the first COMBINED request, and the engine reports applied='combined' instead of falling back to solo. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Hydra Engineering <hydra-engineering@local> Co-authored-by: Claude Opus 4.8 <[email protected]>
kiljoy001
pushed a commit
to kiljoy001/llama.cpp
that referenced
this pull request
Oct 26, 2026
Co-authored-by: ArtyomITA <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
osabnis
pushed a commit
to osabnis/llama.cpp
that referenced
this pull request
Oct 29, 2026
…_fast_mask_default ggml-openvino: enable NPU L0 host tensors and fast prefill mask by default
imaami
pushed a commit
to imaami/llama.cpp
that referenced
this pull request
Nov 2, 2026
Co-authored-by: ArtyomITA <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 483bdab)
imaami
pushed a commit
to imaami/llama.cpp
that referenced
this pull request
Nov 24, 2026
Co-authored-by: ArtyomITA <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 483bdab)
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 26, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call sites whose signatures moved. The block resolves and builds, but on the re-based tree it GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the four defects that debug turned up. Three of them were silent delivery-code losses. - mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid, as R01/R09 established. - ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu. - mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept. - llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows inverse map plus upstream's embd_row event recording. - tests/test-backend-ops.cpp (2): additive on both sides. Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj` (the J-tile count, consumed directly as grid.x). The dense gate+up pair therefore launched grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past src1_q8_1/dst -> page fault. Both arms now derive ntj like the single-node path; the routed arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1 with the experts in tile_spec. Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean, GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair launches and ntj=4 everywhere else. Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to 1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup` (exclusive count), so the first column-count fix alone produced garbage text. Both fixed: the compact path is reachable, bit-identical to the plain path, and +1.9% prefill (3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps). Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490 lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms (ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate, l2_norm_pair, gate_beta_verify). One of them, the inline SSM conv-input fold, fired on qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying path). Resolved by reconciling into ONE dispatcher: every arm was audited against upstream master; all but the DSV4 hyper-connection post are already owned by the delivery's dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used. Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off / fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree; gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086); test-backend-ops -o MUL_MAT_ID 931/931. Fusion is worth +26% decode on the 4B (87.4 vs 69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4). r279 amendment (GitHub issue ggml-org#308, reported by briansp2020): drain a queued async segmented upload before the synchronous splice. The segmented (fused) tensor arm queues its copies on each device's stream and, when the requested range ends mid-row, queues a zero guard of up to 512 bytes PAST the end of that range (the scheduler's `copy_experts` MMQ pad). A row-aligned chunk of the LOADER's chunked `--load-mode none` upload takes that same arm, and the chunk after it usually starts mid-row, so it falls through to the synchronous splice -- and a synchronous write is not ordered against copies already queued on a device stream. A late guard therefore zeroes the first bytes of the next chunk, i.e. real weight data: two loads of the same file produce different weights (each load internally deterministic, the fingerprint changing between loads -- 2 of 6 loads on stock r273, 1 of 24 on r277 per the report, and a needle answer flips). The backend context now records that an async segmented upload may still be in flight on a model/weights buffer and the synchronous arm drains it first, which also restores the intended order (guard first, then the real bytes overwrite it). `GGML_META_SEG_DRAIN=0` is the A/B/bisect arm and `GGML_META_SEG_DRAIN_LOG=1` prints one census line per drain (a fix whose firing is invisible cannot be gated). Measured on gfx1201: 90 async->sync transitions in ONE 35B-A3B `-sm tensor --load-mode none` load (the protection is not vacuous), and 12 loads -- 6 with the drain, 6 with the kill switch -- gave ONE greedy text, so the change is text-neutral where the race does not bite. Gate: `scripts/gate-meta-seg-drain.sh`. The observed defect rate is ~1/24 loads, so a green series is evidence the ordering gap is closed, not proof it was hit here. r304 (contributor PR ggml-org#322, briansp2020): the GDN gate / beta epilogue for F32 and K-quant ssm_alpha/ssm_beta. A GDN layer's `ssm_alpha` / `ssm_beta` projections feed `ADD(dt) -> SOFTPLUS -> MUL(ssm_a)` and `SIGMOID`. The mmvf fusion this block added only took BF16 projections and the mmvq one only Q8_0, so every other published GGUFs projection type ran each step as its own launch. Extended, one switch per piece: - `GGML_CUDA_FUSE_GATE_BETA_F32` (default on): the mmvf gate/beta launch with `T = float`, each row the plain F32 `mul_mat_vec_f` instantiation and the epilogue `add_softplus_mul_bcast_f32`'s arithmetic. The F32 branch also needs the beta rows' row count (`gb_x2 ? 2*ne01 : ne01`, as BF16 already had) -- without it the appended beta rows overwrite the alpha rows' store region; the new F32 arm of `tests/test-fusion-gate-beta-multiseq.cpp` is a negative-tested control for exactly that (reverting the doubling fails all 11 F32 shapes with maxdiff ~0.7-1.4). - `GGML_CUDA_FUSE_GDN_EPI` (default on): Q4_K / Q5_K / Q6_K / IQ4_XS / MXFP4 projections take the chain in the ksplit body's epilogue (`gdn_epi`, per row-concat segment): decode folds it into the existing alpha/beta/z row concat (3 launches -> 1 per GDN layer), the 2..8-token verify band runs alpha + beta as ONE row concat launch with the epilogue (5 -> 2). Every row keeps its own ksplit dot product (same nwarps / long_k / small_m as its unfused launch, and `launch_ksplit`'s existing rows-per-block fallback keeps every segment boundary a multiple of the block height at these 32-48 row shapes), so both outputs stay bit-identical; the concat reorder above puts the larger `attn_gate` projection in front so the small pair and its chains stay adjacent for that launch. - The epilogue's memory rule replaces the generic window check for this fusion, which declined ~29 of 30 layers because the allocator places the ADD / SOFTPLUS / MUL outputs in place over the alpha matmul output that the fused launch never materializes: what must hold is that `dt` / `ssm_a` are weights (not compute-buffer copies) and that no written tensor overlaps them -- **and, when the activation is already Q8_1, the activation itself** (there is no quantize launch then, so the kernel reads it in place; added on review, the PR kept only the dt/a half). With an F32/F16/BF16 activation the matvec reads only the Q8_1 copy, which is why every write-inside- the-activation placement measured here (the gate MUL lands inside `attn_norm-N` on every GDN layer) is harmless. - `GGML_CUDA_GDN_EPI_LOG=1` prints one line the first time each band fires, from BOTH launch families (`gdn_epi: gate_beta decode|verify ...` from mmvf, `gdn_epi: decode|verify <type> rows ...` from the mmvq epilogue), so a gate can prove the fusions are not inert. - Measured (gfx1201, ROCm 10.1, 1 R9700, `-sm layer`, `ROCBLAS_USE_HIPBLASLT=0`): tg128 114.84/114.92 -> 117.10/117.12 (+1.9 %) on Qwen3.6-35B-A3B UD-Q4_K_M (F32 alpha) and 148.62/148.61 -> 150.21/150.08 (+1.0 %) on the LMStudio Q4_K_M (Q4_K alpha); `llama-batched-bench -npl 1,4,8`: TG +2.1/+1.3/+0.9 % and +0.9/+2.8/+1.8 %, pp512 and the Q8_0-alpha 27B control flat; MTP `draft-mtp n3`: 188.0/208.2 -> 189.8/209.9 t/s. Purity: prefill-logit KLD **-0.000001 / 100.000 %** (F32 arm) and **0.000000 / 100.000 %** (Q4_K arm) at -ub 1, 4 and 8 against a base recorded from the previous build's binary, same-seed greedy text identical on both arms plus the reorder-only Flash-Next IQ4_NL case, `none == draft-mtp` text purity on both builds, no GPU faults; `test-fusion-gate-beta-multiseq` 77/77 shapes (the F32 and Q4_K arms added here). Co-authored-by: burnoutIA <[email protected]> r324 amendment (contributor PR ggml-org#335, reported by briansp2020): the down + weighted-reduction fold takes precedence over the MUL-only down fold, and the expert weighted sum is computed without fma contraction. - Precedence: ggml_cuda_moe_down_fold_try_fuse folded the weighted MUL into the down and thereby set x_scale, which disqualifies the larger fold ggml_cuda_mwr_fold_mark had armed for the same MUL_MAT_ID; the reduction then ran as a second launch per MoE layer. It now stands aside for an armed node (GGML_CUDA_MWR_FOLD_FIRST=0 restores the old precedence; default off outside HIP because nvcc ignores the pragma below, so there the fold would be the LESS exact of the two). - Arithmetic: HIP clang contracts `sum + (x * scale) * w` into an fma, so BOTH the fold and the standalone moe_weighted_reduction_f32_vec4/_f32 kernels rounded differently from the graph's MUL/VIEW/ADD chain -- the shipped build's MoE decode text was NOT the unfused chain's text (measured on qwen35moe, qwen3moe and gemma4). Both now run the accumulation under `#pragma clang fp contract(off)`, behind ONE knob (GGML_CUDA_MWR_EXACT=0 restores the contracted pair; two knobs would let the fold and the kernel it replaces disagree, which is exactly the comparison a bisect must not get wrong). - Soundness: the fold's node conditions moved into ggml_cuda_mwr_fold_serve_ok(), enforced at the ARMING site, so "armed implies servable" is a property of the code: a warp-64 device, n_embd above the counter span, a non-contiguous down output or ne[3] != 1 can no longer make the MUL fold step aside for a fold that declines. - Census (GGML_CUDA_MWR_DEBUG): MWR EXACT exact|contracted, MWR FOLD, MWR FOLD ASIDE, MWR FOLD DECLINE, and the existing MWR FUSED, so the precedence and the arithmetic are observable rather than inferred. Measured (gfx1201, ROCm 10.1, 1 x R9700): KLD against the fully unfused graph at -ub 512 (wikitext-2, 10 x 512) 0.006613 / 96.627 % -> 0.000000 / 100.000 %, with the unfused base logits byte-identical on both builds; same-seed greedy text now equals the fully unfused chain on Qwen3.6-35B-A3B Q4_K_M (1002 ch abed0bf40d87), Qwen3-Coder-30B-A3B Q4_K_M (903 ch fc94447651c1) and gemma-4-26B-A4B Q8_0 (902 ch 6faaaeff2903), where the r323 build read bd111389f051 / 553b730d2e24 / 63f491378b41; dense 4B unchanged (18d8b09cd3d3) and GGML_CUDA_MWR_EXACT=0 GGML_CUDA_MWR_FOLD_FIRST=0 reproduces r323 bit for bit (bd111389f051). tg128 +3.3 % (121.66/121.71 -> 125.90/125.33 t/s), pp512 flat. - r326 (contributor PR ggml-org#336, @overdoingism): GGML_CUDA_GRAPH_MAX_TOKENS (default 16, was MMVQ_MAX_BATCH_SIZE = 8) lets 9..16-token graphs take the graph path, and the FA staging arena may no longer be grown from inside a capture (`ggml_backend_cuda_context::capturing`). A 16-row verify that repeats gains (4-slot server aggregate +3.5 % on gfx1201/ROCm 10.1), a moving width pays a capture per new width, and 9..16-row prefill ubatches are captured too. Gate: scripts/gate-graph-replay-width.sh; knobs: ENVIRONMENT.md 1.1c. Co-Authored-By: overdoingism <[email protected]> - r366 (GitHub issue ggml-org#368, the r362 follow-up): the slab's WIDE (prefill) band is no longer defined by the H2D ring hole. r362 declines the ring region on a pool-backed host-expert tier (nothing stages those tables there), but `ring_armed` -- which `ggml_cuda_slab_wide_available()` and the wide-aux allocator gate on -- was `ring_region > 0 && ...`, so declining the hole silently disabled the whole band: every prefill-only transient (the FA staging arena, the CUDA pool's large allocations, the MMB activation cache, the chunked-GDN/QSA3 wide scratch) fell outside the slab, on the ~1536 MiB outside cushion, and the prefill view was then classified NARROW (the size/mark test also required a carved region), so it learned `narrow_floor` as its own size and the band could never come back. Measured on the field GSQ shape (1 x R9700, `-ncmoe 47 --host-experts pool -ub 8192`, 89199-token L1): 924 wide-aux refusals per prefill and `narrow_floor` 1792 -> 3328 MiB with the r362 layout, 0 refusals and 1792 with this. The band is now armed on the context's wide mark (`ring_requested`) and on the boundary covering the live view, wherever that view was placed; `ggml_cuda_slab_wide_place()` is the single placement rule (above the ring when one is carved, the narrow base when none is) and the seed floor uses it too. The ring hole itself is unchanged: `ggml_cuda_slab_arena_alloc_transient` and `ring_slot_capacity` still require `ring_region > 0`, so a pool tier keeps staging nothing. Text byte-identical (`c9da1e69a0b5` on the shape above, `461ca8cd0e88` on 35B-A3B Q8_0 with and without a ring); measured 2107 t/s prefill / 32.5 t/s decode against 2075 / 30.7 for r365's default and 1982 / 27.3 for the `GGML_CUDA_SLAB_RING_MIB=6144` layout.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 27, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call sites whose signatures moved. The block resolves and builds, but on the re-based tree it GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the four defects that debug turned up. Three of them were silent delivery-code losses. - mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid, as R01/R09 established. - ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu. - mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept. - llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows inverse map plus upstream's embd_row event recording. - tests/test-backend-ops.cpp (2): additive on both sides. Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj` (the J-tile count, consumed directly as grid.x). The dense gate+up pair therefore launched grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past src1_q8_1/dst -> page fault. Both arms now derive ntj like the single-node path; the routed arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1 with the experts in tile_spec. Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean, GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair launches and ntj=4 everywhere else. Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to 1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup` (exclusive count), so the first column-count fix alone produced garbage text. Both fixed: the compact path is reachable, bit-identical to the plain path, and +1.9% prefill (3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps). Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490 lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms (ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate, l2_norm_pair, gate_beta_verify). One of them, the inline SSM conv-input fold, fired on qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying path). Resolved by reconciling into ONE dispatcher: every arm was audited against upstream master; all but the DSV4 hyper-connection post are already owned by the delivery's dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used. Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off / fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree; gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086); test-backend-ops -o MUL_MAT_ID 931/931. Fusion is worth +26% decode on the 4B (87.4 vs 69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4). r279 amendment (GitHub issue ggml-org#308, reported by briansp2020): drain a queued async segmented upload before the synchronous splice. The segmented (fused) tensor arm queues its copies on each device's stream and, when the requested range ends mid-row, queues a zero guard of up to 512 bytes PAST the end of that range (the scheduler's `copy_experts` MMQ pad). A row-aligned chunk of the LOADER's chunked `--load-mode none` upload takes that same arm, and the chunk after it usually starts mid-row, so it falls through to the synchronous splice -- and a synchronous write is not ordered against copies already queued on a device stream. A late guard therefore zeroes the first bytes of the next chunk, i.e. real weight data: two loads of the same file produce different weights (each load internally deterministic, the fingerprint changing between loads -- 2 of 6 loads on stock r273, 1 of 24 on r277 per the report, and a needle answer flips). The backend context now records that an async segmented upload may still be in flight on a model/weights buffer and the synchronous arm drains it first, which also restores the intended order (guard first, then the real bytes overwrite it). `GGML_META_SEG_DRAIN=0` is the A/B/bisect arm and `GGML_META_SEG_DRAIN_LOG=1` prints one census line per drain (a fix whose firing is invisible cannot be gated). Measured on gfx1201: 90 async->sync transitions in ONE 35B-A3B `-sm tensor --load-mode none` load (the protection is not vacuous), and 12 loads -- 6 with the drain, 6 with the kill switch -- gave ONE greedy text, so the change is text-neutral where the race does not bite. Gate: `scripts/gate-meta-seg-drain.sh`. The observed defect rate is ~1/24 loads, so a green series is evidence the ordering gap is closed, not proof it was hit here. r304 (contributor PR ggml-org#322, briansp2020): the GDN gate / beta epilogue for F32 and K-quant ssm_alpha/ssm_beta. A GDN layer's `ssm_alpha` / `ssm_beta` projections feed `ADD(dt) -> SOFTPLUS -> MUL(ssm_a)` and `SIGMOID`. The mmvf fusion this block added only took BF16 projections and the mmvq one only Q8_0, so every other published GGUFs projection type ran each step as its own launch. Extended, one switch per piece: - `GGML_CUDA_FUSE_GATE_BETA_F32` (default on): the mmvf gate/beta launch with `T = float`, each row the plain F32 `mul_mat_vec_f` instantiation and the epilogue `add_softplus_mul_bcast_f32`'s arithmetic. The F32 branch also needs the beta rows' row count (`gb_x2 ? 2*ne01 : ne01`, as BF16 already had) -- without it the appended beta rows overwrite the alpha rows' store region; the new F32 arm of `tests/test-fusion-gate-beta-multiseq.cpp` is a negative-tested control for exactly that (reverting the doubling fails all 11 F32 shapes with maxdiff ~0.7-1.4). - `GGML_CUDA_FUSE_GDN_EPI` (default on): Q4_K / Q5_K / Q6_K / IQ4_XS / MXFP4 projections take the chain in the ksplit body's epilogue (`gdn_epi`, per row-concat segment): decode folds it into the existing alpha/beta/z row concat (3 launches -> 1 per GDN layer), the 2..8-token verify band runs alpha + beta as ONE row concat launch with the epilogue (5 -> 2). Every row keeps its own ksplit dot product (same nwarps / long_k / small_m as its unfused launch, and `launch_ksplit`'s existing rows-per-block fallback keeps every segment boundary a multiple of the block height at these 32-48 row shapes), so both outputs stay bit-identical; the concat reorder above puts the larger `attn_gate` projection in front so the small pair and its chains stay adjacent for that launch. - The epilogue's memory rule replaces the generic window check for this fusion, which declined ~29 of 30 layers because the allocator places the ADD / SOFTPLUS / MUL outputs in place over the alpha matmul output that the fused launch never materializes: what must hold is that `dt` / `ssm_a` are weights (not compute-buffer copies) and that no written tensor overlaps them -- **and, when the activation is already Q8_1, the activation itself** (there is no quantize launch then, so the kernel reads it in place; added on review, the PR kept only the dt/a half). With an F32/F16/BF16 activation the matvec reads only the Q8_1 copy, which is why every write-inside- the-activation placement measured here (the gate MUL lands inside `attn_norm-N` on every GDN layer) is harmless. - `GGML_CUDA_GDN_EPI_LOG=1` prints one line the first time each band fires, from BOTH launch families (`gdn_epi: gate_beta decode|verify ...` from mmvf, `gdn_epi: decode|verify <type> rows ...` from the mmvq epilogue), so a gate can prove the fusions are not inert. - Measured (gfx1201, ROCm 10.1, 1 R9700, `-sm layer`, `ROCBLAS_USE_HIPBLASLT=0`): tg128 114.84/114.92 -> 117.10/117.12 (+1.9 %) on Qwen3.6-35B-A3B UD-Q4_K_M (F32 alpha) and 148.62/148.61 -> 150.21/150.08 (+1.0 %) on the LMStudio Q4_K_M (Q4_K alpha); `llama-batched-bench -npl 1,4,8`: TG +2.1/+1.3/+0.9 % and +0.9/+2.8/+1.8 %, pp512 and the Q8_0-alpha 27B control flat; MTP `draft-mtp n3`: 188.0/208.2 -> 189.8/209.9 t/s. Purity: prefill-logit KLD **-0.000001 / 100.000 %** (F32 arm) and **0.000000 / 100.000 %** (Q4_K arm) at -ub 1, 4 and 8 against a base recorded from the previous build's binary, same-seed greedy text identical on both arms plus the reorder-only Flash-Next IQ4_NL case, `none == draft-mtp` text purity on both builds, no GPU faults; `test-fusion-gate-beta-multiseq` 77/77 shapes (the F32 and Q4_K arms added here). Co-authored-by: burnoutIA <[email protected]> r324 amendment (contributor PR ggml-org#335, reported by briansp2020): the down + weighted-reduction fold takes precedence over the MUL-only down fold, and the expert weighted sum is computed without fma contraction. - Precedence: ggml_cuda_moe_down_fold_try_fuse folded the weighted MUL into the down and thereby set x_scale, which disqualifies the larger fold ggml_cuda_mwr_fold_mark had armed for the same MUL_MAT_ID; the reduction then ran as a second launch per MoE layer. It now stands aside for an armed node (GGML_CUDA_MWR_FOLD_FIRST=0 restores the old precedence; default off outside HIP because nvcc ignores the pragma below, so there the fold would be the LESS exact of the two). - Arithmetic: HIP clang contracts `sum + (x * scale) * w` into an fma, so BOTH the fold and the standalone moe_weighted_reduction_f32_vec4/_f32 kernels rounded differently from the graph's MUL/VIEW/ADD chain -- the shipped build's MoE decode text was NOT the unfused chain's text (measured on qwen35moe, qwen3moe and gemma4). Both now run the accumulation under `#pragma clang fp contract(off)`, behind ONE knob (GGML_CUDA_MWR_EXACT=0 restores the contracted pair; two knobs would let the fold and the kernel it replaces disagree, which is exactly the comparison a bisect must not get wrong). - Soundness: the fold's node conditions moved into ggml_cuda_mwr_fold_serve_ok(), enforced at the ARMING site, so "armed implies servable" is a property of the code: a warp-64 device, n_embd above the counter span, a non-contiguous down output or ne[3] != 1 can no longer make the MUL fold step aside for a fold that declines. - Census (GGML_CUDA_MWR_DEBUG): MWR EXACT exact|contracted, MWR FOLD, MWR FOLD ASIDE, MWR FOLD DECLINE, and the existing MWR FUSED, so the precedence and the arithmetic are observable rather than inferred. Measured (gfx1201, ROCm 10.1, 1 x R9700): KLD against the fully unfused graph at -ub 512 (wikitext-2, 10 x 512) 0.006613 / 96.627 % -> 0.000000 / 100.000 %, with the unfused base logits byte-identical on both builds; same-seed greedy text now equals the fully unfused chain on Qwen3.6-35B-A3B Q4_K_M (1002 ch abed0bf40d87), Qwen3-Coder-30B-A3B Q4_K_M (903 ch fc94447651c1) and gemma-4-26B-A4B Q8_0 (902 ch 6faaaeff2903), where the r323 build read bd111389f051 / 553b730d2e24 / 63f491378b41; dense 4B unchanged (18d8b09cd3d3) and GGML_CUDA_MWR_EXACT=0 GGML_CUDA_MWR_FOLD_FIRST=0 reproduces r323 bit for bit (bd111389f051). tg128 +3.3 % (121.66/121.71 -> 125.90/125.33 t/s), pp512 flat. - r326 (contributor PR ggml-org#336, @overdoingism): GGML_CUDA_GRAPH_MAX_TOKENS (default 16, was MMVQ_MAX_BATCH_SIZE = 8) lets 9..16-token graphs take the graph path, and the FA staging arena may no longer be grown from inside a capture (`ggml_backend_cuda_context::capturing`). A 16-row verify that repeats gains (4-slot server aggregate +3.5 % on gfx1201/ROCm 10.1), a moving width pays a capture per new width, and 9..16-row prefill ubatches are captured too. Gate: scripts/gate-graph-replay-width.sh; knobs: ENVIRONMENT.md 1.1c. Co-Authored-By: overdoingism <[email protected]> - r366 (GitHub issue ggml-org#368, the r362 follow-up): the slab's WIDE (prefill) band is no longer defined by the H2D ring hole. r362 declines the ring region on a pool-backed host-expert tier (nothing stages those tables there), but `ring_armed` -- which `ggml_cuda_slab_wide_available()` and the wide-aux allocator gate on -- was `ring_region > 0 && ...`, so declining the hole silently disabled the whole band: every prefill-only transient (the FA staging arena, the CUDA pool's large allocations, the MMB activation cache, the chunked-GDN/QSA3 wide scratch) fell outside the slab, on the ~1536 MiB outside cushion, and the prefill view was then classified NARROW (the size/mark test also required a carved region), so it learned `narrow_floor` as its own size and the band could never come back. Measured on the field GSQ shape (1 x R9700, `-ncmoe 47 --host-experts pool -ub 8192`, 89199-token L1): 924 wide-aux refusals per prefill and `narrow_floor` 1792 -> 3328 MiB with the r362 layout, 0 refusals and 1792 with this. The band is now armed on the context's wide mark (`ring_requested`) and on the boundary covering the live view, wherever that view was placed; `ggml_cuda_slab_wide_place()` is the single placement rule (above the ring when one is carved, the narrow base when none is) and the seed floor uses it too. The ring hole itself is unchanged: `ggml_cuda_slab_arena_alloc_transient` and `ring_slot_capacity` still require `ring_region > 0`, so a pool tier keeps staging nothing. Text byte-identical (`c9da1e69a0b5` on the shape above, `461ca8cd0e88` on 35B-A3B Q8_0 with and without a ring); measured 2107 t/s prefill / 32.5 t/s decode against 2075 / 30.7 for r365's default and 1982 / 27.3 for the `GGML_CUDA_SLAB_RING_MIB=6144` layout.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 27, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call sites whose signatures moved. The block resolves and builds, but on the re-based tree it GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the four defects that debug turned up. Three of them were silent delivery-code losses. - mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid, as R01/R09 established. - ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu. - mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept. - llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows inverse map plus upstream's embd_row event recording. - tests/test-backend-ops.cpp (2): additive on both sides. Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj` (the J-tile count, consumed directly as grid.x). The dense gate+up pair therefore launched grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past src1_q8_1/dst -> page fault. Both arms now derive ntj like the single-node path; the routed arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1 with the experts in tile_spec. Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean, GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair launches and ntj=4 everywhere else. Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to 1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup` (exclusive count), so the first column-count fix alone produced garbage text. Both fixed: the compact path is reachable, bit-identical to the plain path, and +1.9% prefill (3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps). Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490 lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms (ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate, l2_norm_pair, gate_beta_verify). One of them, the inline SSM conv-input fold, fired on qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying path). Resolved by reconciling into ONE dispatcher: every arm was audited against upstream master; all but the DSV4 hyper-connection post are already owned by the delivery's dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used. Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off / fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree; gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086); test-backend-ops -o MUL_MAT_ID 931/931. Fusion is worth +26% decode on the 4B (87.4 vs 69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4). r279 amendment (GitHub issue ggml-org#308, reported by briansp2020): drain a queued async segmented upload before the synchronous splice. The segmented (fused) tensor arm queues its copies on each device's stream and, when the requested range ends mid-row, queues a zero guard of up to 512 bytes PAST the end of that range (the scheduler's `copy_experts` MMQ pad). A row-aligned chunk of the LOADER's chunked `--load-mode none` upload takes that same arm, and the chunk after it usually starts mid-row, so it falls through to the synchronous splice -- and a synchronous write is not ordered against copies already queued on a device stream. A late guard therefore zeroes the first bytes of the next chunk, i.e. real weight data: two loads of the same file produce different weights (each load internally deterministic, the fingerprint changing between loads -- 2 of 6 loads on stock r273, 1 of 24 on r277 per the report, and a needle answer flips). The backend context now records that an async segmented upload may still be in flight on a model/weights buffer and the synchronous arm drains it first, which also restores the intended order (guard first, then the real bytes overwrite it). `GGML_META_SEG_DRAIN=0` is the A/B/bisect arm and `GGML_META_SEG_DRAIN_LOG=1` prints one census line per drain (a fix whose firing is invisible cannot be gated). Measured on gfx1201: 90 async->sync transitions in ONE 35B-A3B `-sm tensor --load-mode none` load (the protection is not vacuous), and 12 loads -- 6 with the drain, 6 with the kill switch -- gave ONE greedy text, so the change is text-neutral where the race does not bite. Gate: `scripts/gate-meta-seg-drain.sh`. The observed defect rate is ~1/24 loads, so a green series is evidence the ordering gap is closed, not proof it was hit here. r304 (contributor PR ggml-org#322, briansp2020): the GDN gate / beta epilogue for F32 and K-quant ssm_alpha/ssm_beta. A GDN layer's `ssm_alpha` / `ssm_beta` projections feed `ADD(dt) -> SOFTPLUS -> MUL(ssm_a)` and `SIGMOID`. The mmvf fusion this block added only took BF16 projections and the mmvq one only Q8_0, so every other published GGUFs projection type ran each step as its own launch. Extended, one switch per piece: - `GGML_CUDA_FUSE_GATE_BETA_F32` (default on): the mmvf gate/beta launch with `T = float`, each row the plain F32 `mul_mat_vec_f` instantiation and the epilogue `add_softplus_mul_bcast_f32`'s arithmetic. The F32 branch also needs the beta rows' row count (`gb_x2 ? 2*ne01 : ne01`, as BF16 already had) -- without it the appended beta rows overwrite the alpha rows' store region; the new F32 arm of `tests/test-fusion-gate-beta-multiseq.cpp` is a negative-tested control for exactly that (reverting the doubling fails all 11 F32 shapes with maxdiff ~0.7-1.4). - `GGML_CUDA_FUSE_GDN_EPI` (default on): Q4_K / Q5_K / Q6_K / IQ4_XS / MXFP4 projections take the chain in the ksplit body's epilogue (`gdn_epi`, per row-concat segment): decode folds it into the existing alpha/beta/z row concat (3 launches -> 1 per GDN layer), the 2..8-token verify band runs alpha + beta as ONE row concat launch with the epilogue (5 -> 2). Every row keeps its own ksplit dot product (same nwarps / long_k / small_m as its unfused launch, and `launch_ksplit`'s existing rows-per-block fallback keeps every segment boundary a multiple of the block height at these 32-48 row shapes), so both outputs stay bit-identical; the concat reorder above puts the larger `attn_gate` projection in front so the small pair and its chains stay adjacent for that launch. - The epilogue's memory rule replaces the generic window check for this fusion, which declined ~29 of 30 layers because the allocator places the ADD / SOFTPLUS / MUL outputs in place over the alpha matmul output that the fused launch never materializes: what must hold is that `dt` / `ssm_a` are weights (not compute-buffer copies) and that no written tensor overlaps them -- **and, when the activation is already Q8_1, the activation itself** (there is no quantize launch then, so the kernel reads it in place; added on review, the PR kept only the dt/a half). With an F32/F16/BF16 activation the matvec reads only the Q8_1 copy, which is why every write-inside- the-activation placement measured here (the gate MUL lands inside `attn_norm-N` on every GDN layer) is harmless. - `GGML_CUDA_GDN_EPI_LOG=1` prints one line the first time each band fires, from BOTH launch families (`gdn_epi: gate_beta decode|verify ...` from mmvf, `gdn_epi: decode|verify <type> rows ...` from the mmvq epilogue), so a gate can prove the fusions are not inert. - Measured (gfx1201, ROCm 10.1, 1 R9700, `-sm layer`, `ROCBLAS_USE_HIPBLASLT=0`): tg128 114.84/114.92 -> 117.10/117.12 (+1.9 %) on Qwen3.6-35B-A3B UD-Q4_K_M (F32 alpha) and 148.62/148.61 -> 150.21/150.08 (+1.0 %) on the LMStudio Q4_K_M (Q4_K alpha); `llama-batched-bench -npl 1,4,8`: TG +2.1/+1.3/+0.9 % and +0.9/+2.8/+1.8 %, pp512 and the Q8_0-alpha 27B control flat; MTP `draft-mtp n3`: 188.0/208.2 -> 189.8/209.9 t/s. Purity: prefill-logit KLD **-0.000001 / 100.000 %** (F32 arm) and **0.000000 / 100.000 %** (Q4_K arm) at -ub 1, 4 and 8 against a base recorded from the previous build's binary, same-seed greedy text identical on both arms plus the reorder-only Flash-Next IQ4_NL case, `none == draft-mtp` text purity on both builds, no GPU faults; `test-fusion-gate-beta-multiseq` 77/77 shapes (the F32 and Q4_K arms added here). Co-authored-by: burnoutIA <[email protected]> r324 amendment (contributor PR ggml-org#335, reported by briansp2020): the down + weighted-reduction fold takes precedence over the MUL-only down fold, and the expert weighted sum is computed without fma contraction. - Precedence: ggml_cuda_moe_down_fold_try_fuse folded the weighted MUL into the down and thereby set x_scale, which disqualifies the larger fold ggml_cuda_mwr_fold_mark had armed for the same MUL_MAT_ID; the reduction then ran as a second launch per MoE layer. It now stands aside for an armed node (GGML_CUDA_MWR_FOLD_FIRST=0 restores the old precedence; default off outside HIP because nvcc ignores the pragma below, so there the fold would be the LESS exact of the two). - Arithmetic: HIP clang contracts `sum + (x * scale) * w` into an fma, so BOTH the fold and the standalone moe_weighted_reduction_f32_vec4/_f32 kernels rounded differently from the graph's MUL/VIEW/ADD chain -- the shipped build's MoE decode text was NOT the unfused chain's text (measured on qwen35moe, qwen3moe and gemma4). Both now run the accumulation under `#pragma clang fp contract(off)`, behind ONE knob (GGML_CUDA_MWR_EXACT=0 restores the contracted pair; two knobs would let the fold and the kernel it replaces disagree, which is exactly the comparison a bisect must not get wrong). - Soundness: the fold's node conditions moved into ggml_cuda_mwr_fold_serve_ok(), enforced at the ARMING site, so "armed implies servable" is a property of the code: a warp-64 device, n_embd above the counter span, a non-contiguous down output or ne[3] != 1 can no longer make the MUL fold step aside for a fold that declines. - Census (GGML_CUDA_MWR_DEBUG): MWR EXACT exact|contracted, MWR FOLD, MWR FOLD ASIDE, MWR FOLD DECLINE, and the existing MWR FUSED, so the precedence and the arithmetic are observable rather than inferred. Measured (gfx1201, ROCm 10.1, 1 x R9700): KLD against the fully unfused graph at -ub 512 (wikitext-2, 10 x 512) 0.006613 / 96.627 % -> 0.000000 / 100.000 %, with the unfused base logits byte-identical on both builds; same-seed greedy text now equals the fully unfused chain on Qwen3.6-35B-A3B Q4_K_M (1002 ch abed0bf40d87), Qwen3-Coder-30B-A3B Q4_K_M (903 ch fc94447651c1) and gemma-4-26B-A4B Q8_0 (902 ch 6faaaeff2903), where the r323 build read bd111389f051 / 553b730d2e24 / 63f491378b41; dense 4B unchanged (18d8b09cd3d3) and GGML_CUDA_MWR_EXACT=0 GGML_CUDA_MWR_FOLD_FIRST=0 reproduces r323 bit for bit (bd111389f051). tg128 +3.3 % (121.66/121.71 -> 125.90/125.33 t/s), pp512 flat. - r326 (contributor PR ggml-org#336, @overdoingism): GGML_CUDA_GRAPH_MAX_TOKENS (default 16, was MMVQ_MAX_BATCH_SIZE = 8) lets 9..16-token graphs take the graph path, and the FA staging arena may no longer be grown from inside a capture (`ggml_backend_cuda_context::capturing`). A 16-row verify that repeats gains (4-slot server aggregate +3.5 % on gfx1201/ROCm 10.1), a moving width pays a capture per new width, and 9..16-row prefill ubatches are captured too. Gate: scripts/gate-graph-replay-width.sh; knobs: ENVIRONMENT.md 1.1c. Co-Authored-By: overdoingism <[email protected]> - r366 (GitHub issue ggml-org#368, the r362 follow-up): the slab's WIDE (prefill) band is no longer defined by the H2D ring hole. r362 declines the ring region on a pool-backed host-expert tier (nothing stages those tables there), but `ring_armed` -- which `ggml_cuda_slab_wide_available()` and the wide-aux allocator gate on -- was `ring_region > 0 && ...`, so declining the hole silently disabled the whole band: every prefill-only transient (the FA staging arena, the CUDA pool's large allocations, the MMB activation cache, the chunked-GDN/QSA3 wide scratch) fell outside the slab, on the ~1536 MiB outside cushion, and the prefill view was then classified NARROW (the size/mark test also required a carved region), so it learned `narrow_floor` as its own size and the band could never come back. Measured on the field GSQ shape (1 x R9700, `-ncmoe 47 --host-experts pool -ub 8192`, 89199-token L1): 924 wide-aux refusals per prefill and `narrow_floor` 1792 -> 3328 MiB with the r362 layout, 0 refusals and 1792 with this. The band is now armed on the context's wide mark (`ring_requested`) and on the boundary covering the live view, wherever that view was placed; `ggml_cuda_slab_wide_place()` is the single placement rule (above the ring when one is carved, the narrow base when none is) and the seed floor uses it too. The ring hole itself is unchanged: `ggml_cuda_slab_arena_alloc_transient` and `ring_slot_capacity` still require `ring_region > 0`, so a pool tier keeps staging nothing. Text byte-identical (`c9da1e69a0b5` on the shape above, `461ca8cd0e88` on 35B-A3B Q8_0 with and without a ring); measured 2107 t/s prefill / 32.5 t/s decode against 2075 / 30.7 for r365's default and 1982 / 27.3 for the `GGML_CUDA_SLAB_RING_MIB=6144` layout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The prompt contains a typo where 'alound' is used instead of 'aloud'.