Enhance ggml_cuda_mul_mat_cublas with compute type fallback#25680
Enhance ggml_cuda_mul_mat_cublas with compute type fallback#25680theIvanR wants to merge 1 commit into
Conversation
Added support for generic compute type capability fallback in CUDA matrix multiplication.
|
Hi @theIvanR, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
CUDA: Fix BF16 compute type selection on unsupported architecturesProblemWhen running MTP-enabled models on older NVIDIA GPUs (for example Kepler / compute capability 3.5), llama.cpp could crash inside the CUDA backend. The issue was caused by ggml-cuda.cu selecting GGML_TYPE_BF16 as the cuBLAS compute type without verifying that the active GPU actually supported BF16 execution. This was especially noticeable with MTP models because the additional MTP projection layers could request a BF16 compute path that normal inference did not normally hit. On unsupported architectures, this resulted in an invalid cuBLAS execution path instead of a graceful fallback. Affected hardware includes:
PatchThe fix adds a hardware capability validation step after compute type selection and environment override handling. The previous flow was: The patched flow becomes: The patch uses the existing CUDA capability checks: instead of hardcoding architecture-specific checks. Resulting behavior:
This prevents unsupported GPUs from entering invalid BF16 execution paths while preserving BF16 acceleration on modern hardware. Expected performanceTested with:
Observed approximate token generation speeds: The patch restores MTP functionality on older CUDA architectures without requiring BF16 support. Interestingly, on Kepler hardware forcing FP32 compute can outperform FP16 paths. This is likely because Kepler does not have fast FP16 arithmetic, and cuBLAS can select a more optimized FP32 GEMM path instead. NotesThis patch does not disable BF16 globally. It only validates that the requested compute type is supported by the active GPU before dispatching the cuBLAS operation. The intended behavior is: "Use the fastest available compute type, but never select a compute type that the hardware cannot execute." This keeps modern GPUs on BF16/FP16 paths while maintaining compatibility with older CUDA architectures. Patch to ggml-cuda.cu: |
|
My MI50s definitely do not support BF16 and have for the most part always worked with MTP for Q4 and Q8 where they have the most OP/s available. if you are running a full BF16 model then... you seem to be out of compute anyway and should probably prefer a model that uses a native compute type on a GPU with less compute anyway???? Note how MTP hardly speeds anything up at all only about 5-10% when it should be a 50-100% speedup etc... |
|
@cb88 MI50 is an AMD GPU and entirely unrelated to the matter as it is not using Cuda methods. As for speeds, I was using the lowest speed achieved in testing and in some cases speedups can indeed approach 50 percent. EDIT, which one specifically are you using of the MI50's the 16GB or the 32GB? I have heard mixed reviews on these and would be interested in performances you achieve with the same LLM on Vulkan (does it support ROCM?) |
|
This is not a valid problem/fix. Please create an issue with a reproduction |

Added graceful CUDA compute type fallback for MTP on older GPUs
Overview
Adds hardware capability checks for CUDA compute type selection to prevent crashes on older NVIDIA architectures when using MTP models.
The original MTP implementation could select BF16 compute paths on GPUs without BF16 support (e.g. Kepler), resulting in cuBLAS failures. This patch adds a fallback mechanism that automatically selects a supported compute type:
Modern GPUs with BF16 support remain unaffected. In reference to the original MTP PR #22673
Additional information
Tested with Qwen3.6 35B-A3B Q4XL on Tesla K40 (Kepler):
The fix allows MTP inference to run correctly on older CUDA architectures without requiring BF16 support.
Requirements