Skip to content

[DSV4] perf: Make FP8 quant output tensor contiguous - #27926

Merged
Fridge003 merged 25 commits into
sgl-project:mainfrom
mattteochen:dsv4/upstream-ue8m0-quant
Jul 8, 2026
Merged

Fridge003 merged 25 commits into
sgl-project:mainfrom
mattteochen:dsv4/upstream-ue8m0-quant

Conversation

@mattteochen

@mattteochen mattteochen commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This PR is an alternative way to achieve #27680.

Deep gemm FP8 einsum silently falls back to an unoptimized path if the input tensor is not contiguous. We can make the per_token_group_quant_8bit_v2 to emit the scale layout needed by deep gemm.

This also implicitly fixes #29038. The previous DSV4 wo_a FP8 DeepGEMM path flattened o: [T, G, D] into [T * G, D] and then viewed the scales back as [T, G, -1]. On the SM100 FP8 einsum path, scales are consumed as per-group slabs, so flattening across T * G can associate a token's FP8 codes with another group's scale. This PR quantizes o as [T, G, D] and emits the scale tensor in DeepGEMM's expected outer/group-major layout, preserving the scale[t, g] to o[t, g, :] association.

image image

Modifications

  • Extended the fp8 quant jit v2 kernel to emit dsv4 fp8 einsum required layout.
  • Added related tests.
  • Updated dsv4 model.

Accuracy Tests

== gpqa ==
198 examples x 16 repeats  |  6980.5s  |  4956 tok/s  |  34.6M tokens

* pass@1[avg-of-16]  =  88.04% +/- 1.56% (SEM 0.39%)
  pass@16            =  96.46%
  majority@16        =  90.15%
  no_answer          =  0.06%
  stop_rate          =  100.00%
  truncated_rate     =  0.00%
  error_rate         =  0.00%
== gsm8k ==
1319 examples (single-shot)  |  156.8s  |  1125 tok/s  |  176K tokens

* score           =  96.29%
  stop_rate       =  100.00%
  truncated_rate  =  0.00%
  error_rate      =  0.00%

Speed Tests and Profiling

Node: 8XB300 + DSV4-Pro

Pareto for 1k1k, no MTP:

series                            conc       TPS/user (sp)    out TPS/GPU (sp)  total TPS/GPU (sp)        TTFT ms (sp)
----------------------------------------------------------------------------------------------------------------------
base                                 4      81.90 ( 1.00x)      39.63 ( 1.00x)      79.78 ( 1.00x)     267.20 ( 1.00x)
base                                 8      70.18 ( 1.00x)      67.67 ( 1.00x)     135.75 ( 1.00x)     244.00 ( 1.00x)
base                                16      55.89 ( 1.00x)     109.25 ( 1.00x)     216.89 ( 1.00x)     244.17 ( 1.00x)
base                                32      41.89 ( 1.00x)     164.00 ( 1.00x)     328.88 ( 1.00x)     245.75 ( 1.00x)
base                                64      28.97 ( 1.00x)     231.01 ( 1.00x)     462.65 ( 1.00x)     250.78 ( 1.00x)
opt                                  4      85.37 ( 1.04x)      41.01 ( 1.03x)      82.54 ( 1.03x)     235.97 ( 1.13x)
base                                64      28.96 ( 1.00x)     230.75 ( 1.00x)     462.12 ( 1.00x)     247.41 ( 1.00x
opt                                  8      73.05 ( 1.04x)      70.42 ( 1.04x)     141.26 ( 1.04x)     234.98 ( 1.04x)
opt                                 16      57.76 ( 1.03x)     112.98 ( 1.03x)     224.30 ( 1.03x)     236.35 ( 1.03x)
opt                                 32      43.05 ( 1.03x)     168.95 ( 1.03x)     338.82 ( 1.03x)     239.09 ( 1.03x)
opt                                 64      29.63 ( 1.02x)     236.42 ( 1.02x)     473.48 ( 1.02x)     241.48 ( 1.02x)

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 #28783296006
Latest PR Test (Extra): ❌ Run #28783295767

liqichao and others added 5 commits June 10, 2026 02:43
…bit_v2

Add support for row-major FP8 quantization with UE8M0 scaling in the
per_token_group_quant_8bit_v2 CUDA kernel. When SCALE_UE8M0 is enabled
with row-major layout, the kernel now directly rounds scales to
power-of-two format, eliminating the need for a separate
deep_gemm.ceil_to_ue8m0 call.

Split from sgl-project#26582 for wheel release purposes.
…python)

Use the new row-major UE8M0 scale support in sgl-kernel to fuse the
separate deep_gemm.ceil_to_ue8m0 call into sglang_per_token_group_quant_fp8
with scale_ue8m0=True for the wo_a path.

Depends on the kernel change in the sgl-kernel PR.
Split from sgl-project#26582 for wheel release purposes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for row-major float32 scale layouts with power-of-2 values (scale_ue8m0) and outer-major scale layouts (scale_outer_major) in the per-token group quantization FP8 kernel, updating both the CUDA kernel and Python APIs, and integrating them into the DeepSeek-V4 model. Feedback on the changes suggests wrapping the deep_gemm import in a try-except block and adding a guard in the new tests to prevent ImportError and test failures on non-Hopper platforms where deep_gemm is not installed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread test/registered/quant/test_fp8_kernel.py Outdated
Comment thread test/registered/quant/test_fp8_kernel.py Outdated
@mmangkad

Copy link
Copy Markdown
Contributor

This plus #26765/#26766 together is basically the AOT version of the all-in-one JIT path I had in #27818, linking it here for context

cc @b8zhong

@mattteochen
mattteochen marked this pull request as ready for review June 22, 2026 13:32
Comment thread python/sglang/srt/layers/quantization/fp8_kernel.py Outdated
Comment thread python/sglang/srt/layers/quantization/fp8_kernel.py Outdated
Comment thread python/sglang/srt/models/deepseek_v4.py Outdated
Comment thread python/sglang/srt/models/deepseek_v4.py Outdated
@mattteochen

Copy link
Copy Markdown
Contributor Author

On B300 with eval commands from #29036:

== gpqa ==
198 examples (single-shot)  |  1796.4s  |  1146 tok/s  |  2.1M tokens

* score           =  89.39%
  stop_rate       =  100.00%
  truncated_rate  =  0.00%
  error_rate      =  0.00%

@mattteochen

Copy link
Copy Markdown
Contributor Author

Updated Pareto 1k1k 8xB300 DSV4-pro low latency config no MTP:
image

series                            conc       TPS/user (sp)    out TPS/GPU (sp)  total TPS/GPU (sp)        TTFT ms (sp)
----------------------------------------------------------------------------------------------------------------------
base                                 4      85.32 ( 1.00x)      41.72 ( 1.00x)      83.98 ( 1.00x)      87.86 ( 1.00x)
base                                 8      77.83 ( 1.00x)      75.20 ( 1.00x)     150.85 ( 1.00x)      89.23 ( 1.00x)
base                                16      65.91 ( 1.00x)     128.43 ( 1.00x)     254.98 ( 1.00x)      92.10 ( 1.00x)
base                                32      52.37 ( 1.00x)     202.78 ( 1.00x)     406.65 ( 1.00x)      97.33 ( 1.00x)
base                                64      39.37 ( 1.00x)     307.24 ( 1.00x)     615.31 ( 1.00x)     103.96 ( 1.00x)
opt                                  4      89.95 ( 1.05x)      43.95 ( 1.05x)      88.48 ( 1.05x)      85.59 ( 1.03x)
opt                                  8      82.34 ( 1.06x)      79.50 ( 1.06x)     159.47 ( 1.06x)      86.41 ( 1.03x)
opt                                 16      69.19 ( 1.05x)     134.75 ( 1.05x)     267.51 ( 1.05x)      89.23 ( 1.03x)
opt                                 32      54.50 ( 1.04x)     211.11 ( 1.04x)     423.36 ( 1.04x)      94.28 ( 1.03x)
opt                                 64      40.45 ( 1.03x)     313.63 ( 1.02x)     628.10 ( 1.02x)     101.19 ( 1.03x)

@mattteochen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@mattteochen
mattteochen requested a review from Fridge003 July 6, 2026 12:48
@mattteochen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

1 similar comment
@mattteochen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/models_e2e/test_deepseek_v4_flash_fp4_h200.py test/registered/models_e2e/test_deepseek_v4_flash_fp8_h200.py 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 test/registered/disaggregation/test_disaggregation_dsv4.py

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/gb300/test_deepseek_v4_pro_fp4.py

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/models_e2e/test_deepseek_v4_flash_fp4_h200.py test/registered/models_e2e/test_deepseek_v4_flash_fp8_h200.py 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 test/registered/disaggregation/test_disaggregation_dsv4.py:

🚀 8-gpu-h200 (3 tests): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_deepseek_v4_flash_fp4_h200.py
cd test/ && python3 registered/models_e2e/test_deepseek_v4_flash_fp8_h200.py
cd test/ && python3 registered/disaggregation/test_disaggregation_dsv4.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

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/gb300/test_deepseek_v4_pro_fp4.py:

⛔ test/registered/gb300/test_deepseek_v4_pro_fp4.py: Suite nightly-4-gpu-gb300-deepseek-v4-pro-fp4 in test/registered/gb300/test_deepseek_v4_pro_fp4.py is not dispatchable via /rerun-test. It has no entry in _LEGACY_SUITE_TO_RUNNER_CONFIG — either it is a non-CUDA suite (npu/amd) or it runs on hardware with no matching runner_config in scripts/ci/runner_configs.yml.

@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/jit/deepseek_v4/test_fp8_wo_a.py

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/jit/deepseek_v4/test_fp8_wo_a.py:

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

cd test/ && python3 registered/jit/deepseek_v4/test_fp8_wo_a.py

@Fridge003
Fridge003 merged commit d7dcdf3 into sgl-project:main Jul 8, 2026
380 of 451 checks passed
Fridge003 pushed a commit that referenced this pull request Jul 8, 2026
…ensor contiguous (#27926) (#30449)

Co-authored-by: Kaixi <matteochen3@gmail.com>
Co-authored-by: liqichao <liqichao@baidu.com>
Co-authored-by: chenbong <bhchen@stu.xmu.edu.cn>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
…ensor contiguous (sgl-project#27926) (sgl-project#30449)

Co-authored-by: Kaixi <matteochen3@gmail.com>
Co-authored-by: liqichao <liqichao@baidu.com>
Co-authored-by: chenbong <bhchen@stu.xmu.edu.cn>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Co-authored-by: liqichao <liqichao@baidu.com>
Co-authored-by: chenbong <bhchen@stu.xmu.edu.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek jit-kernel quant LLM Quantization run-ci CI: run the baseline test suite on this PR sgl-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DeepSeek-V4 FP8 wo_a DeepGEMM path can lower accuracy on Blackwell

4 participants