Repository navigation
Conversation
ormandj
requested review from
BBuf,
DarkSharpness,
Fridge003,
HaiShaw,
HydraQYH,
Ying1123,
celve,
hnyls2002,
ispobock,
merrymercy and
yuan-luo
as code owners
October 7, 2026 18:21
17 of 56 tasks
ormandj
force-pushed
the
dsv41-wo-a-fp8-weight
branch
from
October 19, 2026 17:33
58adb15 to
5c62f33
Compare
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 20, 2026
…indexer) + stack_want decisions - stack.txt: entries 1-2 (local) + Group A boot-critical indexer chain sgl-project#42371/sgl-project#42861/sgl-project#45261/sgl-project#42294/sgl-project#43008 (fe7be85..0dbd8c5). - stack_want.txt: consolidated decision set from 8 parallel evaluators + dsv41(422)/SM120(254) sweeps + sybil/qwen harvests. Records E verdict (merge only sgl-project#43376) and D verdict (merge only sgl-project#42368; sgl-project#33407/sgl-project#34717 dead on flashinfer 0.7.2).
…weight DeepSeek-V4.1 stores WO-A as E4M3 with power-of-two 32x32 block scales and dequantizes it to BF16 at load. On SM120, single-row decode and target verify up to 64 rows now read an E4M3 copy built after loading, which reproduces the BF16 operand exactly and halves the bytes this bandwidth-bound projection streams. Weights without an exact copy keep the BF16 kernels. Online weight updates keep working: WeightUpdater calls an optional invalidate_derived_weights() module hook before writing, which switches the kernel to the BF16 weight through a device flag (so captured CUDA graphs follow), and refresh_derived_weights() after post_load_weights and at the end of an update session rewrites the copy in place, re-enabling it only when the new weight has an exact copy. Also write the fused MXFP8 epilogue's scales in FlashInfer's 128x4 layout for any row count up to 128; the previous offset was correct for rows 0-31 only.
ormandj
force-pushed
the
dsv41-wo-a-fp8-weight
branch
from
October 29, 2026 21:44
5c62f33 to
465a8cc
Compare
Contributor
|
Thanks @ormandj. Closing this because you have 25 PRs open and none updated in 7 days, over our soft cap of 5 for idle PRs. Reopen the two or three you most want reviewed - a short active set moves faster than a long idle one. Some directories moved recently, so an older branch may need retargeting: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
DeepSeek-V4.1 checkpoints store WO-A as E4M3 with power-of-two 32x32 block scales, and the loader dequantizes it to BF16. On SM120, where the fused SM100 WO-A path does not apply, decode and target verify read the 16 MiB BF16 weight (TP4 shape
[2, 1024, 4096]) in every layer, and this projection is bound by weight bandwidth. The E4M3 values and their scales reproduce the BF16 weight exactly from 8 MiB.Modifications
quantize_wo_a_fp8builds the E4M3 copy and returnsNoneunless it reproduces the BF16 weight bit for bit.wo_a_fp8_small_batch/wo_a_fp8_small_batch_mxfp8(1-64 rows) use the existing split-K kernel, which now builds the BF16 operand from the E4M3 copy in registers._apply_wo_a_bf16_matmuluses the copy for single-row decode and for target verify up to 64 rows. Only DeepSeek-V4.1 on SM120 (compute capability 12.0) uses it; other GPUs, other models, and larger batches keep their current paths. Whenwo_bruns FlashInfer MXFP8, target verify of 9-64 rows now returns the MXFP8-quantized activation from the kernel's fused epilogue instead of BF16 thatwo_bthen quantizes. The copy costs 8 MiB per layer per rank and is built after loading.SGLANG_DSV41_WO_A_FP8_COPY=0disables it.WeightUpdatercalls a new optional module hook,invalidate_derived_weights(), before every online update writes. That covers disk, distributed, tensor (includingload_format="direct") and IPC updates, and the start of an update session. WO-A uses the hook to clear its flag. Modules that define both hooks are collected once per model.WeightCheckerleaves the derivedwo_a_fp8_*buffers out of its reset, comparison and checksum.refresh_derived_weights()rewrites the copy in place. It runs frompost_load_weights. At the end of an update session it runs once more: throughpost_load_weightswhen the session loaded nothing, or called directly byWeightUpdaterwhen the session recorded a successful load (whose ownpost_load_weightsalready ran, or was skipped forload_format="direct"), so writes after the last load (for example P2P) are picked up. The flag is set again only if the new weight has an exact copy; if the refresh runs out of memory, the layer stays on the BF16 weight.post_load_weightscall of an online update._wo_a_reduce_quant) wrote scales correctly only for rows 0-31 of FlashInfer's 128x4 layout. It now matchesmxfp8_quantizeup to 128 rows. Current callers use at most 8 rows; this PR routes up to 64.This PR is independent of other open PRs and applies to current main on its own.
Accuracy Tests
GPU tests in
test_dsv4_wo_a_fp8.py(new, 19 cases) andtest_dsv4_wo_a.py(3 cases) pass on an RTX PRO 6000 Blackwell (SM120) on this revision. The CPU tests intest_derived_weight_cache.pypass.test_deepseek_v4_unified_fp8_q_pair.py(from main) gives its stub layer the newwo_a_fp8_weightattribute. The new CPU testtest_deepseek_v4_wo_a_fp8_dispatch.pychecks with stubbed kernels that decode and target verify up to 64 rows take the copy (fused MXFP8 when requested) and that the BF16 kernels serve calls without the copy or above 64 rows.wo_a_bf16_small_batch; 0.02-0.04% of them differ.torch.bmmon the BF16 weight (ratio 1.000)._quantize_partialoutput is bitwise equal tomxfp8_quantizeat 1-8, 31-33, 63-65, 127 and 128 rows, and under graph replay at 6 and 40 rows. Before the fix, scales mismatch above 32 rows. The MXFP8 output of the new kernel matchesmxfp8_quantizeunder graph replay at 1, 8, 33 and 64 rows.wo_a_bf16_small_batchon the new weight at 2 and 8 rows, and at 33 rows its error against FP64 stays within one BF16 ulp of the largest output.invalidate_derived_weights()before a direct update writes, and the update succeeds. An update session calls the invalidate hook at its start. At its end,WeightUpdatercalls the refresh hook itself only when the session recorded a successful load; otherwise it leaves the refresh to thepost_load_weightsit runs. These CPU tests check the updater's own hook calls. The refresh fromDeepseekV4ForCausalLM.post_load_weightsis exercised at startup in the serving runs below, where it builds the copy; no unit test runs an online update through the full model.Serving output quality, same build with the copy on and off (setup below): both arms pass the same gates, which are teacher-forced log-probability agreement with a reference (worst per-prompt mean difference 0.075 nats with the copy on, 0.048 and 0.094 nats in the two runs with it off; limit 0.15) and no repetition loops in 32 streams at 4 and 16 concurrent requests (temperature 1).
Speed Tests and Profiling
Per call on one RTX PRO 6000 Blackwell (SM120), TP4 shape, CUDA graph over 16 distinct layers so the weights are not L2-resident (
us):Single-row decode on main uses
wo_a_bf16_gemv, which this table does not include; the serving A/B below at one request is the end-to-end comparison for that path. Break-even withtorch.bmmis near 96 rows, so the copy is capped at 64. The table was measured before the update flag was added. In a micro-benchmark with an L2-resident weight (20 calls per graph), the flag check adds about 4% at 1-16 rows. With the flag cleared, the kernel runs 3-11% slower thanwo_a_bf16_small_batchat 2-8 rows (6.1-6.3 vs 5.5-5.9 us); only SM120 servers whose updated weight has no exact copy, or whose refresh ran out of memory, run that path.Serving A/B with this change, same image, copy on vs
SGLANG_DSV41_WO_A_FP8_COPY=0: DeepSeek-V4.1-Flash on 4x RTX PRO 6000 Blackwell (SM120, PCIe only, 250 W power limit), TP4/EP2, DSpark speculative decoding, temperature 1, decode from an empty context, up to 16 running requests. The build also carries other pending changes, identical in both arms. Each arm ran 3 warmed 30 s decode cells per concurrency; the copy-on arm is one run, the copy-off arm is two runs (6 repetitions), with matched GPU temperatures and clocks. Steps/s comes from the server's decode log lines at each batch size: generation throughput divided by accepted tokens per step, which is request verify steps per second summed over the batch (the target forward-pass rate times the batch size). At a fixed batch size its relative change equals the change in forward-pass rate, and it does not depend on DSpark acceptance length. Output tok/s is measured by the client."Separated" means every copy-on repetition is above every copy-off repetition. The 16-request differences are within run-to-run variation. Prefill throughput at 8k, 32k and 128k tokens is unchanged (-0.2% to 0.0%).
Limitations: the copy-on run came first and was not repeated after the copy-off runs, so slow drift between runs is not excluded. The copy uses memory: in this configuration the KV pool shrank from 2,284,032 to 2,078,208 tokens with the copy on.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciDeveloped with AI assistance.
CI States
Latest PR Test (Base): ❌ Run #40960255867
Latest PR Test (Extra): ❌ Run #40960255931
Latest PR Test (AMD ROCm 10): ❌ Run #40960255953