Repository navigation
[Perf] SM120: honour SGLANG_OPT_DEEPGEMM_HC_PRENORM for the DeepSeek-V4.1 compensated mhc projection - #47658
Conversation
…V4.1 compensated mhc projection On SM120 the DeepSeek-V4.1 hyper-connection pre-norm always runs _hc_mix_stats_partial_kernel, while SM90/SM100 run the compensated _hc_mix_stats_bf16x3_kernel for the same shapes. The load-time gate that builds bf16_parts requires (is_sm100 or is_sm90), so the explicit opt-in that the is_set() guard in arg_groups/model_hook.py is designed to allow is silently ignored on SM120. Add is_sm120 to the two arch gates and route SM120 into the SM90 branch, which builds the bf16 triple with pure Triton and does not require DeepGEMM; the tf32 branch is left untouched because deep_gemm.tf32_hc_prenorm_gemm has not been verified on this card. Measured on 8x RTX PRO 5000 (SM120, PCIe only), single stream, 60 x 8192 input tokens: with both conditions on, GPU busy 482.52 -> 447.66 ms per prefill step (-8.6% against a same-day stock control), wall-clock p50 491.1 -> 455.0 ms, mhc family 94.76 -> 56.02 ms/step. Either condition alone is a no-op. Cost: the bf16 weight triple is resident, so the KV pool shrinks 6,168,576 -> 6,018,048 tokens (-2.44%). Kernel-level deviation against a fp32 reference is at the incumbent path's own level. No default behaviour changes on any platform.
Pins the three things the change claims, in one file registered on 1-gpu-small (scripts/ci/runner_configs.yml maps that tier to 1-gpu-5090, so the SM120 branch executes here instead of skipping on a mismatched card): - with SGLANG_OPT_DEEPGEMM_HC_PRENORM opted in, SM120 builds the bf16 triple and never the tf32 one, even when ENABLE_JIT_DEEPGEMM is on and deep_gemm.tf32_hc_prenorm_gemm exists; with the env unset nothing is built, so the default pays no resident memory; - rows inside [4096, 65536] reach hc_mix_stats_sinkhorn_bf16x3 and match an fp64 mirror of the reduce arithmetic at the tolerances the existing Hopper test uses (rtol 1e-5, atol 2e-6); - rows outside that band (decode at 1 row, small prefill at 64) stay on the split-K partial kernel, asserted by making the compensated kernel raise. Ran on 8x RTX PRO 5000 (capability (12,0)), sglang 0.5.22: 6 passed. Reverting the two arch conjuncts and the routing in a shadow copy of the package turns exactly the three gated cases red and leaves the other three green, so the file discriminates on this change rather than on a diff being present.
|
@BBuf @DarkSharpness one question about the arch whitelist this PR touches, because the answer decides whether the PR is right.
So: is SM120 excluded from Two pieces of evidence, since "trust us, we measured" is not much on its own.
What we are not claiming: no CI has run on this PR yet (it still needs a We are not asking to flip the SM120 default in this PR. The cost lands as soon as the env is on - |
run_suite executes a registered file as `python3 file.py -f` (ci_utils.run_unittest_files; the fork worker does runpy.run_path with run_name="__main__"), so a pytest-style file without that block collects nothing and the tests never execute. test/README.md requires the block, and collect_tests() raises ValueError when an enabled registry lacks it, which would fail the whole base-b shard at collection. Adds the pytest form the README specifies -- same shape as the sibling mhc tests in this directory. Verified with ruff 0.15.1 (check + format), isort 7.0.0 and codespell 2.4.1 on the patched file.
Measured on capability (12,0): sgl-deep-gemm is a fork and ships sm120_tf32_hc_prenorm_gemm, so the tf32 branch below is reachable and does run on SM120. What keeps us off it is measurement, not availability -- against an fp64 mirror of the reduce arithmetic tf32 sits 1.61e-05 max-relative at M=1024 where the split-K path SM120 runs today sits 2.15e-06, and it builds weight parts at every row count rather than only where the compensated projection is used.
|
Self-correction on the comment above: we have now verified the thing we called unverified, and the answer changes our rationale, not the patch.
Why the SM90 branch is still the right call, measured against an fp64 mirror of
The body and the code comment now carry these measurements instead of "unverified". The question we asked is still open and we still have no answer for it: was the SM120 opt-out a known blocker on the compensated path, or the absence of verification? If it is the former, say so and we will close this. One unrelated fix rode along in the same push: the new test file lacked the |
|
[BBuf Review Agent] @xulunfan The code keeps the SM120 default off and limits the resident-weight cost to explicit opt-ins. @DarkSharpness, was the bf16x3 exclusion tied to a known blocker, or are we OK opening this path? |
BBuf
left a comment
There was a problem hiding this comment.
LGTM. Please wait for the SM120 CI cases to pass.
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
3 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
[BBuf Review Agent] Could you merge the latest main into this branch? CI's maintenance gate won't run the tests until it does. |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
[BBuf Review Agent] @xulunfan these still fail after a rerun, and I can't tell from the logs whether it's this PR. Could you take a look?
|
|
@BBuf Took a look — that failure is not from this PR. The failing file is main's own diffusion test. In the log for That leg installs On this PR's side: the SM120 dispatch test ran 6 passed / 0 skipped on an SM12x runner ( |
|
[BBuf Review Agent] @xulunfan Confirmed at this head: the B300 leg installs without the diffusion extra, but the test imports diffusers at module load. The test and CI setup are unchanged by this PR, so I'm treating this failure as unrelated. |
|
Thanks for confirming. With that leg treated as unrelated, the PR is ready on our side — leaving the merge to you whenever convenient. |
Motivation
On SM120 (Blackwell consumer/workstation, capability 12.0) the DeepSeek-V4.1
hyper-connection pre-norm always runs the batch-invariant split-K projection
(
_hc_mix_stats_partial_kernel), while SM90/SM100 run the compensatedthree-bf16 projection (
_hc_mix_stats_bf16x3_kernel) for the same shapes._mix_stats_impl()already enters the fused block on SM120, becauseuse_fused_statstestsget_platform().is_blackwell, which covers capabilitymajors {10, 11, 12}. What SM120 cannot reach is the compensated branch:
use_bf16_projectionneedsbf16_parts, andbf16_partsis only built whenthe load-time gate in
deepseek_v4.pypasses, which requires(is_sm100 or is_sm90).That gate also requires
envs.SGLANG_OPT_DEEPGEMM_HC_PRENORM. The env defaultis
True, butarg_groups/model_hook.pyturns it off for SM120:The
is_set()guard means a user may opt in explicitly. Today that opt-in issilently ignored on SM120, because the arch whitelist still rejects it: setting
the env changes nothing, and there is no log line saying so. This PR makes the
existing opt-in work. It does not change any default, on any platform.
What changes
Three arch conditions across two modules, plus routing SM120 into the branch that
does not need DeepGEMM, plus one test file that runs on this architecture:
deepseek_v4.py: addis_sm120to thebf16_partsbuild gate, and to theif get_platform().is_sm90:branch that builds the bf16 triple directly.deepseek_v4_mhc.py: addis_sm120to the_mix_stats_implgate that readshc.tf32_parts / hc.bf16_parts.test/registered/kernels/ops/layernorm/test_mhc_bf16x3_sm120.py: new, registeredon
1-gpu-small, whichscripts/ci/runner_configs.ymlmaps to1-gpu-5090, sothe SM120 branch executes in CI rather than skipping on a mismatched card.
SM120 joins the SM90 branch on purpose. The
elsebranch also builds tf32 partsand dispatches
deep_gemm.tf32_hc_prenorm_gemm, and that kernel does run here --sgl-deep-gemmis a fork and shipssm120_tf32_hc_prenorm_gemm, present in the0.2.2 build we measured and in the 0.2.3.post2 wheel
mainpins. We still takethe pure-Triton SM90 branch, because tf32 is the less accurate of the two on this
card: against an fp64 mirror of the reduce arithmetic it sits 1.61e-05
max-relative at M=1024 where the split-K path SM120 runs today sits 2.15e-06, and
in band bf16x3 is both faster and closer to the reference (6.93e-06 vs 1.65e-05 at
M=4096). The tf32 branch also builds parts at every row count, so taking it would
move rows below 4096 onto that kernel by default -- a change this PR does not
measure. Adding
is_sm120to the whitelist without this routing is a different,untested change and is not what this PR proposes.
Mechanism boundary: which calls this actually reaches
Two gates are in series, and both have to hold:
SGLANG_OPT_DEEPGEMM_HC_PRENORM,which decides whether
bf16_partsis built at all;use_bf16_projection = bf16_parts is not None and (hopper_medium or 4096 <= rows <= 65536).hopper_mediumis SM90-only, so on SM120 the compensated projection is reachedonly for row counts inside
[4096, 65536]. Decode (rows == 1) keepshc_mix_stats_sinkhornon both arms; long-output and small-batch prefill shapesare likewise outside the band. Under
--enable-decoder-swa-bounded-replay, 49%of the 80
mix_statscalls per step land in band (2360 bf16x3 vs 2440 partialover 60 steps); the out-of-band calls are small-row and already cost 0.020 ms
each. That is why the family saving is 38.5 ms/step rather than the full 50.05
ms/step the projection kernel alone accounts for.
One caveat for anyone reading a per-kernel diff: the two wrappers share
_hc_mix_reduce_sinkhorn_kernel. Identical call count (4800 over 60 steps), but2.72 -> 0.84 ms/step, because the reduce gets cheaper once the projection output
changes shape. A shared kernel is not automatically excluded from the delta.
Measurements
8x NVIDIA RTX PRO 5000 Blackwell 72GB (SM120, capability (12,0)), PCIe only
(
nvidia-smi topo -mall PHB, no NVLink), torch 2.14.1+cu130, SGLang 0.5.22 +sgl-deep-gemm 0.2.2, a
deepseek_v41MoE checkpoint (hidden_size 5120, 40layers, hc_mult 4), TP8/EP8,
--chunked-prefill-size 16384,--mem-fraction-static 0.78,--enable-decoder-swa-bounded-replay,--context-length 131072.Workload: single stream, 60 requests x 8192 input tokens x 1 output token,
prefix cache flushed before each run, profiler started before traffic, window
purity checked from the engine log (
#new-token: 8192delta == 60).2x2 over the two conditions (same day, same machine, ms per 8192-token prefill
step):
=1=1Both single-condition arms are no-ops (p50 492.5 / 492.7 / 492.5, and the
projection kernel stays
_hc_mix_stats_partial_kernelat 50.05 / 50.14 /50.10 ms per step): the two conditions are in series, which is the point of the
2x2. With both, GPU busy drops 42.36 ms/step (-8.6%) against the same-day stock
control and 34.86 ms/step (-7.2%) against our production baseline; wall-clock
p8k p50 drops 491.1 -> 455.0 ms (-7.35%), two warm repeats 455.0 / 456.3
(0.3% spread). Cost: the bf16 weight triple is resident, so the KV pool shrinks
6,168,576 -> 6,018,048 tokens (-2.44%).
The first request after boot pays a one-off Triton compile (that run shows TTFT
avg 709.2 / p99 3220.4 ms while p50 is already 457.1); steady-state numbers
above are from warm runs.
Per-kernel census of the same two traces (60 steps each, TP-0) decomposes the
family delta of -38.74 ms/step:
partial50.05 -> 0.82,bf16x30 -> 13.11,_hc_mix_reduce_sinkhorn_kernel2.72 -> 0.84, post side(
mhc_post_combine_norm_prefill_kernel<128>+mhc_post_tilelang_kernel+_mhc_post_split_h_kernel) 28.99 -> 28.47. Sum -38.52; the remaining 0.22 sitsin the other small quant/norm kernels in that bucket. No
tf32kernel is hit ineither window, i.e. SM120 takes the pure-bf16 route and the DeepGEMM tf32 path is
never reached.
Per-call cross-check against a standalone micro-benchmark at M=8192, K=20480,
mix=24: partial 1.403 ms -> bf16x3 0.369 ms (3.80x). In the serving trace the
in-band calls go 1.25 ms -> 0.333 ms (3.8x), so the micro-benchmark ratio
reproduces in the engine.
For reference, the same checkpoint on 8x H20 (SM90) runs bf16x3 by default and
spends 10.8 ms/step in it; the SM120 mhc family was 94.76 ms/step before this
change and is 56.02 after, against H20's 66.23.
Numerics
Kernel level, M=4096, K=20480, mix=24, checkpoint values
rms_eps=1e-20,hc_eps=1e-6,sinkhorn_iters=20. Both wrappers share_hc_mix_reduce_sinkhorn_kernel, so any difference comes from the projectionkernel alone. Reference is a fp32 torch mirror of the reduce kernel's arithmetic.
The perturbation introduced by the swap is the same order as the deviation the
incumbent path already has from fp32. bf16x3 is not more accurate here, just
different at the 1e-05 relative level.
End to end: 226 generated arithmetic questions, each padded to 5570-5572 prompt
tokens so the prefill lands inside the projection band, padding unique per
question and the cache flushed before the run (
cached_tokens == 0for all 226,verified). Greedy, 12 output tokens, first-integer scoring. All three arms score
226/226, McNemar b01 = b10 = 0, exact p = 1.0. Per-question text identity and
logprob drift between the changed arm and the baseline (137/226 identical,
median |dlp| 3.44e-02) are at the level of a same-day A-A control that runs the
identical kernels from a different boot (144/226, median |dlp| 2.79e-02), so the
end-to-end instrument cannot resolve this change; accuracy saturates at 100% on
every arm. The kernel-level table above is the discriminating measurement, and we
are not claiming the end-to-end result as one.
What we did not measure
Stating these as gaps, not as assurances:
pins is dispatch, not speed: at 1 and 64 rows the compensated kernel is made to
raise and the split-K partial kernel is asserted to run, so "decode takes the
same path as before" is now tested. The claim that decode and higher concurrency
are unaffected performance-wise still rests on the row-band mechanism above
(
rows == 1never enters the compensated path), not on data from this branch.sm 120and
sm 121, but nothing has executed it on 121, so treat the guard as intentrather than coverage.
it runs.
deep_gemm.tf32_hc_prenorm_gemmdoes instantiate on SM120, and it isreachable from
DeepseekV4DecoderLayerBase.hc_prewhen the env is on and rowscarries an
is_set()guard, and the tf32 route is both less accurate here andunmeasured below 4096 rows) and draw no conclusion about upstream's original
reason. If there is a known SM120 blocker on the compensated path, this PR is
wrong and we want to hear it.
--enable-decoder-swa-bounded-replay(a different share of calls is in band).
lands in band, because the weight triple is built at load time: -2.44% KV
tokens. For a decode-only workload this PR is a pure capacity loss.
Related work
_HC_MIX_BLOCK_Kfor SM120 insidekernels/ops/layernorm/mhc.py(the reduce side). Different file, no conflict; our traces were collected
without that change, so the two numbers are not additive as measured.
unrelated to this gate.
Checklist
ruff format --checkclean on all three files (the wrappedand (...)form is what the formatter produces; the repo sets no
line-length, sothis is the 88-column default).
ruff check --select=F401,F821,F823,UP037clean.incumbent path's own level (table above). Now asserted rather than
promised: the new test compares
hc_mix_stats_sinkhorn_bf16x3against anfp64 mirror of the reduce arithmetic at the tolerances the existing Hopper
test already uses (
rtol=1e-5, atol=2e-6), and SM120 meets them.measurements above: 6 passed with the change; reverting the two arch
conjuncts and the routing in a shadow copy of the package turns exactly the
three gated cases red (
the SM120 opt-in built nothing,in-band rows did not reach the compensated projectionx2) and leaves the two out-of-bandcases plus the weight-split case green. That is a local run, not CI: this
PR has no
run-cilabel yet, so nothing here claims the suite has executed.CI States
Latest PR Test (Base): ✅ Run #42553077789
Latest PR Test (Extra): ❌ Run #42553077744
Latest PR Test (AMD ROCm 10): ✅ Run #42553077707
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: