Skip to content

[DeepSeek-V4] Fuse UE8M0 scale rounding into FP8 group quantization - #26766

Merged
Fridge003 merged 9 commits into
sgl-project:mainfrom
JoeLee314:pr-26582-python
Jun 18, 2026
Merged

Fridge003 merged 9 commits into
sgl-project:mainfrom
JoeLee314:pr-26582-python

Conversation

@JoeLee314

@JoeLee314 JoeLee314 commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This PR optimizes the DeepSeek-V4 wo_a FP8 path by removing the separate deep_gemm.ceil_to_ue8m0 call after activation quantization.

The original path launches quantization first, then rounds the generated FP8 scales to UE8M0/power-of-two format:

sglang_per_token_group_quant_fp8 -> deep_gemm.ceil_to_ue8m0 -> deep_gemm.fp8_einsum

The optimized path emits the rounded power-of-two scale directly from the per-token group quantization kernel:

sglang_per_token_group_quant_fp8(scale_ue8m0=True) -> deep_gemm.fp8_einsum

Performance Test

DeepSeek-V4-Flash, TP=4, 32K input / 1K output, 128 requests, max concurrency 4.

Output token throughput increased by 7.8%.
image
image

Accuracy Tests

GSM8K score: 0.928

Update: precision fix on Blackwell (B300/B200)

The initial fused kernel in this PR had a precision issue on Blackwell: in the
SCALE_UE8M0 && !IS_COLUMN_MAJOR branch, activations were quantized with the
exact FP32 scale while only the output scale was rounded to UE8M0 (power-of-2).
Since quantization and dequantization then used mismatched scales, EAGLE
speculative decoding accept_length dropped from 2.76 to 2.69 on B300/B200.

Thanks to @yhyang201 for catching this and providing the fix. The special branch
is removed and all UE8M0 paths now go through calculate_fp8_scales<SCALE_UE8M0=true>,
which computes the rounded (power-of-2) scale first and quantizes with it — matching
the official DeepSeek-V4 kernel.py act_quant(scale_fmt="ue8m0"). The row-major
UE8M0 test now asserts the scales are exact powers of 2 and the fp8 codes match the
ceil_to_ue8m0 reference.


CI States

Latest PR Test (Base): 🚫 Run #27789934317
Latest PR Test (Extra): ✅ Run #27791183010

@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!

@yhyang201

Copy link
Copy Markdown
Collaborator

Hi, could you ping me on slack? My name is Yuhao Yang.

Co-authored-by: Yuhao Yang <47235274+yhyang201@users.noreply.github.com>

Change-Id: I206d621f90d11b1e2ae42db8ae92b0bd782d5ced
@yhyang201

Copy link
Copy Markdown
Collaborator

Reason for the second commit: #28307

The row-major + SCALE_UE8M0 path quantized with an exact FP32 scale
and only rounded the output scale_inv to power-of-2. This caused a
scale mismatch: FP8 values quantized with one scale, GEMM dequants
with another, amplifying error ~14x (31% average relative error).

On Blackwell (SM100) where DeepGEMM uses native UE8M0 hardware
scaling, this mismatch fully exposed, dropping EAGLE accept_length
from 2.76 (H200) to 2.69 (B300). Hopper (SM90) was less affected
because it uses FP32 scale post-correction.

Fix: use calculate_fp8_scales<SCALE_UE8M0=true> for all UE8M0 paths,
which computes the rounded scale first then quantizes with it. This
matches the official DeepSeek-V4 kernel.py act_quant(scale_fmt="ue8m0").

Results (DSV4-Flash EAGLE spec decode, GSM8K 200 prompts):
  H200 (SM90):  2.76 → 2.76 (unchanged)
  B300 (SM100): 2.69 → 2.77 (+0.08)

Change-Id: Ic011b2dd16a6eb5d41955b2a705e623aaf03b6b4
@Fridge003

Copy link
Copy Markdown
Collaborator

@yuhao318 Please add acc results on harder benchmarks like AIME25

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@Fridge003 Fridge003 added the run-ci-extra CI: also run the extra suite (requires run-ci) label Jun 15, 2026
@yhyang201

Copy link
Copy Markdown
Collaborator

AIME25 Accuracy Report

Model: DeepSeek-V4-Flash
Hardware: 8x NVIDIA B300 SXM6 AC (SM100)
Config: TP=4, EAGLE (num_steps=3, topk=1, draft_tokens=4), flashinfer_mxfp4, chunked_prefill=4096, disable_flashinfer_autotune
Branch: PR #26766 (pr-26582-python, includes fused scale_ue8m0=True in quant kernel)
Eval tool: sgl-eval v0.0.1, AIME25, 30 problems x 16 repeats, temp=1.0, top_p=1.0, max_tokens=400000

Metric Value
pass@1 (avg-of-16) 93.75% (+/- 2.95%, SEM 0.74%)
majority@16 96.67%
pass@16 100.00%
score 93.75%
no_answer rate 0.21%
output throughput 5742.6 tok/s
total completion tokens 15,439,750
total latency 2688.6s (44.8 min)

@JoeLee314

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/models_e2e/test_deepseek_v4_flash_fp4_b200.py test/registered/models_e2e/test_deepseek_v4_flash_fp4_megamoe_b200.py test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/models_e2e/test_deepseek_v4_flash_fp4_b200.py test/registered/models_e2e/test_deepseek_v4_flash_fp4_megamoe_b200.py test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py:

🚀 4-gpu-b200 (3 tests): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_deepseek_v4_flash_fp4_b200.py
cd test/ && python3 registered/models_e2e/test_deepseek_v4_flash_fp4_megamoe_b200.py
cd test/ && python3 registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@Fridge003

Copy link
Copy Markdown
Collaborator

/reurn-test test/registered/jit/test_per_token_group_quant_8bit_v2.py

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/4-gpu-models/test_deepseek_v3_cutedsl_4gpu.py test/registered/models_e2e/test_deepseek_v3_fp4.py

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/4-gpu-models/test_deepseek_v3_cutedsl_4gpu.py test/registered/models_e2e/test_deepseek_v3_fp4.py:

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

cd test/ && python3 registered/4-gpu-models/test_deepseek_v3_cutedsl_4gpu.py

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

cd test/ && python3 registered/models_e2e/test_deepseek_v3_fp4.py

@Fridge003
Fridge003 merged commit bea282c into sgl-project:main Jun 18, 2026
84 of 128 checks passed
@Fridge003 Fridge003 added the release-highlight Candidate PR for release note highlight label Jun 18, 2026
JustinTong0323 added a commit to JustinTong0323/sglang that referenced this pull request Jun 19, 2026
main advanced 15+ commits since the last merge (sgl-project#28598 base), making the PR
CONFLICTING and blocking pr-test. Resolve the one content conflict in
python/sglang/srt/layers/quantization/fp8_kernel.py by taking main's version
(byte-identical): main added the row-major UE8M0 scale path (sgl-project#26766 DSV4 UE8M0
fusion) as a superset of our column-major+tma-aligned path, and hardcodes
//128 which is correct for UE8M0 (group fixed at 128). Everything else
auto-merged from main.
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
…gl-project#26766)

Co-authored-by: liqichao <liqichao@baidu.com>
Co-authored-by: yhyang201 <yhyang201@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek high priority jit-kernel quant LLM Quantization release-highlight Candidate PR for release note highlight run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants