Repository navigation
[BugFix] Clamp indexer scheduler-metadata seq_lens to avoid OOB read in DeepGEMM paged-MQA metadata kernel - #51972
Closed
fergusfinn wants to merge 1 commit into
Closed
fergusfinn wants to merge 1 commit into
fergusfinn wants to merge 1 commit into
Conversation
β¦in DeepGEMM paged-MQA metadata kernel DeepGEMM's SM90 paged-MQA-logits metadata scheduler reads one element past its shared-memory prefix-sum buffer when every context length is zero and batch_size is a multiple of 32: the per-SM binary search saturates to q_idx == batch_size and num_segs_q = prefix_sum[q_idx] - prefix_sum[q_idx-1] reads prefix_sum[batch_size], one int past the align(batch_size, 32)-int allocation. DeepSeek-V4-Flash feeds the kernel exactly that input on every FULL cudagraph capture: dummy decode batches use seq_len 1, the indexer builder divides by compress_ratio (4 for V4-Flash) so every length becomes 0, and capture sizes are multiples of 32. The engine dies at startup with a CUDA illegal memory access during 'Capturing CUDA graphs (decode, FULL)'. Models with compress_ratio 1 can never produce all-zero lengths, so the path is unaffected there. Clamp only the scheduler-metadata input. The schedule is a work-distribution hint and the logits kernel re-derives per-token work from the true context_lens, so the clamp is semantics-preserving. Verified on GH200 (SM90), DeepSeek-V4-Flash DP4+EP, kv-cache-dtype fp8, max-model-len 128000, default compilation config: all 83 FULL decode graphs capture, serving healthy through an OSL=1 benchmark and a 10-minute idle watch. A standalone kernel probe confirms the boundary: all-zero lengths fault at batch sizes 32/64/256 and pass at 8/33/250; nonzero lengths pass at every batch size. Signed-off-by: fergus barratt <fergus.barratt00@gmail.com>
Contributor
|
This pull request has merge conflicts that must be resolved before it can be |
4 tasks done
Contributor
Author
|
Closing: the OOB read was fixed in DeepGEMM itself (metadata scheduler clamps q_idx) and #52035 pinned that DeepGEMM, so this clamp is no longer needed. |
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.
Purpose
FIX #51970
DeepSeek-V4-Flash crashes at engine start with a CUDA illegal memory access during FULL cudagraph capture. The indexer metadata builder divides dummy-batch sequence lengths (1) by
compress_ratio(4 for V4-Flash), producing all-zero lengths, and DeepGEMM's SM90 paged-MQA metadata scheduler reads one element past its shared-memory prefix-sum buffer when every length is zero andbatch_sizeis a multiple of 32 β which capture sizes always are. Models withcompress_ratio = 1never produce all-zero lengths, so only V4-Flash is affected.This PR clamps only the scheduler-metadata input to a minimum of 1. The schedule is a work-distribution hint; the logits kernel re-derives per-token work from the true
context_lens, so the clamp is semantics-preserving. A kernel-side bounds guard in DeepGEMM is the more fundamental fix, but the clamp also protects every released wheel, since wheels vendor DeepGEMM's JIT sources at build time.Test Plan
get_paged_mqa_logits_metadatawith zero-filled and nonzero-filled length tensors across batch sizes 8/32/33/64/250/256 on SM90.deepseek-ai/DeepSeek-V4-Flashon 4x GH200 (--data-parallel-size 4 --enable-expert-parallel --kv-cache-dtype fp8 --max-model-len 128000, default compilation config), thenvllm bench serve(random, ISL 1024 / OSL 1, concurrency 16, 64 prompts) followed by a 10-minute idle health watch β the OSL=1 + idle sequence is the historical trigger for the dummy-batch path.Test Result
align(batch_size, 32)ints).