Skip to content

[Refactor] [NVIDIA] attention: Migrate DSA/DSV4 indexers to DeepGEMM 0.2.5.post2 - #44350

Open
zcnrex wants to merge 23 commits into
sgl-project:mainfrom
zcnrex:chunan/dg-mqa-api-260930
Open

zcnrex wants to merge 23 commits into
sgl-project:mainfrom
zcnrex:chunan/dg-mqa-api-260930

Conversation

@zcnrex

@zcnrex zcnrex commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Purpose and scope

Upgrade sgl-deep-gemm from 0.2.3.post2 to 0.2.5.post2 and migrate the DSA (including DeepSeek-V3.2), DeepSeek-V4, and DeepSeek-V4.1 indexer call sites to the replacement MQA-logits API. This is a self-contained migration; it does not depend on preparatory cleanup or performance PRs.

DeepGEMM removed fp8_mqa_logits / fp8_paged_mqa_logits and changed the fp8_fp4_* interfaces. On SM100 the new kernels require MX scales and BF16 weights, return BF16 logits, and use a different paged schedule. Those requirements also change the representation of FP8 index-K scales stored outside the process.

Required migration changes

  • Compatibility adapter: keep existing call shapes in srt/layers/attention/deep_gemm_mqa_logits.py. Supply unit UE8M0 scales for plain FP8 Q, pass through pre-quantized Q tuples, convert weights/scales, and widen or expand logits where existing consumers require FP32 or full-width rows.
  • Cache writers and readers: use packed UE8M0 index-K scales where the SM100 DeepGEMM paged reader requires them. Preserve compatible FP32 representations for other readers. Update the DSA, k-pool, and V4 C4 writers together with their consumers.
  • Scheduling and memory: match each schedule to its kernel and request grouping, retain the CuTe DSL 256-token schedule, cap SM100 DSV4 schedules at 16384 rows, and account for simultaneously live compressed and expanded logits in the affected prefill budgets. Copy chunked schedules and top-k plans in place during graph replay.
  • PD and external-cache compatibility: reject incompatible index-K layouts, including an older decoder connecting to a UE8M0 prefill. Namespace UE8M0 pages separately in HiCache, Mooncake and MORI direct linkers, and LMCache. Python and Rust bootstrap checks participate in the same compatibility rule. These protections belong in this migration because FP32 and UE8M0 scales occupy the same number of bytes.
  • Architecture dispatch and regression tests: keep supported fallback dispatch consistent with the new dependency; update direct calls, numerical tolerances, schedule tests, cache-format tests, and graph replay tests.

The dependency pin changes in python/pyproject.toml and docker/Dockerfile.cu134. Version 0.2.5 includes sgl-project/DeepGEMM#103 and the SM120 restoration in sgl-project/DeepGEMM#109; 0.2.5.post1 additionally fixes SM100 Mega MoE shared memory on CC 10.7 (sgl-project/DeepGEMM#125), and 0.2.5.post2 adds the CC 10.7 Mega MoE K=64 packed-FP4 MMA and SIMT dispatch pull (sgl-project/DeepGEMM#126). Neither post release touches the MQA logits kernels this PR uses.

SM120 retains the V4 FP4 indexer flag and V4.1 dense/paged DeepGEMM paths restored upstream in #109, with its required 128-token schedule splits and existing 4096-row cap. Existing SM120 backend defaults remain unchanged. Sparse-table MQA remains SM100-only; SM120 uses the dense candidate fallback.

Deferred work

Follow-up V3.2 / DSA V4 V4.1
Adapter relocation, API cleanup, and dispatch consolidation Applies Applies Applies to shared dense/paged adapter callers; sparse logits also have a direct API path
BF16 top-k to remove FP32 widening Applies to SM100 paths that widen Applies to C4 paths that widen Low-ratio FP4 already uses BF16 logits by default on SM100; inspect FP32 overrides and any remaining widening paths
Produce MX Q scales at quantization time Applies to plain FP8 Q callers Applies to FP8 Q callers Low-ratio FP4 already passes packed Q scales; no unit-scale allocation to remove there

A new pool-format abstraction, additional backend enablement, and further kernel tuning are also deferred. Preserving existing SM120 support is included in this migration. The graph replay and cache compatibility changes above remain in this PR as migration requirements.

Known limits

  • Paged DSA, k-pool, and V4 paths that widen SM100 BF16 logits retain both buffers temporarily: 1.5x the old logits storage. Their decode allocation is not covered by the prefill chunk budget.
  • DSA's SM100 metadata schedule is not chunked; the upstream metadata kernel has a roughly 29k-row limit.
  • PD peers must select compatible index-K formats, including backend flags and environment overrides.
  • SM100 BF16 weights/logits can change top-k membership at near-ties.
  • The validation below is tied to the stated commits and hardware. No DSA model, PD pair, or external L3 store has been validated end to end for this migration.

Accuracy Tests

The results below were measured with sgl-deep-gemm 0.2.5 or 0.2.5.post1, as each one states. They have not been rerun on 0.2.5.post2, which changes only Mega MoE on CC 10.7.

At 56b3fabdee, rerun on chunan-4xb300-pr44350g (B300/SM103, torch 2.14.1+cu130, sgl-deep-gemm==0.2.5.post1): 632 passed, 18 skipped, plus 40 subtests passed. Each file ran in a separate pytest process. This includes mocked SM120 dispatch/metadata cases; it is not an SM120 GPU or model E2E run.

Rerun at 56b3fabdee Passed Skipped Subtests passed
test_dsv4_nonpaged_indexer 32 0 34
test_paged_mqa_metadata 115 16 0
test_deepgemm_paged_mqa_logits 192 0 0
test_cute_dsl_fp8_paged_mqa_logits (reduced cases) 196 0 0
test_fp4_indexer 91 2 0
test_dsv41_prefill_sparse_indexer 6 0 6

SM100: B300 (SM103), sgl-deep-gemm==0.2.5.post1, PR head dabf3a9ce9 (merged with main f1a36c4789), torch 2.14.1+cu130, one pytest per file:

File Passed Skipped
test_cute_dsl_fp8_paged_mqa_logits 352 32
test_deepgemm_paged_mqa_logits 192
test_paged_mqa_metadata 115 16: SM100 DeepGEMM uses its own varlen schedule format
test_fp4_indexer 91 2: Hopper paged dispatch
test_dsv4_nonpaged_indexer 31 (+29 subtests)
test_kv_checksum 28 (+4 subtests)
test_dsa_indexer 15 (+41 subtests)
test_fused_store_index_cache 15
test_kpool_stream_scheduling 13 (+50 subtests)
test_dsv32_indexer_fusion 7
test_dsv41_prefill_sparse_indexer 6 (+6 subtests)
test_dense_prefill_indexer 5 (+17 subtests)
test_dsa_mqa_logits_chunking 5
test_dsa_kpool_deepgemm_logits 4
test_dsa_sharded_pd_transfer 4 (+5 subtests)
test_dsv4_unified_fp8_pd 1 (+4 subtests)

At head f42c4847d9 (HiCache keys), on the same setup: test_pd_index_k_scale_layout 5 (+10 subtests), plus the HiCache tests that build storage keys: test_hicache_storage_format_tag 4, test_hicache_dcp_host_pool 18, test_hicache_unified_key_scheme 24, test_hicache_file_lru_unit 41, test_hicache_storage_registration_hook 5, test_pp_prefetch_ticket 17, test_scheduler_hicache_attach 2. test_unified_hicache_transfer_lifecycle (4 failed) and the tensorcast store test (no tensorcast module) fail identically on the commit before, in the box's environment.

Last run at 92213811fd (sgl-deep-gemm==0.2.5), not rerun since: test_v41_kv_store 7 (+54 subtests) / 1 skipped (gfx950 only), test_dsv4_unified_fp8_compress_store 8 skipped (AMD gfx95 only).

  • Graph replay above the SM100 row cap was also checked with real DeepGEMM schedules and top-k plans (24,576 rows, two chunks): after copy_, every chunk tensor keeps its address and matches freshly built metadata.
  • The grouped [batch, next_n] path is bitwise equal to the one-row-per-token path: 72 ad hoc cases (batch {1, 3, 8} x next_n {2, 3, 4, 6} x heads {32, 64} x context {128, 1024, 16384}) and the 5 shapes in the speed table below.
  • Two tests needed test-only fixes for BF16 precision:
    • test_deepgemm_paged_mqa_logits: its per-element tolerance failed near-zero logits. The worst element is about 1% of the summed absolute head terms (about 2.5 BF16 ulps), and calc_diff is about 1e-5. On SM100 it now checks calc_diff < 3e-5, DeepGEMM's own SM100 bound.
    • test_dsv41_prefill_sparse_indexer: the dense reference scores are BF16 now, and at |logit| around 100 one BF16 step is 0.5 to 1. Block scores therefore tie exactly, and tie-breaking picks different members in 88 of 256 rows; every swap is an exact tie. Selections are now compared by their scores.

SM90: H200, with a wheel built from sgl-project/DeepGEMM#103 (before the main merge and the 0.2.5 bump; not rerun since):

  • The adapter matches a torch reference: max relative error 1.9e-4 for both full-width and compressed ragged logits.
  • Kernel tests that pass: test_fused_store_index_cache, test_dsa_indexer, the five kpool tests, test_paged_mqa_metadata, test_dsv32_indexer_fusion, test_fp4_indexer.
  • test_deepgemm_paged_mqa_logits fails on SM90 with a tolerance mismatch. It failed identically on main with the 0.2.2 wheel main used then, and CI only runs it on B200.

Model accuracy: DeepSeek-V4-Flash, TP4 on 4x B300. Setup:

  • Launch flags: the B300 Low-Latency recipe from test/manual/dsv4/test_b300_flash.py (TP4, flashinfer_mxfp4, EAGLE 3/1/4).
  • Eval: sgl-eval 0.1.3. GSM8K on all 1319 questions; AIME25 with 16 samples per problem at temperature 1.0 and a 64k max-token cap (the test/manual/dsv4/_common.py defaults).
  • The first two rows ran on the same box and the same main.
sglang sgl-deep-gemm GSM8K AIME25 pass@1 hit 64k cap
main e7c55f6959 0.2.3.post2 0.968 0.835 16.9%
this PR, 92213811fd 0.2.5 0.968 0.848 15.4%
this PR on main 4da6f585f3 0.2.5 0.969 0.935 6.0%
  • On the same base, accuracy is unchanged. A later GSM8K pair on one box: PR 5a4b7e7097 (0.2.5.post1) 0.965, main e7c55f6959 0.968, within main's own run-to-run spread (0.965–0.968).
  • Both arms on current main sit below the harness's 0.93 AIME25 threshold. The cause is in main: [Feat] openai: Render DeepSeek-V4/V4.1 chat prompts with deepseek-recipe #45315 now renders an unset reasoning_effort on V4-Flash as the "Absolute maximum" effort prompt. With SGLANG_DSV4_REASONING_EFFORT=low, which restores the checkpoint's default prompt, main scores 0.925. Details are in this comment. This PR does not change prompt rendering.
  • No DSA model (DeepSeek-V3.2 / GLM-5) was run end to end, and neither PD nor HiCache L3 was run end to end; those paths are covered by the kernel and unit tests above.

On SM100 the indexer weights and logits pass through BF16, as upstream DeepGEMM intends, so top-k selection can differ slightly from the FP32 path at near-ties.

Speed Tests and Profiling

DeepSeek-V4-Flash serving, 4x B300, same recipe as above, bench_serving random 128 in / 128 out, concurrency 256, 2048 prompts, after a warmup bench. Arms in ABBA order on one box; same-code boots differ by 0.6–1.8%.

sglang sgl-deep-gemm output tok/s (run 1 / run 2) mean TPOT ms
main e7c55f6959 0.2.3.post2 3866 / 3887 60.9 / 60.6
this PR, 5a4b7e7097 0.2.5.post1 3850 / 3850 61.1 / 61.1
  • Within noise of main. An earlier PR head was about 7% slower because it widened the paged logits to FP32 over the whole CUDA-graph logits width (799 µs per call); the prefix-only widen takes 38 µs.
  • DeepGEMM 0.2.5's SM100 paged MQA kernel costs a fixed ~1–3 µs more per call than 0.2.3 when every row is its own request, and is equal at long context. It is about 1% of a decode step at this shape.
  • Grouping DSV4 C4's MTP verify rows into one DeepGEMM request makes that kernel 22–56% faster at 256–1024 rows, but measured flat end to end at both 128-token and 16k contexts (64 requests x 16k, ABBA: 6495 vs 6554 tok/s, TPOT 4.87 ms both), so it is not in this PR.

DSA SM100 target-verify, paged MQA logits (B300, next_n = 4, 64 heads, CUDA-graph replay, µs per call):

batch x context schedule [batch, next_n], per-row call (before 887f7e07b6) grouped call (this PR) per-row schedule and call
1 x 32k 143.9 25.8 24.4
8 x 16k 95.6 23.9 22.6
32 x 8k 54.8 23.3 24.8
64 x 4k 34.1 21.7 23.1
128 x 2k 25.4 21.4 23.7

A schedule whose request grouping differs from the call's leaves the output unchanged but unbalances the SMs.

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #40985816538
Latest PR Test (Extra): ❌ Run #40985816290
Latest PR Test (AMD ROCm 10): ❌ Run #40985816504

DeepGEMM's upstream sync (sgl-project/DeepGEMM#103) removes fp8_mqa_logits
and fp8_paged_mqa_logits and changes fp8_fp4_*mqa_logits: no clean_logits
or logits_dtype, compressed ragged logits, and on SM100 MXFP8/MXFP4 Q/K
(int32 packed UE8M0 scales), BF16 weights, BF16 logits, a varlen
`indices` per paged query row and a new paged schedule format. SM90 keeps
E4M3 + FP32 scales; SM120 has no DeepGEMM MQA kernels any more.

- deep_gemm_mqa_logits.py wraps the new API in the old call shapes
  (FP32 logits, 256-column row stride): unit Q scales when the Q scale is
  folded into the weights, BF16 weights, K scales repacked to UE8M0, a
  Triton kernel that widens compressed rows back to full width for the
  DSA top-k, and indices / varlen-flattened metadata on SM100.
- Index-K caches on SM100 round each token's scale to a power of two and,
  when DeepGEMM reads the paged cache, store it as packed UE8M0 (lossless;
  FP8 bytes unchanged). Writers: kpool Triton kernels, DSA
  fused_store_index_k_cache / fused_k_indexer_norm_rope_store / act_quant
  fallback, DSV4 fused_norm_rope_indexer. Other paged backends keep FP32.
- kpool and DSA ragged paths read compressed logits; DSA paged verify uses
  one row per token on SM100.
- DSV4 C4 builds DeepGEMM metadata on SM100; V4.1 runs DeepGEMM index
  logits only on SM100 (SM120 takes the Triton indexer), and the FP4 C4
  indexer requires SM100 or gfx95.
- Logits row-chunk budgets count the BF16 buffer on SM100.
- Tests: kpool DeepGEMM logits, fused-store UE8M0 packing, DSA paged
  DeepGEMM on SM100; updated mocks and direct calls for the new API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On SM100 DeepGEMM's MQA logits take BF16 weights and return BF16, so two
tests that assumed FP32 failed on a B300 without a kernel fault:

- test_deepgemm_paged_mqa_logits: elementwise atol=2e-2/rtol=8e-3 rejects
  logits near zero, where positive and negative head terms cancel. Across
  configs calc_diff is ~1e-5 and the worst error is <=1% of the sum of
  |terms| (~2.5 BF16 ulps). On SM100 it now checks calc_diff < 3e-5,
  upstream DeepGEMM's own SM100 bound; SM90 keeps the elementwise check.
- test_dsv41_prefill_sparse_indexer: the dense reference scores are now
  BF16, whose step at |logit| ~100 is 0.5-1, so block and position scores
  tie exactly and torch vs kernel tie-breaking pick different members
  (88/256 rows at 256x40000, every swap an exact tie). Block and own-top-k
  selections are compared as score multisets, and picks tied with the
  selection floor count toward the overlap.

Both pass on B300 (SM103) with a sgl-deep-gemm wheel built from
sgl-project/DeepGEMM#103: 192/192 and 6/6 (+6 subtests).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Heisenberg-Yin added a commit to Heisenberg-Yin/sglang that referenced this pull request Oct 18, 2026
…nd DeepSeek-V4.1 on SM100

One exact, histogram-driven decode top-k selector for the DSA indexer
(top-2048, 64-slot pages) and the DeepSeek-V4.1 ratio-1/2 index layers
(top-512, 128-slot pages), both reading the BF16 logits of DeepGEMM's
SM100 paged MQA logits kernel. The kernel counts each row's scores into
1024 coarse bins while it writes them (histogram=); the selector derives
the crossing bin from the histogram, selects everything above it and ranks
the bin exactly (ties to the lower physical slot), falling back to an exact
whole-row select when the histogram disagrees with the scores or the
crossing bin overflows the candidate buffer. Rows of up to 16384 scores
are selected by one CTA from registers. Scratch returns to rest after
every call, so CUDA graph replays need no reset. Grid sizes follow the
GPU's SM count, which the storage passes to every call; the row thresholds
between launch shapes were measured on B200 (148 SMs).

- kernels/jit/csrc/litetopk_decode/select.cuh: the selector, templated over
  the two shipped configurations (Bf16Top2048, Bf16Top512).
- kernels/ops/attention/litetopk_decode.py: configs, storage / plan, and
  runtime detection of the device and of DeepGEMM's BF16 paged MQA logits
  API with a histogram (declared Python parameters: indices and histogram,
  no logits_dtype).
- srt/layers/attention/litetopk_decode.py: per-process selector buffers,
  plans per row count, CUDA-graph-safe growth.
- DSA, on the MXFP8 (UE8M0) index-K cache: Indexer._get_topk_paged passes
  the plan's histogram through deep_gemm_mqa_logits.fp8_paged_mqa_logits,
  which then returns the BF16 logits without widening them, and replaces
  the sgl-kernel fused paged top-k transform for decode and verify; when
  LiteTopK serves verify, verify tokens get their causal lengths in the
  producer schedule. The torch paged MQA logits fallback and the
  flashinfer / torch top-k backends keep the default top-k.
- DeepSeek-V4.1: FullTopKIndexer.topk_decode and
  SparseTableBackend.publish_decode count the histogram with
  fp8_fp4_paged_mqa_logits and select in place of the default top-k
  (topk_transform_paged_v2 on the widened FP32 logits).
  Decode reuses the forward's DeepGEMM schedule; verify schedules the
  tokens of a request as one request (one KV pass), once per forward.

Off by default (SGLANG_OPT_LITETOPK_DECODE); unsupported devices, DeepGEMM
builds, modes and shapes keep the default top-k. Builds on sgl-project#44350 (the
fp8_fp4 MQA logits API); the histogram producer comes from
sgl-project/DeepGEMM#94.

Also covers DeepSeek-V4.1, replacing sgl-project#42351.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zcnrex and others added 2 commits October 22, 2026 13:27
Collapse the (kRoundScale, kPackScale) template pair into a single kScaleFmt
(FP32 / power-of-two FP32 / packed UE8M0) and compute it with the existing
cast_to_ue8m0 / inv_scale_ue8m0 helpers instead of exp2f(ceilf(log2f())),
a division, and re-extracting the exponent. The three index-K store kernels
share quant_index_k_scale(). ue8m0_scale now implies round_scale.

Outputs are bit-identical to the previous kernels for all three formats.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The gathered-KV dispatch test asserts FP32 scales, but on an SM100 host
dsv4_fp8_index_cache_is_ue8m0() is true and the scales are viewed as int32.
Patch it to False so the CPU test is host-independent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Oct 27, 2026
zcnrex and others added 2 commits October 27, 2026 10:24
main sgl-project#45112 moved ops/attention/fused_store_index_cache.py to
ops/kvcache/dsa_fused_store_index_cache.py; the merge kept the old path
in dsa/indexer_k.py and dsv4/compress.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zcnrex

zcnrex commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

DeepSeek-V4-Flash accuracy on current main: AIME25 drop from the default reasoning effort, not from this PR

While validating this PR I ran DeepSeek-V4-Flash on 4x B300 (TP4, the B300 Low-Latency recipe from test/manual/dsv4/test_b300_flash.py, sgl-eval 0.1.3). Settings: GSM8K on all 1319 questions; AIME25 with 16 samples per problem at temperature 1.0 and a 64k max-token cap. These match the test/manual/dsv4/_common.py defaults, where the AIME25 threshold is 0.93.

sglang sgl-deep-gemm reasoning effort AIME25 pass@1 hit 64k cap output tokens, mean / median GSM8K
this PR on main 4da6f585f3 (before #45315) 0.2.5 unset 0.935 6.0% 16.4k / 9.7k 0.969
main e7c55f6959 0.2.3.post2 unset 0.835 16.9% 25.0k / 18.8k 0.968
this PR on main e7c55f6959 0.2.5 unset 0.848 15.4% 24.0k / 16.9k 0.968
main e7c55f6959 0.2.3.post2 SGLANG_DSV4_REASONING_EFFORT=low 0.925 6.9% 16.0k / 9.7k 0.965

This PR and main score the same on the same base. The drop comes from main, and pinning the effort recovers it.

Cause: #45315 renders DeepSeek-V4 prompts through deepseek-recipe 0.2.0 as ModelVersion.DeepseekV4Pro. A request with thinking on and no reasoning_effort gets recipe's default tier high, which prepends this 79-token instruction:

Reasoning Effort: Absolute maximum with no shortcuts permitted.
You MUST be very thorough in your thinking and comprehensively decompose the problem ...
  • V4-Flash's bundled encoding/encoding_dsv4.py and its README add that prefix only for reasoning_effort="max"; its default renders nothing. The removed in-tree encoder detected this "preview" profile and also rendered nothing.
  • For the same AIME problem, main renders 107 prompt tokens with no effort set and 28 with reasoning_effort="low". The 28-token prompt is token-identical to the checkpoint encoder's default encode_messages(..., thinking_mode="thinking").

With the prefix, V4-Flash reasons about 50% longer, and about one sample in six reaches the 64k cap before answering.

#45315 lists the change under "Behavior changes", so it is intended. However, deepseek-recipe 0.2.0 has no V4-Flash model version (only DeepseekV4Pro and DeepseekV41Flash), so V4-Flash now renders as V4-Pro by default. Possible fixes:

  • default V4-Flash to low in the adapter, which restores the checkpoint's prompt;
  • or set SGLANG_DSV4_REASONING_EFFORT=low in the V4-Flash recipes;
  • or add a V4-Flash version to deepseek-recipe.

This PR does not change prompt rendering. Accuracy comparisons for it should pin the effort, or use a base from before #45315.

zcnrex and others added 4 commits October 27, 2026 15:12
… layer

Writers take a single IndexKScaleFmt (FP32 / POW2 / UE8M0) instead of the
round_scale + ue8m0_scale pair, matching the kernels' kScaleFmt. The ragged
DeepGEMM paths (DSA, kpool, DSV4 nonpaged) repack an FP32 index-K scale to
UE8M0 once per layer instead of once per row chunk, and pack_ue8m0_x4 is one
Triton launch instead of five torch ops with an int64 temporary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SM100 DeepGEMM returns BF16 paged logits [rows, max_seq_len]; widening the
whole buffer to FP32 copied the full CUDA-graph width (1024 x 262144 on
DeepSeek-V4-Flash TP4 MTP decode) on every C4 indexer call, ~0.8 ms each.
Copy only the columns below each row's context length, matching the
garbage-past-length contract main's FP32 kernel had.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Recovers the ~2.5% prefill regression on CC 10.7 (DeepGEMM sgl-project#125).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…assert

- CuTe DSL walks 256-token KV splits; DeepGEMM 0.2.5 schedules 384. Build
  its schedule with sglang's 256-split builder (decode, verify, and the
  backend's precomputed schedule when the backend is cutedsl).
- The k-pool's only SM100 paged reader is DeepGEMM, so it always writes
  the UE8M0 index cache there, whatever the configured backend.
- The UE8M0 assertion no longer fires under the torch fallback, and CuTe
  DSL now scores draft_extend_v2 per row instead of falling to DeepGEMM
  on an FP32-scale cache.
- test_cute_dsl_fp8_paged_mqa_logits uses the CuTe DSL schedule and adds
  a draft-extend case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zcnrex

zcnrex commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Migration scope and follow-ups

Updated for 56b3fabdee.

This PR is the self-contained DeepGEMM migration: bump to 0.2.5.post1 and adapt DSA/V3.2, V4, and V4.1 indexer callers to the replacement MQA API. No preparatory refactoring PR is required.

Keep in this PR: the compatibility adapter and required format conversions; matching kernel/schedule grouping; row caps and affected prefill memory accounting; graph-safe metadata copies; index-cache writers/readers; PD format negotiation (including older decoders); UE8M0 namespaces for HiCache, Mooncake/MORI direct linkers, and LMCache; architecture dispatch adjustments and regression tests. The new scale representation makes PD/storage protection part of the migration, even though those files do not call DeepGEMM.

Defer these three cleanup/performance tasks:

Task V3.2 / DSA V4 V4.1
Move/rename the adapter and consolidate dispatch Yes Yes Yes for shared dense/paged callers; sparse logits have a separate direct API path
Let top-k consume BF16 logits and remove FP32 widening SM100 paths that widen C4 paths that widen Low-ratio FP4 already defaults to BF16 on SM100; check FP32 overrides and other widening paths
Emit MX Q scales in the producer Plain FP8 Q paths FP8 Q paths Low-ratio FP4 already produces packed Q scales, so this particular optimization is already unnecessary there

Existing SM120 support stays in this migration: V4's FP4 flag and V4.1 dense/paged DeepGEMM paths are preserved, using SM120's 128-token schedule splits and 4096-row cap. SM120 backend defaults stay unchanged. Sparse-table MQA remains SM100-only, with the dense candidate fallback on SM120. Additional backend enablement, a new pool-format abstraction, and further tuning remain separate follow-ups. V4.1 is included in the migration, but its low-ratio FP4 path does not have the same conversion overhead as the older FP8 paths.

Validation and remaining limits: the PR description retains the accuracy/performance results with their original commit IDs; they are not claims of a fresh run on this head. Paged decode paths that widen still retain BF16 plus FP32 logits (1.5x the old logits storage), DSA metadata retains the roughly 29k-row upstream limit, and no DSA-model, PD-pair, or external-L3 E2E run has been reported. BF16 near-ties can change top-k membership. Migration correctness fixes stay here; removing conversion overhead requires a separate E2E accuracy/performance comparison.

The measured V4 C4 MTP grouping optimization remains deferred: it improved the kernel but was flat end to end in the tested workloads. See the PR's speed results for the measurements.

The SM120 fix at 56b3fabdee passed pre-commit checks and source-level probes. A subsequent run on chunan-4xb300-pr44350g (B300/SM103, torch 2.14.1+cu130, DeepGEMM 0.2.5.post1) passed all six targeted suites: 632 tests and 40 subtests passed, 18 skipped. This includes the mocked SM120 dispatch/metadata tests and all 196 reduced CuTe DSL cases. See the PR description for per-file counts. No SM120 GPU or new model E2E run was performed.

zcnrex and others added 3 commits October 28, 2026 11:00
Move the deep_gemm_mqa_logits and environ imports this PR added inside
functions to module top. deep_gemm stays lazy (optional native dependency),
and sglang.kernels.ops.attention.dsv4 stays local in dsa/utils.py (it imports
dsa.utils at load) and dsv4/metadata.py; those are aliased so the local import
no longer shadows the module-level name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…per ragged budget

- DSA target-verify on SM100 scores a request's next_n rows as one DeepGEMM
  request again (native [B, next_n] path), matching the schedule dsa_backend
  builds from [B, next_n] context lengths. The per-row call it replaced
  disagreed with that schedule's request grouping and unbalanced the SMs:
  up to 5.6x slower per call at batch 1 x 32k context on B300 (CUDA-graph
  replay), same outputs.
- The DSV4 paged indexer caps rows per DeepGEMM schedule at 16384 on SM100.
  DeepGEMM's SM100 metadata kernel keeps two ints per row in shared memory
  and asserts past ~29k rows, which the logits budget alone did not prevent.
- The DSA full-width ragged chunk budget counts 2x the keys off SM100: the
  FP32 compressed logits stay live while they expand to full width.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…60930

# Conflicts:
#	python/sglang/srt/layers/attention/dsa/dsa_indexer.py
@zcnrex
zcnrex marked this pull request as ready for review October 28, 2026 18:23
zcnrex and others added 2 commits October 28, 2026 11:40
…aph replay

PagedIndexerMetadata.copy_ rebound the per-chunk DeepGEMM schedules and top-k
plans. A captured prefill graph keeps reading the tensors it captured, so above
the row cap (16384 on SM100, 4096 on SM120) replays ran with the captured
batch's schedules and top-k plans against new lengths. When both sides chunk the
rows the same way, copy each chunk tensor in place; copy_metadata now copies
list fields element-wise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…; match kpool schedules to DeepGEMM

- PD: get_pd_kv_layout reports the index-K scale format (FP32 or DeepGEMM's
  SM100 packed UE8M0), so the bootstrap check refuses mismatched prefill and
  decode servers instead of decoding with wrong scales. A peer that reports no
  layout only matches FP32 scales. One decider, dsa_index_k_cache_is_ue8m0,
  now sets the DSA cache format.
- kpool: the schedule builders call DeepGEMM's metadata builder directly. The
  kpool kernel is always DeepGEMM, so SGLANG_FP8_PAGED_MQA_LOGITS_TORCH=1 no
  longer pairs a 256-token JIT schedule with the 384-token SM100 kernel.
- DSV4.1 low-ratio indexer: always gets DeepGEMM's schedule on SM100, also
  with SGLANG_OPT_USE_TILELANG_INDEXER=1.
- DSA cutedsl fallback schedule uses the CuTe DSL builder.
- benchmark_cute_dsl_fp8_paged_mqa_logits.py runs on DeepGEMM 0.2.5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…FP32 ones

The FP32 and packed UE8M0 index-K scale formats share their bytes, so a page
stored under one format and read under the other gives wrong top-k with no
error: after upgrading a store filled by an FP32 build, or when servers with
another GPU arch or indexer backend share a store. The storage model name now
carries "index_k-ue8m0" for a UE8M0 cache, so those pages miss instead. FP32
caches keep their old keys.

index_k_cache_is_ue8m0(kv_pool) is now the one check that both the PD layout
and the storage key use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the hicache Hierarchical Caching for SGLang label Oct 28, 2026
…coders on prefill

- The Mooncake and UMBP direct L3 linkers built their storage config from
  the bare model path, so UE8M0 and FP32 index-K pages shared keys. They now
  use with_index_k_storage_tag, the same helper HiCacheController uses.
- A decoder from before this change skips the kv_layout check when the
  prefill sends one and it has none, and accepts UE8M0 pages. Decoders now
  send their layout as decode_kv_layout on the aggregate /route query. The
  Python and Rust bootstrap servers of a UE8M0 prefill refuse a query
  without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ages

LMCache's sglang connector registers the DSA and DSV4 index-K buffers
under model_config.model_path, so UE8M0 and FP32 pages shared a namespace.
The connector now gets a copy of the model config whose model_path carries
the same index-K tag as the HiCache and direct-linker keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zcnrex zcnrex changed the title [Refactor] [NVIDIA] indexer: Move the DSA/DSV4 indexers onto DeepGEMM's fp8_fp4 MQA logits API [NVIDIA] Migrate DSA/DSV4 indexers to DeepGEMM 0.2.5.post1 Oct 28, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@kpham-sgl kpham-sgl self-assigned this Oct 29, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@zcnrex zcnrex changed the title [NVIDIA] Migrate DSA/DSV4 indexers to DeepGEMM 0.2.5.post1 [Refactor] [NVIDIA] attention: Migrate DSA/DSV4 indexers to DeepGEMM 0.2.5.post1 Oct 29, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zcnrex zcnrex changed the title [Refactor] [NVIDIA] attention: Migrate DSA/DSV4 indexers to DeepGEMM 0.2.5.post1 [Refactor] [NVIDIA] attention: Migrate DSA/DSV4 indexers to DeepGEMM 0.2.5.post2 Oct 30, 2026
@kpham-sgl

Copy link
Copy Markdown
Collaborator

Suggestion: keep the FP32 index-K cache as the default and gate the new SM100 kernel behind use_legacy, as #45893 did for FlashMLA.

  1. Why. 0.2.5 makes SM100 write UE8M0 scales into the bytes FP32 used, so this PR needs PD layout strings and storage tags, and those still leave gaps:

    If FP32 stays the default, none of these reach default users.

  2. What DeepGEMM changed (v0.2.3.post2 to v0.2.5.post2). The SM100 MQA kernel was rewritten, not tightened:

    • kIsMXSF, kCleanLogits, kIsCompressedLogits and the logits-dtype templates are gone.
    • It is MX-only, with BF16 weights and logits, a fixed 384 split, and varlen-only paged scheduling.
    • smxx_clean_logits and sm100_mqa_logits_metadata are removed.
    • SM90 and SM120 still take FP32 scales.
  3. DeepGEMM side. Keep the 0.2.3 SM100 kernel, scheduler, layout, clean-logits and host runtime under legacy names, and add use_legacy to fp8_fp4_mqa_logits, fp8_fp4_paged_mqa_logits and get_paged_mqa_logits_metadata (the schedule formats differ). With use_legacy=True that is the exact kernel main runs today.

  4. sglang side. The pool owns index_k_scale_fmt, FP32 by default, set once at construction. Today the format is re-derived in five places. Call sites pass use_legacy=pool.index_k_scale_fmt == FP32. Only UE8M0 pools report a PD layout or tag their storage keys.

  5. Open. It is not yet checked that the 0.2.3 kernel builds against 0.2.5's shared headers (smxx_layout.hpp and the TMA/UTCCP utilities changed slightly). That needs an SM100 build.

This branch has not been deployed

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

Labels

deepseek dependencies Pull requests that update a dependency file hicache Hierarchical Caching for SGLang jit-kernel memory-pool mooncake unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants