Repository navigation
Conversation
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]>
…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]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
|
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
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
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
This PR does not change prompt rendering. Accuracy comparisons for it should pin the effort, or use a base from before #45315. |
… 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]>
Migration scope and follow-upsUpdated for 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:
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 |
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
…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]>
…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]>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Suggestion: keep the FP32 index-K cache as the default and gate the new SM100 kernel behind
|
Purpose and scope
Upgrade
sgl-deep-gemmfrom 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_logitsand changed thefp8_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
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.The dependency pin changes in
python/pyproject.tomlanddocker/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
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
Accuracy Tests
The results below were measured with
sgl-deep-gemm0.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 onchunan-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.56b3fabdeetest_dsv4_nonpaged_indexertest_paged_mqa_metadatatest_deepgemm_paged_mqa_logitstest_cute_dsl_fp8_paged_mqa_logits(reduced cases)test_fp4_indexertest_dsv41_prefill_sparse_indexerSM100: B300 (SM103),
sgl-deep-gemm==0.2.5.post1, PR headdabf3a9ce9(merged with mainf1a36c4789), torch 2.14.1+cu130, one pytest per file:test_cute_dsl_fp8_paged_mqa_logitstest_deepgemm_paged_mqa_logitstest_paged_mqa_metadatatest_fp4_indexertest_dsv4_nonpaged_indexertest_kv_checksumtest_dsa_indexertest_fused_store_index_cachetest_kpool_stream_schedulingtest_dsv32_indexer_fusiontest_dsv41_prefill_sparse_indexertest_dense_prefill_indexertest_dsa_mqa_logits_chunkingtest_dsa_kpool_deepgemm_logitstest_dsa_sharded_pd_transfertest_dsv4_unified_fp8_pdAt head
f42c4847d9(HiCache keys), on the same setup:test_pd_index_k_scale_layout5 (+10 subtests), plus the HiCache tests that build storage keys:test_hicache_storage_format_tag4,test_hicache_dcp_host_pool18,test_hicache_unified_key_scheme24,test_hicache_file_lru_unit41,test_hicache_storage_registration_hook5,test_pp_prefetch_ticket17,test_scheduler_hicache_attach2.test_unified_hicache_transfer_lifecycle(4 failed) and the tensorcast store test (notensorcastmodule) 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_store7 (+54 subtests) / 1 skipped (gfx950 only),test_dsv4_unified_fp8_compress_store8 skipped (AMD gfx95 only).copy_, every chunk tensor keeps its address and matches freshly built metadata.[batch, next_n]path is bitwise equal to the one-row-per-token path: 72 ad hoc cases (batch {1, 3, 8} xnext_n{2, 3, 4, 6} x heads {32, 64} x context {128, 1024, 16384}) and the 5 shapes in the speed table below.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), andcalc_diffis about 1e-5. On SM100 it now checkscalc_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):
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_logitsfails 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:
test/manual/dsv4/test_b300_flash.py(TP4,flashinfer_mxfp4, EAGLE 3/1/4).test/manual/dsv4/_common.pydefaults).e7c55f695992213811fd4da6f585f35a4b7e7097(0.2.5.post1) 0.965, maine7c55f69590.968, within main's own run-to-run spread (0.965–0.968).reasoning_efforton V4-Flash as the "Absolute maximum" effort prompt. WithSGLANG_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.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_servingrandom 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%.e7c55f69595a4b7e7097DSA SM100 target-verify, paged MQA logits (B300,
next_n= 4, 64 heads, CUDA-graph replay, µs per call):[batch, next_n], per-row call (before887f7e07b6)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