Skip to content

[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
vllm-project:mainfrom
doublewordai:upstream-pr/dsv4-indexer-clamp
Closed

fergusfinn wants to merge 1 commit into
vllm-project:mainfrom
doublewordai:upstream-pr/dsv4-indexer-clamp

Conversation

@fergusfinn

Copy link
Copy Markdown
Contributor

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 and batch_size is a multiple of 32 β€” which capture sizes always are. Models with compress_ratio = 1 never 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

  • Standalone kernel boundary probe (script in the linked issue): call get_paged_mqa_logits_metadata with zero-filled and nonzero-filled length tensors across batch sizes 8/32/33/64/250/256 on SM90.
  • End-to-end: serve deepseek-ai/DeepSeek-V4-Flash on 4x GH200 (--data-parallel-size 4 --enable-expert-parallel --kv-cache-dtype fp8 --max-model-len 128000, default compilation config), then vllm 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

  • Kernel probe before the fix: zero-filled lengths fault (illegal memory access) at batch sizes 32, 64, and 256; pass at 8, 33, and 250; nonzero fills pass at every batch size. This matches the shared-memory boundary (align(batch_size, 32) ints).
  • Before: serving DeepSeek-V4-Flash with the default compilation config dies at "Capturing CUDA graphs (decode, FULL): 0/83", 2/2 attempts (failing worker varies).
  • After: all 83 FULL decode graphs capture, startup completes, the OSL=1 benchmark finishes 64/64, and the 10-minute idle watch shows /health 200 throughout with zero engine errors.

…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>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork β€” automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify

mergify Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @fergusfinn.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@fergusfinn

Copy link
Copy Markdown
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.

@fergusfinn fergusfinn closed this Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs-rebase

Projects

None yet

1 participant