Skip to content

[Bugfix][Attention] Keep DSV4.1 sparse prefill out of FULL cudagraphs - #59986

Merged
ZJY0516 merged 2 commits into
vllm-project:mainfrom
he-yufeng:fix/dsv41-sparse-full-cudagraph-prefill
Oct 27, 2026
Merged

ZJY0516 merged 2 commits into
vllm-project:mainfrom
he-yufeng:fix/dsv41-sparse-full-cudagraph-prefill

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #59970. Fixes #62417. The five DSV4.1-specific sparse metadata builders declare AttentionCGSupport.ALWAYS, so with cudagraph_mode=FULL_AND_PIECEWISE prefill and mixed batches get FULL-graph captured even though their prefill metadata is not graph-safe, and the engine dies with an illegal memory access once adaptive verification runs mixed batches at concurrency. Downgrade them to UNIFORM_BATCH and report the speculation width as the varlen decode bound, mirroring the reviewed pattern from #59751.

Claims

Validation

.venv/bin/python -m pytest tests/v1/worker/test_attn_utils.py -q

82 passed on CPU. The 10 new parametrized cases pin, per backend and num_speculative_tokens in {0, 7}, that support resolves to UNIFORM_BATCH, that decode widths up to the speculation width stay graph-eligible, and that one token wider is rejected with the reported bound. Changed-file pre-commit (ruff-check, ruff-format) passed.

Not run: the B300 (SM103) end-to-end reproducer from the issue, no compatible hardware available here, and CI does not exercise these builders. The change only narrows what FULL graphs capture: prefill moves to the piecewise path that the issue's adaptive-verification-off and FULL_DECODE_ONLY arms already exercise for 30+ minutes under load, so no batch that was not captured before becomes captured.

Details

Root cause, from the issue's arm table: adaptive verification on + FULL_AND_PIECEWISE hits the IMA 4/4 within a minute; verification off in the same mode is stable; verification on with FULL_DECODE_ONLY is stable. The failing ingredient is prefill inside FULL graphs. Each affected builder now also overrides get_varlen_cudagraph_max_query_len to return max_decode_query_len(vllm_config) (1 + num_speculative_tokens on MRV2), the same width the V2 runner uses when it builds varlen decode replays.

Not a duplicate of #59751: that PR changes only the generic FlashInferMLASparseTRTLLMMetadataBuilder for #59681, while the DSV4.1 model wires its own five builders, which the #59970 reporter calls out explicitly. Checked the issue thread and open PRs referencing #59970 before starting; nothing else covers them.

AI assistance: Kimi Code (Kimi K3) prepared the patch and tests; I reviewed every changed line and ran the validation above.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

@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 added deepseek Related to DeepSeek models DSv4.1 Related to DeepSeek-V4.1 models nvidia bug Something isn't working labels Oct 4, 2026
@mergify

mergify Bot commented Oct 6, 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, @he-yufeng.

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

@mergify mergify Bot added the needs-rebase label Oct 6, 2026
@he-yufeng
he-yufeng force-pushed the fix/dsv41-sparse-full-cudagraph-prefill branch from cba4e26 to 57087f7 Compare October 6, 2026 09:20
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and resolved the test_attn_utils.py overlap with #59751, which landed in the meantime: both tests now sit side by side, since that PR covers the generic FlashInferMLASparseTRTLLMMetadataBuilder and this one the five DSV4.1 builders. Also caught a missing num_speculative_tokens parametrize on my test while rerunning, fixed in the same push. pytest tests/v1/worker/test_attn_utils.py: 82 passed.

@mergify mergify Bot removed the needs-rebase label Oct 6, 2026
@he-yufeng
he-yufeng force-pushed the fix/dsv41-sparse-full-cudagraph-prefill branch from 57087f7 to 42c5b5d Compare October 6, 2026 09:23
@lishunyang12

Copy link
Copy Markdown
Contributor

e2e test results?

@he-yufeng

Copy link
Copy Markdown
Contributor Author

@lishunyang12 No e2e from my side: the reproducer from #59970 needs an SM103 part and I have no compatible GPU here, and the CI lanes I can see do not build these DSV4.1 builders. What I ran is the scheduler-level parametrization in tests/v1/worker/test_attn_utils.py (82 passed on CPU), which pins per backend and num_speculative_tokens that support now resolves to UNIFORM_BATCH and that decode widths up to 1 + num_speculative_tokens stay graph-eligible.

The cleanest e2e confirmation would come from whoever has the B300 repro in #59970: serve DSV4.1 with cudagraph_mode=FULL_AND_PIECEWISE and adaptive verification on, then drive mixed batches at concurrency; before this change it dies with the IMA within about a minute, after it prefill should fall back to the piecewise path that the verification-off arm already runs stably. If a maintainer can point a GPU lane at this PR I am happy to write a small serve-and-probe script for it.

@he-yufeng
he-yufeng force-pushed the fix/dsv41-sparse-full-cudagraph-prefill branch from 42c5b5d to 86579a1 Compare October 7, 2026 05:05
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (the conflict notice went away with it) and reran the pin suite: 82 passed in tests/v1/worker/test_attn_utils.py.

On e2e: I don't have DSV4.1 hardware here, so nothing beyond CPU-level tests ran on my side. What the unit tests pin is the failure mode itself: all five builders now declare UNIFORM_BATCH and report 1 + num_speculative_tokens as the varlen bound, so prefill and mixed batches leave FULL capture while uniform decode keeps its graphs. That is the same shape as the reviewed fix in #59751. The adaptive-verification run that crashed in #59970 needs real hardware to replay, so an e2e confirmation has to come from CI or someone with the checkpoint.

@he-yufeng
he-yufeng force-pushed the fix/dsv41-sparse-full-cudagraph-prefill branch from 86579a1 to cba4e26 Compare October 20, 2026 02:16
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased onto current main; no semantic conflicts. The attention-utils suite passes locally on this head (91 passed, CPU).

@he-yufeng
he-yufeng force-pushed the fix/dsv41-sparse-full-cudagraph-prefill branch from cba4e26 to 015333c Compare October 20, 2026 02:18
Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Co-authored-by: Kimi Code <kimi-code@moonshot.cn>
@he-yufeng
he-yufeng force-pushed the fix/dsv41-sparse-full-cudagraph-prefill branch from 015333c to d29af51 Compare October 20, 2026 03:32
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (3b51898) to pick up #62593 — the earlier pre-commit failure here was the Step5 sparse_attention.py mypy breakage inherited from main, not something in this change. Clean rebase, diff unchanged.

@tomasruizt

tomasruizt commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Hi @he-yufeng! Thank you for submitting this. I can test it e2e. I got here after investigating #62417 and the proposed solution #62535. I think this PR is the right fix.

Edit: Can you add "Fixes #62417"?

ids=["flashmla", "flashinfer_mla", "swa_flashinfer", "swa_flashmla", "compressor"],
)
@pytest.mark.parametrize("num_speculative_tokens", [0, 7])
def test_dsv41_sparse_builders_keep_varlen_decode_graphs_only(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of introducing a new test, please parametrize the existing one test_flashinfer_sparse_full_graphs_exclude_prefill_keep_varlen_decode()

) -> int | None:
# Decode replays use device request boundaries; prefill metadata is
# not graph-safe.
return max_decode_query_len(vllm_config)

@tomasruizt tomasruizt Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One idea to deduplicate code is to introduce a mixin class and reuse it across builders. This mixin could live in vllm/vllm/v1/attention/backend.py.

class VarlenDecodeCGMixin:
    _cudagraph_support: ClassVar[AttentionCGSupport] = AttentionCGSupport.UNIFORM_BATCH
    
    @classmethod
    def get_varlen_cudagraph_max_query_len(
        cls,
        vllm_config: VllmConfig,
        kv_cache_spec: KVCacheSpec,
    ) -> int | None:
        # Decode replays use device request boundaries; prefill metadata is
        # not graph-safe.
        return max_decode_query_len(vllm_config)

The attribute _cudagraph_support can alternatively be left out of the mixin, then each builder class would define it separately. But setting UNIFORM_BATCH seems like a recurring pattern.

Reuse:

class DeepseekV4FlashInferSparseMLAMetadataBuilder(
     VarlenDecodeCGMixin, DeepseekV4SparseMLAMetadataBuilder):
    ...

@tomasruizt

Copy link
Copy Markdown
Contributor

I ran deepseek-ai/DeepSeek-V4.1-Flash-1017 on GSM8K and different probes (thanks @xzwgit for the reproducers) on 2xB300 (TP2 + EP): it looks good. Haven't done perf benchmarks.

Branch main main PR
Server arg --enforce-eager --compilation-config '{"cudagraph_mode": "FULL"}' --compilation-config '{"cudagraph_mode": "FULL"}'
Resolved cudagraph mode none (eager) FULL FULL_DECODE_ONLY
GSM8K accuracy ✅ 0.955 ❌ 0.020 ✅ 0.955
GSM8K invalid ✅ 0.000 ❌ 0.980 ✅ 0.005
17*19=? probe (#62417) ✅ 323 ❌ no answer, garbage text up to the 2048-token limit ✅ 323
Tool-call probe (#62417) ✅ successful tool call ❌ garbage text, no tool call ✅ successful tool call
Illegal memory access (#59970) ✅ no ❌ yes (in the perf sweep at c1) ✅ no

@tomasruizt

Copy link
Copy Markdown
Contributor

@mgoin This PR implements the same pattern we needed in "AV for Mamba2" #53036 (review)

@xzwgit

xzwgit commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Cross-arch confirmation from the SM120 leg — clean on the vLLM 0.32.0 tree + FlashInfer 0.7.2 (RTX PRO 6000D 84G x8, TP8+EP8, DeepSeek-V4.1-Flash-1017, DSpark k=3, cudagraph_mode=FULL requested).

Setup: stock v0.32.0 wheel + a mechanical port of this PR's head d29af51 to the five builder sites (ALWAYS -> UNIFORM_BATCH + get_varlen_cudagraph_max_query_len), with the model_runner guard from #62535 removed. The in-tree machinery fires exactly like your B300 run:

CUDAGraphMode.FULL is not supported with DeepseekSparseSWAFlashInferBackend backend
(support: AttentionCGSupport.UNIFORM_BATCH); setting cudagraph_mode=FULL_DECODE_ONLY
Probe stock 0.32.0, no guard + this PR
Engine boot engine boots ~90 s READY ~100 s
First prefill batch 17*19= (#62417) engine dies on first request 323 (3/3)
Thinking-chat probe (#62417) garbage loops sane reasoning + answer (3/3)
Tool-call probe (#62417) no tool call correct get_weather({"city":"Beijing"}) (3/3)
random 1K x 1K, c32 burst (#59970) n/a (engine dead) 32/32, 0 failed, 0 CUDA errors, /health OK

Also notable for #62417: the chat/thinking corruption we had previously tracked as a kernel-level numeric issue (flashinfer-ai/flashinfer#6812) does not reproduce with this PR on SM120 — the FULL-graph admission of prefill-bearing batches looks like the actual root cause of that symptom as well.

(SM120 note: this arch additionally needs the SM120 block-size declaration from #60762 to boot at all — independent axis, both are required here.)

Closing #62535 in favor of this PR. Thanks @tomasruizt for the e2e run and the pointer.

@xzwgit

xzwgit commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Linking for the tracker: #62417 (SM120/RTX PRO 6000D leg of the same failure class — DSpark adaptive verification + FULL graph, corruption symptoms) is also fixed by this PR — confirmed by both arch legs now (2xB300 above, SM120 in our comment). Adding Fixes #62417 to the description would close it automatically when this lands.

@he-yufeng

Copy link
Copy Markdown
Contributor Author

@tomasruizt @xzwgit Thanks for running both arch legs — the B300 GSM8K table and the SM120 FlashInfer confirmation are exactly the coverage I could not get locally. Added Fixes #62417 to the description as suggested.

@gty111 gty111 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@gty111 gty111 added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 27, 2026
@gty111

gty111 commented Oct 27, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

✅ @he-yufeng, CI is now available for this PR.

  • /ci run starts upstream CI; /amd-ci run starts AMD CI only.
  • Run commands test your branch with every commit currently on its upstream target branch. If it is behind, the bot merges the target branch into it first (pull before pushing again). Append --allow-stale to a run command to test an outdated branch as is, at your own risk.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /amd-ci retry retries failed jobs in AMD CI for the current PR head. Use /amd-ci run when the current head has no AMD CI build.
  • /ci cancel cancels scheduled or running CI builds for this PR branch; /amd-ci cancel does the same for AMD CI only.

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #97512 for commit 8dc913310de0.

ℹ️ This PR is 489 commits behind upstream main. Merged upstream main into this branch as 8dc913310de0 before starting CI. Pull the branch before pushing more changes.

@ZJY0516 ZJY0516 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this

@github-project-automation github-project-automation Bot moved this to Ready in NVIDIA Oct 27, 2026
@ZJY0516
ZJY0516 merged commit 8977b13 into vllm-project:main Oct 27, 2026
75 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA Oct 27, 2026
Micador pushed a commit to Micador/vllm that referenced this pull request Oct 27, 2026
…vllm-project#59986)

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Co-authored-by: Kimi Code <kimi-code@moonshot.cn>
Co-authored-by: vllm-agent <claw@inferact.ai>
Signed-off-by: Christopher Mackenzie <christopher.mackenzie.software@gmail.com>
zkawfanx added a commit to zkawfanx/vllm that referenced this pull request Oct 28, 2026
[A100][Backport] Keep sparse prefill out of FULL CUDA graphs (vllm-project#59986)
syeehyn pushed a commit to syeehyn/vllm that referenced this pull request Oct 29, 2026
…vllm-project#59986)

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Co-authored-by: Kimi Code <kimi-code@moonshot.cn>
Co-authored-by: vllm-agent <claw@inferact.ai>
(cherry picked from commit 8977b13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working deepseek Related to DeepSeek models DSv4.1 Related to DeepSeek-V4.1 models nvidia ready ONLY add when PR is ready to merge/full CI is needed

Projects

Status: Done

7 participants