fix(cuda): increase argmax topk kernel limit from 32 to 64#25
Merged
Conversation
The custom topk_f32 CUDA kernel had a hardcoded K <= 32 limit from fixed-size heap arrays. The Gemma 4 GGUF bakes top_k=64 into its metadata (general.sampling.top_k), which the DFlash reduced verifier passes through to the target model's verification logits as K=64. On CUDA 12.x / pre-CCCL 3.2 builds, the CUB TopK fallback is unavailable, so K=64 hits the custom path and crashes: argmax.cu:557: GGML_ASSERT(K <= 32) failed Increase the register arrays and assertion to K <= 64. Shared memory usage stays well within limits (16 KB at K=64, 32 warps). Bump the CUB auto-threshold to K > 64 so the custom path covers the full top_k=64 range. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Owner
|
Seems legit. Thanks! |
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.
Summary
topk_f32CUDA kernel limit from K ≤ 32 to K ≤ 64 by expanding the fixed-size register arraystop_k=64rangeProblem
On CUDA 12.x / pre-CCCL 3.2 Linux builds, the CUB TopK fallback (
GGML_CUDA_DFLASH_CUB_TOP_K_AVAILABLE) is unavailable because it requires CCCL ≥ 3.2. The customtopk_f32kernel is the only path, and it has a hardcoded K ≤ 32 limit.The Gemma 4 GGUF bakes
general.sampling.top_k = 64into its metadata. The DFlash reduced verifier picks this up and passes K=64 to the target model's verification logits, which hits:This crashes the server on the first inference request with any Gemma 4 model + DFlash on CUDA 12.x builds.
Fix
heap_val[32]/heap_idx[32]→heap_val[64]/heap_idx[64](register arrays, +256 bytes per thread)GGML_ASSERT(K <= 32)→GGML_ASSERT(K <= 64)K > 32→K > 64Shared memory at K=64, 32 warps: ~16 KB — well within the 48 KB default limit. Register pressure increase is modest and causes no issues on tested hardware (RTX 5090, RTX 3090).
Test plan
GGML_CUDA_FA=ON,GGML_CUDA_FA_ALL_QUANTS=ONGGML_ASSERT🤖 Generated with Claude Code