Skip to content

[Fix] [NVIDIA] deepseek_v4: Build the DeepGEMM schedule for the low-ratio prefill-graph indexer on SM12x - #45381

Closed
mathieu-rossini wants to merge 1 commit into
sgl-project:mainfrom
mathieu-rossini:fix/dsv41-sm120-prefill-graph-lowratio-metadata
Closed

mathieu-rossini wants to merge 1 commit into
sgl-project:mainfrom
mathieu-rossini:fix/dsv41-sm120-prefill-graph-lowratio-metadata

Conversation

@mathieu-rossini

@mathieu-rossini mathieu-rossini commented Oct 20, 2026 •

Copy link
Copy Markdown

Motivation

On SM120, --cuda-graph-backend-prefill breakable cannot start DeepSeek-V4.1, the 1017 variant included: the prefill CUDA graph capture fails in the ratio-1/2 indexer. Both DeepSeek-V4.1-Flash and DeepSeek-V4.1-Flash-1017 declare the same 20 ratio-1 and 18 ratio-2 layers; reproduced with the 1017.

The model hook forces SGLANG_FP8_PAGED_MQA_LOGITS_TORCH on SM120, so PagedIndexerMetadata.__post_init__ sets deep_gemm_metadata = None unless force_deep_gemm_metadata is set. _low_ratio_prefill_indexer_metadata, which builds the c1/c2 indexer metadata for the prefill graph, never sets it. The captured low-ratio indexer has no Torch path: _deep_gemm_prefill_captured always calls deep_gemm_fp4_paged_mqa_logits with the plan from row_chunks(), which is then None:

File "sglang/srt/layers/attention/deepseek_v4_backend.py", line 3275, in forward_low_ratio_sources
File "sglang/srt/layers/attention/deepseek_v4_backend.py", line 3745, in _low_ratio_index_topk_captured
File "sglang/srt/layers/attention/dsv4/v41_indexer/full_topk.py", line 65, in topk_prefill_captured
File "sglang/srt/layers/attention/dsv4/v41_indexer/full_topk.py", line 180, in _deep_gemm_prefill_captured
File "sglang/kernels/ops/attention/dsv4/index_logits.py", line 108, in deep_gemm_fp4_paged_mqa_logits
File "deep_gemm/__init__.py", line 164, in fp8_fp4_paged_mqa_logits
RuntimeError: Assertion error (/deepgemm/csrc/apis/../jit_kernels/impls/../heuristics/../../utils/layout.hpp:45): t.is_cuda()

This complements #45261, which fixes the same missing schedule on the decode path (init_forward_metadata_indexer); without that one, V4.1 does not start on SM120 at all. The two PRs touch different functions and do not conflict.

Modifications

_low_ratio_prefill_indexer_metadata passes force_deep_gemm_metadata=get_platform().is_sm120, the condition #45261 applies to the low-ratio decode metadata. On SM120 the prefill-graph indexer then gets its DeepGEMM schedule (per row chunk when row_chunk > 0). Other platforms are unchanged: there the flag stays False as before.

Accuracy Tests

One of our GPU servers, 4x RTX PRO 6000 Blackwell (SM120), TP4 / EP4, DeepSeek-V4.1-Flash-1017 with DSpark, --enable-encoder-swa-bounded-replay, FP8 KV cache, --chunked-prefill-size 2048, context 1M. Tree: main @ ed0b8f43, FlashInfer 0.7.2, with three other open SM120 fixes that V4.1 needs here: #42371 (without it make_candidate_indexer refuses SM120 at backend start, issue #42364), a local equivalent of #45261 (the decode-path fix above) and a local equivalent of #42714. We hit the last one ourselves: without it, 64 running requests × 1M context (also 32 × 1M and 64 × 800K) failed at the first decode with an illegal memory access that a CUDA coredump placed in _page_split_kernel; with it, that configuration ran.

  • Without this change, with --cuda-graph-backend-prefill breakable: the capture fails as above, on every rank.
  • With it: the prefill graph is captured (34 s, 1.77 GB on rank 0) and prefill batches report cuda graph: True.
prefill graph off breakable prefill graph, with this change
GSM8K 5-shot, 1319 questions (few_shot_gsm8k, parallel 64) 0.923 / 0.899 (two runs) 0.911
Code planted at a random depth of a ~14K-token prompt, greedy recall 6/6 6/6

The two runs without the graph show the run-to-run spread; the result with the graph falls inside it. The ~14K-token prompts fit under the graph's 16 384-token replay limit, so they prefill through the captured graph, where the ratio-1/2 indexers must pick the planted block.

Speed Tests and Profiling

No speed change is intended; this is a crash fix. For reference, on this machine the breakable prefill graph was slower than eager prefill above ~500 prompt tokens (median TTFT, prefix cache defeated, one request at a time):

Prompt tokens 126 518 1 980 7 860 15 677
prefill graph off 0.094 s 0.104 s 0.184 s 0.645 s 1.263 s
breakable prefill graph 0.070 s 0.117 s 0.281 s 1.015 s 2.007 s

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

Developed with AI assistance.


CI States

Latest PR Test (Base): ❌ Run #39417319004
Latest PR Test (Extra): ❌ Run #39417319065
Latest PR Test (AMD ROCm 10): ❌ Run #39417319003

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

…atio prefill-graph indexer on SM12x

On SM120 the model hook forces SGLANG_FP8_PAGED_MQA_LOGITS_TORCH, so
PagedIndexerMetadata drops deep_gemm_metadata unless
force_deep_gemm_metadata is set. _low_ratio_prefill_indexer_metadata never
sets it, and the captured ratio-1/2 indexer always scores with
deep_gemm_fp4_paged_mqa_logits, so the breakable prefill CUDA graph capture
fails on the first DeepSeek-V4.1 layer with a ratio-1/2 source
(DeepGEMM assertion t.is_cuda()). Force the schedule there on SM120, as the
decode path does.
@github-actions

Copy link
Copy Markdown
Contributor

Required checks failed on 49b3a7b; this PR cannot be merged until they pass.

Lint (run)
Run pre-commit run --all-files locally and push the result. The run log shows any other failing step.

@mathieu-rossini

Copy link
Copy Markdown
Author

Closing: this is no longer needed on main. _low_ratio_prefill_indexer_metadata was removed by #45783, so the prefill graph no longer calls the paged FP4 MQA logits for the ratio-1/2 indexers, and #45261 now forces the DeepGEMM schedule on SM12x for those ratios in init_forward_metadata_indexer. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant