Skip to content

Add FP4 Indexer for DeepSeek V4 on SM120 - #27059

Merged
ch-wan merged 2 commits into
sgl-project:mainfrom
liz-badada:sm12x-fp4-indexer-upstream
Jul 24, 2026
Merged

ch-wan merged 2 commits into
sgl-project:mainfrom
liz-badada:sm12x-fp4-indexer-upstream

Conversation

@liz-badada

@liz-badada liz-badada commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Follow-up to #26209, extends the FP4 Indexer to SM120 (depends on sgl-project/DeepGEMM#56).

Accuracy

DeepSeek V4 Flash GSM8K

Accuracy
Default FP8 95.5%
FP4 indexer 93.0%

Performance

Two sets of results are reported because they were collected on different SGLang software stacks. They use the same model, workload, and FP8-versus-FP4 indexer comparison, but different SM120 main-attention backends. Therefore, each table is a valid within-stack A/B comparison, while the absolute numbers across the two tables are not directly comparable as a regression test.

Test configurations

Setting Original PR measurement Latest validation
SGLang source 5453e93c50 Tested at 245a47444c; tree identical to current squashed PR head 9f100e6e27
DeepGEMM source deepseek-ai/DeepGEMM#324 sgl-project/DeepGEMM#55
Hardware 4x SM120 4x SM120
FlashInfer Not used for SM120 attention 0.6.14
SM120 attention backend Triton FlashInfer
Baseline indexer Torch FP8 Torch FP8
Optimized indexer DeepGEMM FP4 DeepGEMM FP4
Model DeepSeek-V4-Flash DeepSeek-V4-Flash
Tensor parallelism TP4 TP4
Workload 8 prompts, 8192 input tokens, 256 output tokens, concurrency 8, seed 3 Same
MoE backend Marlin Marlin
Chunked prefill 4096 4096
Radix cache Disabled Disabled
CUDA Graph Maximum decode batch size 16 Maximum decode batch size 16

The latest validation explicitly selected the supported SM120 FlashInfer paged-attention path:

export SGLANG_SM120_FLASHMLA_BACKEND=flashinfer
export SGLANG_OPT_DSV4_NONPAGED_INDEXER=0
export SGLANG_OPT_FLASHMLA_SPARSE_PREFILL=0

SGLANG_OPT_DSV4_NONPAGED_INDEXER=0 ensures that the paged indexer path covered by DeepGEMM PR #55 is exercised. Sparse prefill was disabled to isolate the supported FlashInfer paged path on SM120.

Latest validation: FlashInfer attention

SGLang tested commit: 245a47444c
Current PR head: 9f100e6e27
Both commits have the same Git tree: dce05ad8fc61e17e0062bbafa376fc54cd8f95ae.

Both cases completed all 8 requests successfully.

Metric Default FP8 Indexer FP4 Indexer Change
Successful requests 8/8 8/8 -
Request throughput 0.155116 req/s 0.389084 req/s +150.83%
Input throughput 1270.710 tok/s 3187.374 tok/s +150.83%
Output throughput 39.7097 tok/s 99.6054 tok/s +150.83%
Mean E2E latency 51.447145 s 20.533064 s -60.09%
Mean TTFT 12.946906 s 9.395233 s -27.43%
Mean TPOT 150.981 ms 43.678 ms -71.07%

The latest server command was:

export SGLANG_SM120_FLASHMLA_BACKEND=flashinfer
export SGLANG_OPT_DSV4_NONPAGED_INDEXER=0
export SGLANG_OPT_FLASHMLA_SPARSE_PREFILL=0

python3 -m sglang.launch_server \
  --model-path /models/DeepSeek-V4-Flash \
  --served-model-name deepseek-ai/DeepSeek-V4-Flash \
  --host 127.0.0.1 \
  --port 31720 \
  --trust-remote-code \
  --tp 4 \
  --moe-runner-backend marlin \
  --chunked-prefill-size 4096 \
  --mem-fraction-static 0.70 \
  --disable-flashinfer-autotune \
  --disable-radix-cache \
  --skip-server-warmup \
  --cuda-graph-max-bs-decode 16

For the FP4 case, the same command was used with:

--enable-deepseek-v4-fp4-indexer

The current benchmark entry point has moved from sglang.bench_serving to sglang.benchmark.serving:

python3 -m sglang.benchmark.serving \
  --backend sglang \
  --host 127.0.0.1 \
  --port 31720 \
  --model deepseek-ai/DeepSeek-V4-Flash \
  --tokenizer /models/DeepSeek-V4-Flash \
  --dataset-name random-ids \
  --random-input-len 8192 \
  --random-output-len 256 \
  --random-range-ratio 1 \
  --num-prompts 8 \
  --max-concurrency 8 \
  --seed 3 \
  --output-file benchmark.jsonl

Although --skip-server-warmup was used in the latest run, the benchmark client performed its default warmup request before starting the timed region.

Original measurement: Triton attention

SGLang commit: 5453e93c50

At this revision, the SM120 attention implementation selected Triton by default through SGLANG_SM120_TRITON_FLASHMLA=1.

Metric Default FP8 Indexer FP4 Indexer Change
Input throughput 148.52 tok/s 159.58 tok/s +7.45%
Output throughput 4.641 tok/s 4.987 tok/s +7.45%
Mean E2E latency 440.97 s 410.49 s -6.91%
Mean TTFT 237.20 s 233.58 s -1.53%
Mean TPOT 799.11 ms 693.75 ms -13.19%

The original server command was:

python3 -m sglang.launch_server \
  --model-path /models/DeepSeek-V4-Flash \
  --served-model-name deepseek-ai/DeepSeek-V4-Flash \
  --host 0.0.0.0 \
  --port 31720 \
  --trust-remote-code \
  --tp 4 \
  --moe-runner-backend marlin \
  --chunked-prefill-size 4096 \
  --mem-fraction-static 0.70 \
  --disable-flashinfer-autotune \
  --disable-radix-cache \
  --cuda-graph-max-bs 16

For the FP4 case, the same command was used with:

--enable-deepseek-v4-fp4-indexer

The benchmark command was:

python3 -m sglang.bench_serving \
  --backend sglang \
  --host 127.0.0.1 \
  --port 31720 \
  --model deepseek-ai/DeepSeek-V4-Flash \
  --tokenizer /models/DeepSeek-V4-Flash \
  --dataset-name random-ids \
  --random-input-len 8192 \
  --random-output-len 256 \
  --random-range-ratio 1 \
  --num-prompts 8 \
  --max-concurrency 8 \
  --seed 3

Why the percentage improvement changed

The two result sets are not contradictory. The following decomposition shows what changed:

Stack FP4 E2E Additional time observed with the FP8 indexer (FP8 - FP4) FP8 E2E E2E reduction from FP4
Original Triton stack 410.49 s +30.48 s 440.97 s 6.91%
Latest FlashInfer stack 20.53 s +30.91 s 51.45 s 60.09%

The FP8 indexer adds approximately 31 seconds in both measurements. The major change is that the FP4 path, which represents the rest of the model plus the faster indexer, decreased from 410.49 seconds to 20.53 seconds on the newer stack.

On the original stack, the approximately 30.48-second saving was small relative to the 440.97-second total, so E2E latency improved by only 6.91%. On the latest stack, the surrounding model path became much faster while the FP8-indexer overhead remained approximately 31 seconds. Removing that overhead reduced E2E latency from 51.45 seconds to 20.53 seconds, or 60.09%.

For the fixed-concurrency workload, benchmark duration decreased from approximately 51.57 seconds to 20.56 seconds. Throughput is inversely proportional to duration for a fixed amount of work, so this is a 51.57 / 20.56 = 2.508x throughput ratio, reported as a 150.83% increase.

Therefore, the larger percentage does not mean that the FP4 indexer itself suddenly became several times faster. Its absolute E2E benefit remained approximately 31 seconds. The newer SGLang stack made the surrounding SM120 attention and model-execution path much faster, exposing the FP8 indexer as the dominant remaining bottleneck.

The full cross-run speedup should not be attributed solely to FlashInfer because the SGLang revisions also differ by roughly six weeks of development. A backend-only experiment on one fixed SGLang revision would be required to isolate the exact contribution of the attention backend.

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.

CI States

Latest PR Test (Base): ❌ Run #29984983462
Latest PR Test (Extra): ❌ Run #29984983412

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@liz-badada liz-badada changed the title Enable DeepSeek V4 FP4 indexer on SM120 FP4 indexer on SM120 Jun 2, 2026
@liz-badada liz-badada changed the title FP4 indexer on SM120 Add FP4 Indexer for DeepSeek V4 on SM120 Jun 2, 2026
@liz-badada
liz-badada marked this pull request as ready for review June 9, 2026 09:39
liz-badada added a commit to liz-badada/DeepGEMM that referenced this pull request Jun 30, 2026
Extract only the paged FP4 MQA path required by sgl-project/sglang#27059 from deepseek-ai#324. The upstream feature commit 9160119 is not independently cherry-pickable because it relies on earlier SM120 JIT, MMA, and scheduler refactors, so this commit carries only the leaf support missing from sgl/dev.\n\nThe supported contract is intentionally limited to next_n=1, 64 query heads, head_dim=128, block_kv=64, FP32 logits, 2-D context lengths, and no varlen indices. Dense MQA, FP8 MQA, BF16 logits, wider shape support, and SM121 family reuse are deliberately excluded.
liz-badada added a commit to liz-badada/DeepGEMM that referenced this pull request Jun 30, 2026
Extract only the paged FP4 MQA path required by sgl-project/sglang#27059 from deepseek-ai#324. The upstream feature commit 9160119 is not independently cherry-pickable because it relies on earlier SM120 JIT, MMA, and scheduler refactors, so this commit carries only the leaf support missing from sgl/dev.

The supported contract is intentionally limited to next_n=1, 64 query heads, head_dim=128, block_kv=64, FP32 logits, 2-D context lengths, and no varlen indices. Dense MQA, FP8 MQA, BF16 logits, wider shape support, and SM121 family reuse are deliberately excluded.
liz-badada added a commit to liz-badada/DeepGEMM that referenced this pull request Jul 1, 2026
Extract only the paged FP4 MQA path required by sgl-project/sglang#27059 from deepseek-ai#324. The upstream feature commit 9160119 is not independently cherry-pickable because it relies on earlier SM120 JIT, MMA, and scheduler refactors, so this commit carries only the leaf support missing from sgl/dev.

The supported contract is intentionally limited to next_n=1, 64 query heads, head_dim=128, block_kv=64, FP32 logits, 2-D context lengths, and no varlen indices. Dense MQA, FP8 MQA, BF16 logits, wider shape support, and SM121 family reuse are deliberately excluded.
@liz-badada
liz-badada force-pushed the sm12x-fp4-indexer-upstream branch from 5453e93 to 9f100e6 Compare July 13, 2026 03:18
@liz-badada

Copy link
Copy Markdown
Collaborator Author

/tag-run-ci-label

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 13, 2026
@liz-badada

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@liz-badada

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

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.

Can we skip this for now. We can reenable it after deepgemm is ready

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

@liz-badada
liz-badada force-pushed the sm12x-fp4-indexer-upstream branch from 9f100e6 to 90398a6 Compare July 23, 2026 06:23
@ch-wan

ch-wan commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

/rerun-test test_dsv4_nonpaged_indexer.py‎

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_dsv4_nonpaged_indexer.py:

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

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

@ch-wan
ch-wan merged commit 1e69765 into sgl-project:main Jul 24, 2026
185 of 203 checks passed
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants