Skip to content

[SM120] dspark: widen SWA index width to an instantiated sparse-MLA shape - #34717

Closed
AliceChenyy wants to merge 2 commits into
sgl-project:mainfrom
AliceChenyy:sm120-dspark-index-width
Closed

AliceChenyy wants to merge 2 commits into
sgl-project:mainfrom
AliceChenyy:sm120-dspark-index-width

Conversation

@AliceChenyy

@AliceChenyy AliceChenyy commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

DSPARK does not start on consumer Blackwell (SM120). CUDA graph capture aborts:

Check failed: (ok) is false: Unsupported sparse-MLA prefill configuration:
model=DSV4 num_heads=16 topk=192 page_block_size=64 topk_extra=0 extra_page_block_size=0

build_dspark_swa_page_indices derives its index width from swa_window + block_size,
which lands on 192 for the DSPARK shape (128 sliding-window entries + the draft
block). FlashInfer's SM120 sparse-MLA prefill matrix instantiates topk in
{128, 512, 1024, 2048}, so the host gate rejects 192 — and it rejects it by aborting
the process, not by falling back. num_heads=16 itself is supported.

What this does

Widen an uninstantiated index width to the next instantiated one. The padded tail is
-1 and the kernel already masks per row through topk_length, so the extra columns
are inert.

128 stays in the set deliberately: it is the only width the DSv4 dual (SWA
extra-cache) dispatch instantiates, and widening it breaks the MTP path.

Relationship to flashinfer-ai/flashinfer#4380

The exact-192 shape is the better long-term answer and now exists upstream — #4380
added topk 192/256 for DSV4 decode and single-cache prefill, and vLLM builds on it in
vllm-project/vllm#51538 by carrying the true dense width (aligned to the kernel's
64-entry tile) instead of rounding.

That path is not available here yet:

FlashInfer prefill dispatch widths
0.6.15.post1 (pinned by sglang) 128, 512, 1024, 2048
v0.6.17 (latest stable) 128, 512, 1024, 2048
nightly 0.6.18 128, 192, 256, 512, 1024, 2048

sglang pins flashinfer_python==0.6.15.post1, so this change is what works on the
pinned dependency. When the pin moves to a release carrying #4380, switching to the
exact width is a one-line follow-up.

I prototyped that follow-up (probe _DECODE_DSV4_DISPATCH at runtime, use 192 when
present, fall back otherwise) and measured it — see below. It made no measurable
difference, so it is not included here rather than carrying the extra complexity and
its two fragile assumptions (intersecting across head counts, and using the decode
table as a proxy because FlashInfer exposes no prefill capability query).

Measurements

4x RTX 6000D (SM120), TP4, deepseek-ai/DeepSeek-V4-Flash-0731,
--moe-runner-backend flashinfer_mxfp4 --speculative-algorithm DSPARK,
--mem-fraction-static 0.80. ISL 8192 / OSL 1024.

Rounded 512 (this PR) vs exact 192 (nightly-0.6.18 build), same tree, same FlashInfer:

bs width throughput (tok/s) TPOT (ms) ITL (ms)
1 192 91.00 10.87 9.82
1 512 92.13 10.73 9.82
8 192 313.41 18.00 10.62
8 512 311.69 17.09 10.63
32 192 520.8 / 522.2 37.7 / 39.0 21.4 / 22.4
32 512 524.5 / 522.7 38.4 / 38.4 21.2 / 21.9

Identical within run-to-run noise at every batch size (bs=32 was repeated twice per
arm; the within-arm spread is as large as the between-arm difference).

Accuracy, sgl-eval run aime25 --n-repeats 16 --max-tokens 200000 (480 samples):

arch pass@1 spread truncated
SM120, 4x RTX 6000D 98.54% (473/480) 96.7–100%, stdev 1.71% 0
SM100, 4x B200 (reference, no patch needed) 98.96% (475/480) 93.3–100%, stdev 2.01% 0

The SM120 row is re-measured on the exact commit in this PR. An earlier run of the same
eval on the pre-cleanup variant of this patch (module-level arch detection instead of the
lazy call) gave 98.33% / stdev 3.65%, i.e. the same result within noise.

Without this change the SM120 server never reaches ready state, so there is no
same-arch baseline to compare against.

Regression check

No effect off SM120: _sm120_index_width returns its argument unchanged when
is_sm120_supported() is false, and arch detection is called inside the function so it
does not pull CUDA into module import.

On SM120 with DeepSeek-V4-Flash (fp8), FlashInfer 0.6.18, GSM8K 50q:

config accuracy TPOT (ISL 8K, bs1)
deep_gemm MoE 0.980 12.41 ms
MTP-2 0.960 6.97 ms

Both match their pre-existing baselines.


CI States

Latest PR Test (Base): ❌ Run #31684742437
Latest PR Test (Extra): ❌ Run #31684742223

…hape

DSPARK does not start on consumer Blackwell (SM120). CUDA graph capture aborts:

  Check failed: (ok) is false: Unsupported sparse-MLA prefill configuration:
  model=DSV4 num_heads=16 topk=192 page_block_size=64

`build_dspark_swa_page_indices` derives its index width from
`swa_window + block_size`, which lands on 192 for the DSPARK shape (128
sliding-window entries + the draft block). FlashInfer's SM120 sparse-MLA prefill
matrix instantiates topk in {128, 512, 1024, 2048}, so the host gate rejects 192
-- and it rejects it by aborting the process, not by falling back. `num_heads=16`
itself is supported.

Widen an uninstantiated width to the next instantiated one. The padded tail is
-1 and the kernel already masks per row through `topk_length`, so the extra
columns are inert. 128 stays in the set deliberately: it is the only width the
DSv4 dual (SWA extra-cache) dispatch instantiates, and widening it breaks MTP.

The exact-192 shape is the better long-term answer and now exists upstream --
flashinfer-ai/flashinfer#4380 added topk 192/256 for DSV4 decode and single-cache
prefill. It ships only in nightly 0.6.18; the latest stable (v0.6.17) still
dispatches {128, 512, 1024, 2048}, and sglang pins flashinfer_python==0.6.15.post1.
This change is what works on the pinned dependency. It costs nothing measurable:
against a nightly-0.6.18 build using the exact 192 width, end-to-end serving is
identical within run-to-run noise.

Measured on 4x RTX 6000D (SM120), TP4, deepseek-ai/DeepSeek-V4-Flash-0731,
--moe-runner-backend flashinfer_mxfp4 --speculative-algorithm DSPARK:

  width  bs   throughput    TPOT      ITL
  192    1    91.00 tok/s   10.87ms   9.82ms
  512    1    92.13 tok/s   10.73ms   9.82ms
  192    8    313.41        18.00     10.62
  512    8    311.69        17.09     10.63
  192    32   520.8/522.2   37.7/39.0 21.4/22.4
  512    32   524.5/522.7   38.4/38.4 21.2/21.9

  AIME25 (sgl-eval, n-repeats 16, 480 samples): pass@1 98.33%, 0 truncated.
  Reference on 4x B200 (SM100), same command: 98.96%.
  Without this change the server does not reach ready state at all.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Keep the two things that cannot be derived from the code -- FlashInfer aborts on
an uninstantiated width rather than falling back, and 128 must stay in the set or
MTP breaks. The measurement table lives in the PR description, and the note about
lazy arch detection described module-level code that no longer exists.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment on lines +240 to +241
def _sm120_index_width(width: int) -> int:
if width in _SM120_INDEX_WIDTHS or not is_sm120_supported():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use get_platform().is_sm120 instead of is_sm120_supported

_SM120_INDEX_WIDTHS = (128, 512, 1024, 2048)


def _sm120_index_width(width: int) -> int:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move this function to python/sglang/kernels/ops/attention/flash_mla_sm120.py

block_swa_locs = full_to_swa_mapping[block_full_locs].to(torch.int32)

target_width = ceil_align(swa_window + block_size, page_index_aligned_size)
target_width = _sm120_index_width(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Change to this form:

target_width = ceil_align(swa_window + block_size, page_index_aligned_size) if not get_platform().is_sm120 else ceil_align_sm120(swa_window + block_size, page_index_aligned_size)

detain added a commit to detain/sglang that referenced this pull request Oct 20, 2026
…indexer) + stack_want decisions

- stack.txt: entries 1-2 (local) + Group A boot-critical indexer chain sgl-project#42371/sgl-project#42861/sgl-project#45261/sgl-project#42294/sgl-project#43008 (fe7be85..0dbd8c5).
- stack_want.txt: consolidated decision set from 8 parallel evaluators + dsv41(422)/SM120(254) sweeps + sybil/qwen harvests.
  Records E verdict (merge only sgl-project#43376) and D verdict (merge only sgl-project#42368; sgl-project#33407/sgl-project#34717 dead on flashinfer 0.7.2).
@AliceChenyy

Copy link
Copy Markdown
Contributor Author

Closing: main now pins FlashInfer 0.7.4, whose SM120 sparse-MLA prefill accepts any topk that is a multiple of 64 with heads in {8,16,32,64} (_policy.py:648, _api.py:710). DSPARK's native width ceil_align(128 + block, 64) = 192 is therefore legal, and widening it to 512 is no longer needed. If DSPARK capture still fails on SM120, a fix should query FlashInfer's supported_topk() rather than hard-code widths; happy to reopen.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants