Repository navigation
CUDA: fix MMQ memory fault if n_expert >> n_ubatch - #29941
Merged
JohannesGaessler merged 1 commit intoOct 4, 2026
Merged
JohannesGaessler merged 1 commit into
JohannesGaessler merged 1 commit into
Conversation
am17an
approved these changes
Oct 4, 2026
Contributor
Author
IMbackK
approved these changes
Oct 4, 2026
pwilkin
approved these changes
Oct 4, 2026
1 task
5 tasks
Wizard815
pushed a commit
to Wizard815/mx-llama.cpp-Rocm10
that referenced
this pull request
Oct 6, 2026
(cherry picked from commit dd26678)
Wizard815
added a commit
to Wizard815/mx-llama.cpp-Rocm10
that referenced
this pull request
Oct 6, 2026
Picking dd26678 brought in upstream's launch block as well as its one-line size fix, but the fork declares ids_src1/ids_dst/expert_bounds further down, so the block referenced them before their declarations: mmq.cu:251: error: use of undeclared identifier 'ids_src1' The fork already has its own launch inside the chunked workspace path, so the inserted copy was both a duplicate and out of order. Remove it. Upstream's actual change (J_max sized by ne12 rather than ne11) stays. Assisted-by: Hermes Agent
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 8, 2026
(cherry picked from commit dd26678)
4 tasks done
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 14, 2026
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 15, 2026
nickistre
pushed a commit
to nickistre/llama-cpp-turboquant
that referenced
this pull request
Nov 16, 2026
(cherry picked from commit dd26678)
nickistre
pushed a commit
to nickistre/llama-cpp-turboquant
that referenced
this pull request
Nov 16, 2026
(cherry picked from commit fc9ce6b) Ported by hand: this branch predates upstream's prec_src1 plumbing and the mmq_args::ncols_opt field. J_best is now chosen on the host in ggml_cuda_mul_mat_q and passed via mmq_args, and it sizes the src1_q8_1 tail padding and pads ids_dst by J_best-1. Tile selection still optimizes against ne1 (dense) / ne12 (MoE), as mul_mat_q_switch_J did here before; upstream's RDNA3/RDNA4 ncols_opt heuristic is not carried over, so tile choices on any GPU are unchanged. Together with dd26678 (ggml-org#29941) this fixes "CUDA error: an illegal memory access" (Xid 31) in MUL_MAT_ID when op offload streams CPU-resident MoE experts to the GPU (--cpu-moe), seen at ubatch 4096 on sm_75 (upstream issues ggml-org#27792, ggml-org#28241, ggml-org#29847). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
My attention was drawn to these failing test cases by @am17an :
With the CUDA backend they result in an illegal memory access. The issue seems to be a bug in determining how much padding is needed for the temporary q8_1 buffer in the MMQ kernel. It's supposed to be as many extra columns as is the maximum tile width
J. For dense models this is determined bounded bysrc1->ne[1]. For MoE models however the tensor layout is different and it is instead bounded bysrc1->ne[2]. So the MMQ code is using the wrong value which can result in OOB memory accesses if the number of experts is much larger than the physical batch size. And the fix is simply to use the correct value instead.I decided against adding test cases to
test-backend-ops.cppbecause the tensors needed for a reproduction are relatively large and the conditions for this defect to manifest as a bug were highly specific.Requirements