Repository navigation
CUDA: linearize MoE data layout for MMQ/MMF - #31047
Merged
ggerganov merged 3 commits intoNov 5, 2026
Merged
Conversation
francisab
added a commit
to francisab/llama.cpp
that referenced
this pull request
Oct 23, 2026
…screens Assisted-by: GitHub Copilot Co-authored-by: Copilot App <[email protected]>
francisab
added a commit
to francisab/llama.cpp
that referenced
this pull request
Oct 24, 2026
…screens Assisted-by: GitHub Copilot Co-authored-by: Copilot App <[email protected]>
Contributor
|
For the F16 slow-down: The rest LGTM |
am17an
approved these changes
Oct 25, 2026
Contributor
|
I think this is good, but it needs to be rebased and has significant conflicts. |
francisab
added a commit
to francisab/llama.cpp
that referenced
this pull request
Oct 28, 2026
…ash-Next and 27B Assisted-by: GitHub Copilot Co-authored-by: Copilot App <[email protected]>
|
I found this PR while doing research and deployed and tested. Qwen3.8-Flash-Next (512 experts) - Have ~6.1 gain on prompt processing (2,048 tokens). |
francisab
added a commit
to francisab/llama.cpp
that referenced
this pull request
Oct 28, 2026
Assisted-by: GitHub Copilot Co-authored-by: Copilot App <[email protected]>
JohannesGaessler
force-pushed
the
cuda-mmq-linearized-2
branch
from
November 3, 2026 15:51
bea596f to
49c92b9
Compare
Contributor
Author
|
I pushed a rebased version with the conflicts resolved, please re-review. |
Contributor
Author
|
I forgot: I also applied the patch suggested by @am17an . |
JohannesGaessler
force-pushed
the
cuda-mmq-linearized-2
branch
from
November 5, 2026 08:16
49c92b9 to
3acdd10
Compare
Member
|
Ran a few queries on my RTX 5090 machine - haven't spotted any problems and the PP perf is slightly better. |
adderek
pushed a commit
to adderek/llama.cpp
that referenced
this pull request
Nov 5, 2026
350 upstream commits. Conflicts and how they were resolved: - ggml type ids: upstream numbers GGML_TYPE_F8_E4M3 43, which the fork's TURBO3_0 already holds (TURBO2/3/4 and TQ3_1S/TQ4_1S are 43-47). The fork keeps its ids so existing TQ*_1S GGUFs still load; F8_E4M3 is 48, GGML_TYPE_COUNT 49, and gguf-py's GGMLQuantizationType.F8_E4M3 matches. An upstream-written FP8 GGUF would therefore read its type-43 tensors as turbo3; the model loader now refuses any weight of a turbo KV type with a message naming the cause. LLAMA_FTYPE_MOSTLY_F8_E4M3 (42) does not collide. - MUL_MAT_ID: upstream lets id -1 skip a slot on CPU (ggml-org#26631, CUDA left out). The CPU and repack paths take both: -1 always, and any id < 0 for the fork's partial mul_mat_id (MoE tiering). - CUDA MoE layout: upstream replaced expert_bounds with tile_spec (ggml-org#31047). The fork's partial mul_mat_id skips rows, so the compact column range is shorter and the seam tiles past its end are never written; mmq.cu and mmf.cu zero tile_spec for partial calls (a zero tile has col_low == col_high and the kernels skip it). The forward/inverse id map memsets are kept. - CUDA graphs: upstream captures in chunks and launches each chunk as soon as it is captured (ggml-org#30804). The fork's out-of-memory fallback moves into ggml_cuda_graph_launch_chunk: an OOM instantiation returns false without launching, the graph is marked disable_due_to_oom, its executables are destroyed, the capture lock released, and evaluation restarts directly from the first node of the failed chunk (the chunks before it have run). Checked by faking the OOM at a mid-graph chunk and at the last one: greedy output identical to graphs on and off, warning printed once. - mmq: IQ1_M stays off MMQ on RDNA3 (fork); its tile loader gains upstream's x_gate parameter and its write-back the has_fusion flag. - fattn-mma-f16: upstream's AMD_WMMA_256B_AVAILABLE guard with the fork's VKQ_C sizing. - llama-graph: TurboQuant Q pre-rotation kept on every attention path, with upstream's kv_rows argument and per-layer self_v_rot. Sparse MLA takes upstream's n_embd_v (v_cur may be null) for the V view and for the padded-head trim. build_lora_mm_id: partial assert, then upstream's cur_mm (Hadamard input for the folded weight, raw cur for LoRA). - kv-cache: buffers go through upstream's llama_memory_bufs::emplace, which clears them; the TurboQuant rotation matrices are filled after it, gated on the cache's own no_alloc (hparams.no_alloc is gone). - hybrid-idx: no-turbo indexer types with upstream's no_alloc and without the removed n_pad. - qwen4exp: turbo Q pre-rotation before upstream's per-stream selection. - server: keep_heap_mapped() moved into upstream's refactored llama_server(); the prompt-cache retire list uses common_state_data. - tests/CMakeLists.txt: upstream moved the model tests out of the non-Windows-shared block; the fork's moe-tier and turbo-kv tests stay guarded by it. test-moe-tier writes its keys with llama_arch_kv_name since llama_model_saver lost its (arch, gguf) constructor. - test-backend-ops: fork's partial mul_mat_id cases and upstream's small-K cases both kept; turbo3/turbo4 added to the new kv_rows FA cases. kv_rows FlashAttention is NVIDIA-only upstream; on ROCm the context probe falls back to the dense mask, so the turbo kv_rows cases report "not supported" there, as the f16 ones do. Tested on gfx1100: ctest 83/87, the four failures environmental (ggml-vocabs git-lfs pointers; system python lacks jinja2 and numpy - test_conversion_fp8 passes 15/15 under uv). test-backend-ops MUL_MAT_ID 931/931, MUL_MAT 2517/2517, FLASH_ATTN_EXT 4040/4040. llama-bench turbo4 KV vs master, pp512/tg128: Ornith-1.5-9B 3114/99.0 vs 3044/99.9, Qwen3.6-35B-A3B 3794/98.1 vs 3477/97.1 (pp noise +-160-390).
Kmic-68
pushed a commit
to Kmic-68/llama.cpp
that referenced
this pull request
Nov 7, 2026
…06) into the P100 fork Conflicts and what was kept: - KQ mask: upstream's llm_attn_mask / kv_rows refactor (ggml-org#29510). Our compact I32 causal mask is handled in llama_kv_cache_context::set_input_attn_mask; the single-sequence fast mask fill only runs when the mask columns are the cells (no kv_rows). kv_rows attention is MMA-only, so on sm_60 the probe reports it unsupported and the dense/compact mask path is used as before. - MoE layout: took upstream's linearized MMQ/MMF MoE data layout (ggml-org#31047) in mmid.cu, mmf.cuh, mmq.cuh. It replaces our repeated-expert-id handling there (63924ad); upstream keeps those test cases disabled and top-k routers never repeat an expert. The cuBLAS sort path keeps its fix. The opt-in fp16 MoE GEMM (GGML_CUDA_P60_MOE_GEMM=1) now builds its jobs from the helper's tile list; the math is unchanged. - mmq.cu: upstream applies the tokens-per-expert tile sizing to every arch (ours did it on sm_60 only). - scale.cu: upstream's strided rewrite plus our scale == 0 -> bias rule. - common_state_data (upstream) is an alias of our common_ckpt_buffer, so state buffers keep the pooled, huge-page, no-zero-fill allocator. Checkpoints are ref-counted upstream now (ggml-org#30137): our keep-the-just-restored-checkpoint path claims it through the const pointer, except a slot-file one. - MTP: upstream's mem-shared (gemma4) verify rows merged with our verify_pos0/pending_pos bookkeeping; upstream's own MTP get_state/set_state dropped in favour of ours (position + row, resets stale state). - fattn: the q4p kernel takes upstream's new KV_rows argument (unused). qwen35 MTP K/V-only path uses the per-layer K/V rotations (ggml-org#31073). Math: with upstream's softplus log1pf change (74bca39) reverted as a diagnostic, logits match the pre-merge build exactly (27B Q6_K -c 4096 x 8: KLD -0.000006, same top 100 %; -ub 1: KLD 0). Kept: it moves the Qwen3.8 GDN gate (KLD 0.001-0.003) and reads no worse against the fp32 reference (Q5_K_M -ub 1: KLD 0.001713 vs 0.001779). Upstream's q8_1 correction-sum fix (8fc0376) moves only the MTP head, whose weights are Q4_0: greedy-draft MTP text and acceptance are identical to the base, the draft probabilities move, and the quantized sum is the more exact one (simulated Q4_0 x q8_1 dot: RMS error 0.58 vs 1.44). Kept. OPTLOG 329. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AaVsfEiPALnEHpNH9UZbjk
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 8, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that upstream ggml-org#31047 replaced by tile specs - deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the llm_attn_mask raw mask, build_attn_mha's kv_rows argument - llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit) - kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510) - graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition Co-Authored-By: Claude Opus 5.5 <[email protected]>
wispoffates
added a commit
to wispoffates/llama.cpp
that referenced
this pull request
Nov 8, 2026
… off Upstream ggml-org#31047 sizes the MUL_MAT_ID tile by tokens per expert on every GPU (what Kane's sm_60 tile did in v5.37). The env opt-out stays as the A/B switch: GGML_CUDA_MMQ_MOE_TPE=0 sizes the tile against all ubatch tokens again. Assisted-by: Claude Opus 5.5 (Claude Code)
wispoffates
added a commit
to wispoffates/llama.cpp
that referenced
this pull request
Nov 8, 2026
) ggml-org#31047 changed ggml_cuda_launch_mm_ids_helper to emit tile specs (expert, col_low, col_high) instead of per-expert bounds. The tile GEMM keeps its own tiling: tile_mm_id_tiles now counts the ids per expert in shared memory (ids below 0 first, as the helper's compact layout orders them) and writes the bounds next to the tile list, in the same single launch. The helper's tile specs go to a scratch buffer. Compact layout and tiles unchanged -> same results. Assisted-by: Claude Opus 5.5 (Claude Code)
wispoffates
added a commit
to wispoffates/llama.cpp
that referenced
this pull request
Nov 8, 2026
…f659f2); Kane's MMQ tile now upstream (ggml-org#31047) CREDITS and SETTINGS note that upstream ggml-org#31047 sizes the MoE MMQ tile per expert on every GPU, so the series carries only the GGML_CUDA_MMQ_MOE_TPE=0 switch; SETTINGS gains the v5.41 bullet (ggml-org#31047, ggml-org#30137 shared checkpoints, llama-bench decode note). Assisted-by: Claude Opus 5.5 (Claude Code)
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 11, 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).
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 11, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that upstream ggml-org#31047 replaced by tile specs - deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the llm_attn_mask raw mask, build_attn_mha's kv_rows argument - llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit) - kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510) - graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition Co-Authored-By: Claude Opus 5.5 <[email protected]>
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 12, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that upstream ggml-org#31047 replaced by tile specs - deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the llm_attn_mask raw mask, build_attn_mha's kv_rows argument - llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit) - kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510) - graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 12, 2026
Re-based onto a691b23. Applied clean, but its routed path called the pre-re-base `ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only). The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it gained an optional `expert_bounds` output that MMB keeps using: one compaction serves MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and routed-GLU) allocate the tile_spec buffer they do not read. No MMB kernel logic changed. Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1 routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`); `GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 12, 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).
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 12, 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).
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 12, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that upstream ggml-org#31047 replaced by tile specs - deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the llm_attn_mask raw mask, build_attn_mha's kv_rows argument - llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit) - kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510) - graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 12, 2026
Re-based onto a691b23. Applied clean, but its routed path called the pre-re-base `ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only). The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it gained an optional `expert_bounds` output that MMB keeps using: one compaction serves MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and routed-GLU) allocate the tile_spec buffer they do not read. No MMB kernel logic changed. Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1 routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`); `GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 12, 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).
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 12, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that upstream ggml-org#31047 replaced by tile specs - deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the llm_attn_mask raw mask, build_attn_mha's kv_rows argument - llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit) - kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510) - graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 12, 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).
1 task done
PapyKahan
added a commit
to PapyKahan/llama.cpp
that referenced
this pull request
Nov 13, 2026
Upstream's version is kept wherever it does what the branch did; the branch's stays where upstream has none: - MoE cache: upstream's ClassLRU replaces the SLRU (ggml-org#31233) and takes the branch's pending and exclusive slots, tail skip and background admissions; the misses left to the CPU are upstream's (ggml-org#30966 as merged, ggml-org#31888: a second slot map, the scheduler prefetching the inputs), which replaces the branch's stash and CPU part registration, and the scheduler's copy callback is upstream's again. Host mode, phases and the service policy as before. - build_moe_ffn: upstream's slots and CPU ids from build_moe_cache_slots, the host and batch parts before them. - CUDA MMQ and MMF: upstream's tile specs (ggml-org#31047, ggml-org#32067) replace the branch's tile map; the counting sort of the ids writes them, and they are zeroed first when ids may be negative. The marker of negative ids moves to its own op parameter, off the accumulator precision's. - CUDA flash attention: padded head sizes (ggml-org#30285) in the kernel with the in-place quantized loaders; a quantized cache keeps the dense mask instead of kv_rows (ggml-org#29510), which those loaders do not take. - lightning indexer: upstream's MMA kernel (ggml-org#31803, ggml-org#29050) with the branch's row indices. - MMVF for few rows: upstream's rule (ggml-org#31959) after the branch's switch. - recurrent models: upstream's conv state store in one set_rows (ggml-org#31660) with the branch's state marks; the fused delta net only (ggml-org#32078). - qwen4exp: QSA without the kq_mask as upstream, with the branch's query chunks; rope through build_rope (ggml-org#31683). - context: the scheduler is reused across reserves (ggml-org#32009) but not across the phases of the MoE cache, which give back each other's compute buffers; graph slots are reset with either. - MTP: the target rows on the device (ggml-org#31927) stay off with the background catch-up, which reads them while the target decodes its next batch. - server: checkpoints by reference (ggml-org#30137), a reused one is taken over through a mutable task id. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_016qCoLqWgrDtkf9nYBJgAyJ
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 13, 2026
… allocator fixes Groundwork block (multiple base-level concerns, by design): - FA KV-split width invariance (launch_fattn, n_q <= 8) - shared-NextN MTP heads keep their own KV (is_mem_shared gate) - CPU llamafile_sgemm routes n <= 8 to vec_dot (decode/verify band unity) - single-device -sm tensor skips the Meta wrapper - meta-buffer compute-container headroom 16 -> 128 (recurrent snapshot views) - multi-ubatch logits readback ordering (async D2H race) - ggml-alloc: release view sources whose views are never consumed (W4) - ggml-alloc: reuse the recorded layout only for the graph it was computed for (graph fingerprint; delivery repo issue ggml-org#183) Sources: old 00, 05, 07, 09a(compute headroom), 06(readback), 15(W4). Also carries two generic upstream foundation changes: - the upstream MUL_MAT_ID duplicate-ids fix (upstream/UPSTREAM-PR-mul-mat-id-dup.patch, re-cut against the post-ggml-org#31047 tile_spec grid): mm_ids_helper keeps every occurrence of a repeated expert id as its own compact row. The compact column count is then exactly n_tokens*n_expert_used, so every column has its own tile_spec entry and upstream's per-tile grid covers the expanded list -- the in-kernel column-tile loop this fix used to need is gone, and upstream's seam writer is reused verbatim (one tile_spec entry per expert against the n_experts trailing slots). The host sorted fallback emits every match. Fixes the test-backend-ops MUL_MAT_ID dup=1 failures and the quantize_mmq_q8_1 page fault; validated after the merge with `test-backend-ops -o MUL_MAT_ID` 931/931 on gfx1201. Applied here so every later MUL_MAT_ID block builds on correct duplicate handling. - cache the pre-existing upstream env reads that sit on hot paths in function-local statics: GGML_CUDA_CUBLAS_COMPUTE_TYPE (per cuBLAS matmul), GGML_CUDA_ENABLE_UNIFIED_MEMORY (per device allocation), GGML_CUDA_REGISTER_HOST, GGML_CUDA_NO_PINNED, LLAMA_GRAPH_INPUT_DEBUG (per graph input) and LLAMA_BATCH_DEBUG (per batch). getenv() is expensive on Windows. Also fixes delivery repo issue ggml-org#183. ggml_gallocr_alloc_graph() re-applied the recorded node_allocs/leaf_allocs positionally and invalidated them only on a node/leaf count or a per-node size change, so a graph with the same node count but a different node order, op/shape set or output marking inherited a layout computed for a different graph. In-graph sampling (build_sampling + ggml_build_forward_select, one chain per sequence x output row) is exactly such a graph: selecting another sequence's chain keeps the node count and changes which top_k tensors are outputs, so with the second scheduler on a --parallel server the newly active candidate-id tensors all landed on one recycled block and every output row read the last computed ids. DFlash drafting therefore produced correct drafts only for the first slot that served a request. The allocator now records an FNV-1a fingerprint of the graph its layout belongs to (node/leaf order, op, type, ne[], view_src, INPUT/OUTPUT/COMPUTE flags, node/leaf split) and re-reserves on a mismatch; it only ever adds a re-reserve, never skips one. Also extend the -Wshadow sweep to the remaining upstream shadowing declarations the clang build reports (all present at the fork point): step35.cpp per-layer n_embd_k_gqa/n_embd_v_gqa, llama-moe-cache.cpp init_ctx, llama-vocab.cpp _try_copy, llama-quant.cpp layer_info, and llama-model.cpp make_gpu_buft_list / get_tensor. Fold (r86): beta 13, meta-hot-dispatcher (issue ggml-org#184). The split-state dispatcher is back to the exact pre-ggml-org#170 shape and the ggml-org#170 alias/host resolution lives in a noinline, cold helper. Measured zero (-0.06 %, greedy text identical, 4 concurrent streams on 2x R9700); the dispatcher drops 454 -> 287 B. Rename-only -Wshadow sweeps are not carried as part of this block: they re-skin every re-base conflict in the files later blocks also touch and silence a warning class that is not an error (the llama target keeps -Wshadow enabled for new code).
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 13, 2026
Re-based onto a691b23. Applied clean, but its routed path called the pre-re-base `ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only). The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it gained an optional `expert_bounds` output that MMB keeps using: one compaction serves MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and routed-GLU) allocate the tile_spec buffer they do not read. No MMB kernel logic changed. Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1 routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`); `GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 13, 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).
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 14, 2026
… allocator fixes Groundwork block (multiple base-level concerns, by design): - FA KV-split width invariance (launch_fattn, n_q <= 8) - shared-NextN MTP heads keep their own KV (is_mem_shared gate) - CPU llamafile_sgemm routes n <= 8 to vec_dot (decode/verify band unity) - single-device -sm tensor skips the Meta wrapper - meta-buffer compute-container headroom 16 -> 128 (recurrent snapshot views) - multi-ubatch logits readback ordering (async D2H race) - ggml-alloc: release view sources whose views are never consumed (W4) - ggml-alloc: reuse the recorded layout only for the graph it was computed for (graph fingerprint; delivery repo issue ggml-org#183) Sources: old 00, 05, 07, 09a(compute headroom), 06(readback), 15(W4). Also carries two generic upstream foundation changes: - the upstream MUL_MAT_ID duplicate-ids fix (upstream/UPSTREAM-PR-mul-mat-id-dup.patch, re-cut against the post-ggml-org#31047 tile_spec grid): mm_ids_helper keeps every occurrence of a repeated expert id as its own compact row. The compact column count is then exactly n_tokens*n_expert_used, so every column has its own tile_spec entry and upstream's per-tile grid covers the expanded list -- the in-kernel column-tile loop this fix used to need is gone, and upstream's seam writer is reused verbatim (one tile_spec entry per expert against the n_experts trailing slots). The host sorted fallback emits every match. Fixes the test-backend-ops MUL_MAT_ID dup=1 failures and the quantize_mmq_q8_1 page fault; validated after the merge with `test-backend-ops -o MUL_MAT_ID` 931/931 on gfx1201. Applied here so every later MUL_MAT_ID block builds on correct duplicate handling. - cache the pre-existing upstream env reads that sit on hot paths in function-local statics: GGML_CUDA_CUBLAS_COMPUTE_TYPE (per cuBLAS matmul), GGML_CUDA_ENABLE_UNIFIED_MEMORY (per device allocation), GGML_CUDA_REGISTER_HOST, GGML_CUDA_NO_PINNED, LLAMA_GRAPH_INPUT_DEBUG (per graph input) and LLAMA_BATCH_DEBUG (per batch). getenv() is expensive on Windows. Also fixes delivery repo issue ggml-org#183. ggml_gallocr_alloc_graph() re-applied the recorded node_allocs/leaf_allocs positionally and invalidated them only on a node/leaf count or a per-node size change, so a graph with the same node count but a different node order, op/shape set or output marking inherited a layout computed for a different graph. In-graph sampling (build_sampling + ggml_build_forward_select, one chain per sequence x output row) is exactly such a graph: selecting another sequence's chain keeps the node count and changes which top_k tensors are outputs, so with the second scheduler on a --parallel server the newly active candidate-id tensors all landed on one recycled block and every output row read the last computed ids. DFlash drafting therefore produced correct drafts only for the first slot that served a request. The allocator now records an FNV-1a fingerprint of the graph its layout belongs to (node/leaf order, op, type, ne[], view_src, INPUT/OUTPUT/COMPUTE flags, node/leaf split) and re-reserves on a mismatch; it only ever adds a re-reserve, never skips one. Also extend the -Wshadow sweep to the remaining upstream shadowing declarations the clang build reports (all present at the fork point): step35.cpp per-layer n_embd_k_gqa/n_embd_v_gqa, llama-moe-cache.cpp init_ctx, llama-vocab.cpp _try_copy, llama-quant.cpp layer_info, and llama-model.cpp make_gpu_buft_list / get_tensor. Fold (r86): beta 13, meta-hot-dispatcher (issue ggml-org#184). The split-state dispatcher is back to the exact pre-ggml-org#170 shape and the ggml-org#170 alias/host resolution lives in a noinline, cold helper. Measured zero (-0.06 %, greedy text identical, 4 concurrent streams on 2x R9700); the dispatcher drops 454 -> 287 B. Rename-only -Wshadow sweeps are not carried as part of this block: they re-skin every re-base conflict in the files later blocks also touch and silence a warning class that is not an error (the llama target keeps -Wshadow enabled for new code).
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 14, 2026
Re-based onto a691b23. Applied clean, but its routed path called the pre-re-base `ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only). The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it gained an optional `expert_bounds` output that MMB keeps using: one compaction serves MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and routed-GLU) allocate the tile_spec buffer they do not read. No MMB kernel logic changed. Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1 routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`); `GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 14, 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.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 14, 2026
Re-based onto a691b23. Applied clean, but its routed path called the pre-re-base `ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only). The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it gained an optional `expert_bounds` output that MMB keeps using: one compaction serves MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and routed-GLU) allocate the tile_spec buffer they do not read. No MMB kernel logic changed. Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1 routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`); `GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 14, 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.
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 14, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that upstream ggml-org#31047 replaced by tile specs - deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the llm_attn_mask raw mask, build_attn_mha's kv_rows argument - llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit) - kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510) - graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 14, 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.
stew675
pushed a commit
to stew675/llama.cpp
that referenced
this pull request
Nov 14, 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.
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.
This PR changes the data layout for the MMQ and MMF CUDA kernels. Instead of just lower and upper bounds for the columns assigned to each expert the helper kernel in
mmid.cunow pre-computes the assignment of tiles. This way you can get by with fewer tiles that can potentially run in the main kernel so there is less overhead. Also you can more flexibly distribute the tiles across experts which is needed as a prerequisite for a simple implementation of duplicate expert IDs in the CUDA backend (without causing a 10-20% performance regression). Other than the expert tile layout the only other functional change is that I am also enabling the optimization for RDNA 3/4 that prefers smaller tiles for other GPUs as well; previously this was not beneficial due to the increased overhead. The performance improvements from the new data layout are 2-4%, the rest is from the smaller tiles (so less compute is wasted). For Granite 3.0 the performance changes are relatively noisy because whether or not the fixup kernel runs has a large impact on the total runtime. Other than the previous points I have refactored the MMQ code a bit more generally to fit better with the new data structures.Performance tiny MoE
Table generated with
scripts/compare-llama-bench.pyPerformance mid-sized MoE
Table generated with
scripts/compare-llama-bench.pyPerformance check dense
Table generated with
scripts/compare-llama-bench.pyRequirements