Repository navigation
[1/2] cuda: check mmvf applies before the AMD MUL_MAT_ID shortcut - #334
Merged
TheTom merged 1 commit intoSep 3, 2026
Merged
Conversation
ggml_cuda_mul_mat_id() has an AMD-only fast path that calls ggml_cuda_mul_mat_vec_f() directly for non-quantized experts. Unlike the non-id path, it never consulted ggml_cuda_should_use_mmvf(), which is the predicate for what that kernel actually requires: an even column count and strides aligned to twice the type size. An expert matrix with an odd k therefore reached the kernel and tripped its GGML_ASSERT(ncols % 2 == 0). test-backend-ops hits this on an f32 MUL_MAT_ID case with n=1 and k=3, so the entire MUL_MAT_ID suite aborted on AMD before reaching any later type, including every TurboQuant case. Consult the predicate, and fall through to the sorted-routing path below when it declines. `test-backend-ops -o MUL_MAT_ID` now completes on an MI210 with 979/979 passing, where before it dumped core after 11 cases. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01NxP6x5bmUDYFvmouceN2mR
This was referenced Aug 31, 2026
TheTom
merged commit Sep 3, 2026
f737363
into
TheTom:feature/turboquant-kv-cache
6 of 21 checks passed
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.
Overview
ggml_cuda_mul_mat_id()has an AMD-only shortcut that callsggml_cuda_mul_mat_vec_f()directly for non-quantized experts. Unlike the non-id path (which reaches the kernel viaggml_cuda_should_fuse_mul_mat_vec_f→ggml_cuda_should_use_mmvf), this shortcut never consulted that predicate — andggml_cuda_should_use_mmvf()is precisely what rejects the shapes the kernel cannot take: an odd column count (src0_ne[0] % 2 != 0) and strides not aligned to twice the type size.An expert matrix with an odd
ktherefore reached the kernel and trippedGGML_ASSERT(ncols % 2 == 0)inmmvf.cu.This is not hypothetical.
test-backend-ops -o MUL_MAT_IDhits it in theall_typessweep atwhere f32 gives
k = 3. On an MI210 the suite dumps core after 11 cases, so every later type — including all of the TurboQuant MUL_MAT_ID coverage — never ran.The fix consults the existing predicate, and falls through to the sorted-routing path below when it declines.
Additional information
test-backend-ops -o MUL_MAT_IDon an MI210 (gfx90a), ROCm 7.2.3:This is another instance of the pattern AGENTS.md already documents — "A green run means the cases that ran passed, not that your change was exercised." Here it is worse than a silent skip: the process aborts, so the TQ3_1S/TQ4_1S MUL_MAT_ID sweep has not been executing on AMD at all.
Found while validating TurboQuant MoE work across CDNA2 / RDNA3 / RDNA2. The fix itself is independent of TurboQuant and applies to any non-quantized MoE expert tensor with an odd
kon an AMD backend.Requirements
test-backend-opscore dump, traced it to the missingggml_cuda_should_use_mmvf()check, wrote this patch and its commit message, and ran the before/after verification on the MI210. I reviewed the change and am responsible for every line of it. (I'm actually having surgery on my arm tomorrow; after that and some recovery hopefully typing will be less of a problem and I won't need to lean so heavily on the mechanical assistance.)