Repository navigation
ggml-cuda: key the MUL_MAT_ID MMVQ batch cap on the compiled arch - #287
danielhanchen wants to merge 2 commits into
Conversation
get_mmvq_mmid_max_batch() compared the device's cc, while the kernel's __launch_bounds__ come from get_mmvq_mmid_max_batch_for_device(), i.e. the __CUDA_ARCH__ the driver actually loaded. Since ggml-org#27828 a P100 (cc 600) is allowed 8 tokens, but a build without sm_60 (e.g. the default 50-virtual;61-virtual list) runs compute_50 PTX there, whose Q4_K MoE kernel is bounded at 160 threads. Launching 6-8 tokens then fails with 'CUDA error: invalid argument' in mul_mat_vec_q_switch_ncols_dst. Use ggml_cuda_highest_compiled_arch(cc), as get_device_table_id() already does. Builds that contain the device's own arch are unchanged.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 838118fdeb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (cc == GGML_CUDA_CC_PASCAL || cc == GGML_CUDA_CC_VOLTA || cc >= GGML_CUDA_CC_ADA_LOVELACE) { | ||
| // Key on the arch the kernels were compiled for, as get_mmvq_mmid_max_batch_for_device does: | ||
| // a P100 running 50-virtual PTX has __launch_bounds__ from the pascal_older table. | ||
| const int arch = ggml_cuda_highest_compiled_arch(cc); |
There was a problem hiding this comment.
Distinguish loadable PTX from real-only cubins
For a valid mixed build such as CMAKE_CUDA_ARCHITECTURES=61-virtual;75-real running on an sm_89 GPU, __CUDA_ARCH_LIST__ loses the -virtual/-real distinction, so this helper returns 750 even though the sm_75 cubin is not binary-compatible with sm_89 and the driver must JIT the compute_61 PTX. The device kernel therefore uses the Pascal/older launch bound while the host selects the Turing cap (for example, Q2_K permits 7 warps instead of 4), recreating the invalid launch this change is intended to prevent. Preserve whether each target supplies PTX or conservatively account for every image the driver can load rather than treating the numerically highest compiled target as the loaded architecture.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reachable from the builds this ships with: every prebuilt profile lists plain arches (real + PTX) or -virtual only, and the upstream default list keeps a PTX target per major, so the highest compiled arch <= cc is what the driver loads. A hand-made real-only cross-major list (61-virtual;75-real on sm_89) also misleads get_device_table_id() and the other ggml_cuda_highest_compiled_arch() callers today; that is a broader pre-existing limitation of CUDA_ARCH_LIST, not something this fix introduces.
| // Key on the arch the kernels were compiled for, as get_mmvq_mmid_max_batch_for_device does: | ||
| // a P100 running 50-virtual PTX has __launch_bounds__ from the pascal_older table. |
There was a problem hiding this comment.
Keep the explanatory comment on one line
The new explanation is a single sentence split after the colon, contrary to the repository rule that comments must not be hard-wrapped or split mid-sentence; collapse it into one comment line so the change follows the required review conventions.
AGENTS.md reference: AGENTS.md:L77-L84
Useful? React with 👍 / 👎.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…lothai#287 (in upstream as ggml-org#31679)
pr-set : repin Inkling, DiffusionGemma, unslothai#251 and unslothai#264 for b12164, drop unslothai#287
Overview
Fixes unslothai/unsloth#14109 (a P100 crashes in
mul_mat_vec_q_switch_ncols_dstwithCUDA error: invalid argumentsince the last update).One file, host side only:
The defect
ggml-org#27828 lets a P100 (cc 600) use MMVQ for MUL_MAT_ID up to 8 tokens. It changed two places that have to agree:
get_mmvq_mmid_max_batch(type, cc): keyed on the device'sccget_mmvq_mmid_max_batch_for_device<type>(): keyed on__CUDA_ARCH__, and it sets the__launch_bounds__ofmul_mat_vec_q_moeThey only agree when the build contains the device's own arch. The
cuda12-legacyprebuilt (and the upstream default list) is50-virtual;61-virtual, with no sm_60, so a P100 runs the compute_50 PTX. That kernel is compiled against thepascal_oldertable, while the host now says 8 tokens:.maxntidin the legacy buildA launch with more threads than
__launch_bounds__is rejected withcudaErrorInvalidValue, which is theinvalid argumentin the report. The.maxntidvalues were read fromcuobjdump -ptxofmmvq.cu.obuilt with the legacy arch list.The fix
Key the host decision on
ggml_cuda_highest_compiled_arch(cc), the arch the driver actually loads, which is whatget_device_table_id(cc)in the same file already does. A build that contains the device's arch getsarch == cc, so nothing changes there. The device code is untouched (the PTX ofmmvq.cu.ois byte identical before and after).Enumerating host cap vs kernel bound over 9 build profiles (the 8 prebuilt CUDA profiles plus the upstream default list), 17 NVIDIA compute capabilities and 21 quant types: 2226 cells, 294 over-launch before, 0 after, and every cell where the build contains the device's arch is unchanged.
Same change as ggml-org#28578, which was closed on 2026-10-05 for not following the PR template (no technical review), before ggml-org#27828 added the Pascal case that makes it reachable on the legacy prebuilt.
Evidence
Tiny random Qwen3-MoE (hidden 256, 8 experts, top-2), pure Q4_K,
llama-bench -ngl 99 -p N -ub N -n 0. Real P100s are no longer handed out by Kaggle (aNvidiaTeslaP100push runs on T4s), so this ran on an RTX PRO 6000 (sm_120), which hits the same mismatch with the legacy build: the driver JITs the compute_61 PTX (pascal_olderbounds) while the host takes the>= ADAbranch (8 tokens).cuda12-legacyprebuilt (what the reporter runs)CUDA error: invalid argumentcuda12-olderprebuilt (contains the device arch, control)Same source as the b11696 prebuilt, built with the legacy arch list (
50-virtual;61-virtual, CUDA 12.8), on a B200 (sm_100, same mismatch):test-backend-ops -o MUL_MAT_ID -b CUDA0cuda12-legacyprebuiltinvalid argumentinvalid argumentCUDA error: invalid argumentThe crash line matches the report exactly:
current device: 0, in function ggml_cuda_kernel_launch at .../ggml-cuda/common.cuh:1743.The first prebuilt carrying ggml-org#27828 is
b11642-mix(2026-10-15);b11541-mixand older are unaffected, which matches "since last update".