Skip to content

cuda: fix grid.y overflow in non-contiguous dequantize/convert kernels - #19999

Merged
am17an merged 1 commit into
ggml-org:masterfrom
oobabooga:fix-cuda-grid-y-overflow
Mar 1, 2026
Merged

am17an merged 1 commit into
ggml-org:masterfrom
oobabooga:fix-cuda-grid-y-overflow

Conversation

@oobabooga

Copy link
Copy Markdown
Contributor

The dequantize_block and convert_unary kernels pass ne01 directly as the CUDA grid y-dimension, but grid.y is limited to 65535. When ne01 exceeds this, the kernel launch fails with cudaErrorInvalidConfiguration.

This happens when using llama-server with flash attention, quantized KV cache, multiple parallel slots, and long context. With multiple slots the KV caches are non-contiguous, so the NC dequantization path is taken, and ne01 (the KV cache length) ends up as grid.y.

The grid.z dimension was already capped at 65535 with a grid-stride loop. This applies the same pattern to grid.y.

Closes #19487
Closes #19724

Reproduction

# Start server with GLM-4.7-Flash, flash attention, quantized KV, 3 slots
llama-server \
    --model GLM-4.7-Flash-UD-Q6_K_XL.gguf \
    --ctx-size 608256 \
    --flash-attn on \
    --cache-type-k q8_0 \
    --cache-type-v q8_0 \
    -np 3 \
    --no-kv-unified \
    -ngl 999 \
    --port 5000

# Generate a ~150k token prompt
python3 -c "
import json
text = 'The quick brown fox jumps over the lazy dog. ' * 15000
req = {'model': 'test', 'messages': [{'role': 'user', 'content': text}], 'max_tokens': 32}
open('/tmp/prompt.json', 'w').write(json.dumps(req))
"

# Send 3 concurrent requests - crashes or produces CUDA errors
curl -X POST http://localhost:5000/v1/chat/completions -H "Content-Type: application/json" -d @/tmp/prompt.json &
curl -X POST http://localhost:5000/v1/chat/completions -H "Content-Type: application/json" -d @/tmp/prompt.json &
curl -X POST http://localhost:5000/v1/chat/completions -H "Content-Type: application/json" -d @/tmp/prompt.json &
wait

# CUDA error: invalid configuration argument

@github-actions github-actions Bot added Nvidia GPU Issues specific to Nvidia GPUs ggml changes relating to the ggml tensor library for machine learning labels Mar 1, 2026
@am17an
am17an merged commit 66d65ec into ggml-org:master Mar 1, 2026
77 of 78 checks passed
@jeffbolznv

Copy link
Copy Markdown
Contributor

Is it possible to add backend tests for this?

Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
MrLordCat referenced this pull request in MrLordCat/llama.cpp-rdna-lab Jul 16, 2026
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning Nvidia GPU Issues specific to Nvidia GPUs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: CUDA backend crash on GLM-4.7-Flash with FA on and quantized KV cache Eval bug: In function launch_fattn: CUDA ERROR: Invalid configuration

3 participants