Skip to content

[Perf] deepseek-v4.1: Score a request's verify rows as one request in the full-scan indexer - #45251

Merged
kpham-sgl merged 5 commits into
sgl-project:mainfrom
kpham-sgl:indexer-group-verify-rows
Oct 20, 2026
Merged

kpham-sgl merged 5 commits into
sgl-project:mainfrom
kpham-sgl:indexer-group-verify-rows

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Under DSpark target verify the ratio-1 and ratio-2 DeepSeek-V4.1 indexers call DeepGEMM's paged logits kernel with every draft row as its own request, so each row streams its request's whole index-K cache: six times per request with block 5. On a DEP16 decode at 64 requests per rank and 128K contexts the four full scans take 1.27 ms of a 22.6 ms DSpark cycle.

Modifications

  • PagedIndexerMetadata.rows_per_request: the draft block for static verify, 1 for ragged verify and everywhere else. The DeepGEMM schedule is planned over the lengths viewed [requests, block] (the JIT planner flattens them, so grouped rows use DeepGEMM's).
  • DeepGEMMDecodeData.paged_logits_args views q as [requests, block, heads, 64], the lengths as [requests, block], and takes one page-table row per request. Both full-scan callers use it: FullTopK._deep_gemm_decode and the candidate-source publish_decode.
  • No kernel change: fp8_fp4_paged_mqa_logits already schedules next_n rows per request in blocks of 128 / heads, so six rows read the cache twice instead of six times.
  • The logits tensor, the per-row lengths and page table handed to top-k are unchanged, so the bf16 DeepSelect top-k, top-k v2 and the paged top-k all see the same input as before.

Validation

DeepSeek-V4.1-Flash, one DEP16 worker on 4x4 GB300 (DP attention 16, EP16, MegaMoE, flashmla_mega, DSpark block 5, static ragged verify, bf16 index logits, decode graphs at batch 64), 1,024 random-id prompts of 128K tokens held at 64 per rank, golden acceptance 3.51, main 49766a74f9 against this branch, one run each. Step time from the scheduler's Decode batch lines over the steady window; kernel times from a torch trace of 20 steps.

64 per rank, 128K contexts main this PR
Full scans, layers 2 / 8 / 14 (ratio 2) / 20 (ratio 1), us 249 / 259 / 246 / 516 96 / 96 / 97 / 183
Four scans per verify step, ms 1.27 0.47
DSpark cycle (draft + verify), ms 22.57 21.57

Other kernels unchanged within 1%. GSM8K at native acceptance on one DEP2 node (5 shots, 1,314 examples, temperature 0): 97.56% main, 97.11% this branch, inside the run-to-run spread, as the check below shows.

Kernel-level check on one GB300 (DeepGEMM v0.2.2, bf16 logits): the same fp8_fp4_paged_mqa_logits call on identical random inputs, per row (next_n 1) and grouped six per request (next_n 6), on three batches: 64 x 6 rows at 128K slots with two seeds, and 16 x 6 at 64K. Every logit a row scores inside its own length is bit-equal (78M values, max abs diff 0), so the per-row top-k is identical on all three. The fp32-logits output type was not run.


CI States

Latest PR Test (Base): ❌ Run #39350404495
Latest PR Test (Extra): ❌ Run #39350404499
Latest PR Test (AMD ROCm 10): ❌ Run #39350404651

… the full-scan indexer

Under DSpark target verify the ratio-1 and ratio-2 indexers called DeepGEMM's paged
logits kernel with every draft row as its own request, so each row streamed its
request's whole index-K cache. With the static block the rows are request-major, so the
metadata and both scan paths (full top-k and the candidate-source publish) now take them
as [requests, block, heads, 64] with 2D lengths and one page-table row per request, which
the kernel scores in blocks of 128 / heads rows. At 128K contexts and 32 index heads that
reads the cache twice per request instead of six times. Ragged verify keeps one row per
request.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/unit/layers/test_dsv4_nonpaged_indexer.py test/registered/attention/unittests/dsv4/test_deepseek_v4.py test/registered/e2e/models/test_deepseek_v41_flash_gb300_dp4ep4.py

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (1 test): ❌ View workflow run

cd test/ && python3 registered/unit/layers/test_dsv4_nonpaged_indexer.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/attention/unittests/dsv4/test_deepseek_v4.py

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/attention/unittests/dsv4/test_deepseek_v4.py

🚀 4-gpu-gb300 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_dp4ep4.py

kpham-sgl and others added 2 commits October 19, 2026 16:51
copy_metadata asserts that the field lists cover every dataclass field, so the new field
failed every in-place copy of an indexer metadata: CUDA graph replay of a full
DSV4Metadata and the breakable prefill graph's refresh of the c1 and c2 metadata. The
grouping is fixed per capture, so it is an equality check.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@sgl-project sgl-project deleted a comment from github-actions Bot Oct 20, 2026
@sgl-project sgl-project deleted a comment from github-actions Bot Oct 20, 2026
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/unit/layers/test_dsv4_nonpaged_indexer.py

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/layers/test_dsv4_nonpaged_indexer.py

@github-actions

This comment has been minimized.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@sgl-project sgl-project deleted a comment from github-actions Bot Oct 20, 2026
@sgl-project sgl-project deleted a comment from github-actions Bot Oct 20, 2026
@kpham-sgl
kpham-sgl merged commit 476fe86 into sgl-project:main Oct 20, 2026
106 of 122 checks passed
zcnrex added a commit to zcnrex/sglang that referenced this pull request Oct 23, 2026
Resolve conflicts with bf16 V4.1 index logits (sgl-project#44051, sgl-project#45880), grouped
verify rows (sgl-project#45251), the two-level-only prefill graph (sgl-project#45783) and KV-shard
index-K writes (sgl-project#44280): the adapter takes a logits_dtype and maps
[batch, next_n] paged queries and schedules to grouped varlen rows on SM100.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
akhilg-nv added a commit to akhilg-nv/sglang that referenced this pull request Oct 23, 2026
…he C4 indexer

In a static MTP verify the C4 indexer called DeepGEMM's paged logits kernel
with every draft row as its own request, so each row streamed its request's
whole index-K cache. The C4 PagedIndexerMetadata now takes rows_per_request
(sgl-project#45251's grouped DeepGEMM schedule), and group_verify_rows views q, the
per-row lengths and the page table as one next_n query per request.

Only the SM100 DeepGEMM path groups, from 16 requests on: below that, at
short context, the grouped launch is up to 1.2x slower than per row. B200,
cold L2, FP8, next_n 4: 32 requests x 64K 37.1 -> 28.4 us, 32 x 128K
73.2 -> 51.3 us, 128 x 64K 181.8 -> 87.0 us; never slower from 16 requests
on. Grouped logits equal per-row logits bit for bit (FP8 and FP4).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
chaohu2000 added a commit to flytiger-eco/sglang-for-sail that referenced this pull request Oct 27, 2026
… the full-scan indexer (sgl-project#45251)

Co-authored-by: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 54b99da72ea89f27fb13d512d691054be21676fb)
Juhyun-Kim-Memphis added a commit to vessl-ai/sglang that referenced this pull request Oct 28, 2026
…he torch prefill indexer (adapted from sgl-project#45794)

Adaptation of upstream sgl-project#45794 (65f19fc) to this branch,
which lacks the later index-plan refactors (sgl-project#45251, sgl-project#45577, sgl-project#45938), so the
upstream patch does not apply as is.

- Under prefill CP the caller passes req_rows=None with rank-local rows; rebuild
  the row-to-request map from req_pool_indices and rows_per_request instead of
  asserting. Without this, prefill CP on SM90 (torch indexer) dies at the first
  prefill.
- Pad the dequantized index K to a multiple of 64 rows when it is BF16 on CUDA
  and lc >= 1024, size query chunks on the padded width, and slice scores back
  to lc before masking and top-k. Here index_k comes from req_to_token slots
  instead of upstream's k_slots. The padding is on the key axis only, so the
  #88 row shard (which splits query rows) and its max-merge are unchanged.
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