Repository navigation
[Spec] Support quantized target lm_head in the DFlash2 selector - #35496
Merged
kpham-sgl merged 1 commit intoAug 20, 2026
Merged
Conversation
Jiminator
requested review from
Qiaolin-Yu,
Ying1123,
hnyls2002 and
merrymercy
as code owners
August 19, 2026 08:59
Jiminator
force-pushed
the
feat/dflash2-quantized-lm-head
branch
4 times, most recently
from
August 19, 2026 11:14
000d975 to
6f06c58
Compare
Jiminator
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
ch-wan and
ispobock
as code owners
August 19, 2026 11:14
Jiminator
force-pushed
the
feat/dflash2-quantized-lm-head
branch
from
August 19, 2026 11:19
6f06c58 to
28198c8
Compare
Jiminator
force-pushed
the
feat/dflash2-quantized-lm-head
branch
from
August 19, 2026 22:32
28198c8 to
c55f68f
Compare
Jiminator
force-pushed
the
feat/dflash2-quantized-lm-head
branch
from
August 19, 2026 22:59
c55f68f to
4df0df1
Compare
DFlash2's candidate selector borrows the target lm_head and matmuls draft hiddens against .weight directly, so a quantized target (ModelOpt NVFP4 packed, compressed-tensors FP8 per-channel) fails the dense-head screen and DFLASH refuses to serve such checkpoints. Route an applicable quantized head through quant_method.apply — the same gate (should_apply_lm_head_quant_method) and kernel the target's own logits path uses. A packed weight cannot be row-sliced to the org vocab like the dense path, so the padded tail is masked to -inf out of the top-k instead: a crop view would either break the contiguity flashinfer's radix top-k CHECK_INPUTs or copy the whole valid vocab to restore it. Both TP paths project through one helper; their control flow is unchanged. The worker's pre-capture screen admits a gate-passing quantized head into the graph-folded selector sampler rather than leaving it on the eager per-round fallback, so quantized and dense heads take the same code path; the kernel it captures is the one the target's own logits path already runs under CUDA graphs. The dense-only screen still guards the non-selector static-matmul sampler. Folded and eager measure equal on the same cell (accept lengths bit-identical), so this is path consistency, not the speedup itself. Co-authored-by: LING ZHI <[email protected]>
Jiminator
force-pushed
the
feat/dflash2-quantized-lm-head
branch
from
August 19, 2026 23:31
4df0df1 to
1bb0253
Compare
Collaborator
|
/rerun-test test_dflash_logits.py test_dflash.py test_basic_sanity_dflash.py test_gemma4_dflash_31b_extra.py |
Contributor
|
Results for 🚀 🚀 🚀 |
Collaborator
|
/rerun-test test_dflash_overlap_hostsync.py |
Contributor
|
Results for 🚀 |
This was referenced Aug 20, 2026
3 tasks done
Closed
8 tasks
Ligator
added a commit
to WaxacaBytes/spark-ai-hub
that referenced
this pull request
Aug 26, 2026
SGLang published RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead on 2026-08-24: the same NVFP4 body with the output projection left dense. Their finding is that FP8 KV cache plus a 4-bit lm_head is where NVFP4 loses the most accuracy, since every logit is computed from 4-bit weights on top of an already-lossy KV read, and a dense head recovers it. Swapped in as the NVFP4 DFlash2 build rather than added alongside. The new recipe is otherwise identical to the one it replaces -- same engine build, same drafter, same flags, same mem-fraction -- so the only variable is the checkpoint. It is also DFlash2's native target shape, since the quantized-head path only landed in sgl-project/sglang#35496. Measured back-to-back on one box with tools/benchmark_editing_column.py: writing editing weights BF16 head 27.8 60.3 23.8 GB packed head 30.3 68.3 21.9 GB So the accuracy option costs 8-12% of throughput and 1.9 GB, which is about what bandwidth predicts for a head that grows from ~0.5 GB to ~1.9 GB and is read on every decode step. Recorded in the recipe description so the tradeoff is visible before install. Re-measuring the outgoing recipe put it at 30.3 vs its published 30.0, so the gap is real rather than drift. Also add bf16head to models.js BUILD_TOKENS. The model-grouping key strips trailing build tokens off the slug, and an unknown token halts the strip, so the recipe grouped under qwen38-27b-nvfp4-bf16head and sat outside the Qwen3.8-27B table as a lone row. Per-tensor precision describes how a checkpoint was built, not which model it is, so it belongs with the quant and drafter tokens already there. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E3KJUKJpW1zjUSzKK7A5R2
chinazhangchao
pushed a commit
to chinazhangchao/sglang-windows
that referenced
this pull request
Sep 15, 2026
…project#35496) Co-authored-by: LING ZHI <[email protected]>
3 of 5 tasks
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
DFlash2's selector matmuls draft hiddens against the target
lm_head.weightdirectly, so quantized targets (ModelOpt NVFP4, compressed-tensors FP8) fail withRuntimeError: DFlash2 selector requires a dense FP16/BF16/FP32 target lm_head— on 32GB GPUs those checkpoints are the only way to serve Qwen3.8-27B. #34859 fixed the same problem for DSpark viaquant_method.apply; this does the same for the DFlash2 selector.Overlaps #35462 (@ryou315, credited as co-author): this PR additionally keeps the quantized logits contiguous by masking the padded tail instead of cropping — a padded local vocab crop otherwise fails flashinfer's radix top-k
CHECK_INPUTat TP=1 and can hang TP>1, since only the rank holding the tail errors while its peers enter the all-gather.Follow-ups split out of this PR so each stays reviewable on its own: #35580 (degenerate-config guard), #35581 (optional cleanup).
Modifications
models/dflash.py:_project_candidate_logitsprojects draft hiddens through the target head, restricted to the org vocab. Whenshould_apply_lm_head_quant_methodadmits the head it runsquant_method.applyover the padded local vocab and masks the padded tail to-inf(a packed weight cannot be row-sliced like the dense path; masking keeps the logits contiguous with no copy, and does nothing when the vocab is unpadded). Both TP branches call it; their control flow is unchanged.speculative/dflash_worker_v2.py_maybe_build_draft_sampler: the selector branch accepts a dense head or one the quant gate admits, so quantized and dense heads take the same graph-folded_SelectorDraftSamplerpath (the captured kernel is the one the target's own logits path already runs under CUDA graphs). The dense-only screen still guards the non-selector static-matmul sampler.Accuracy Tests
RTX 5090, target
RadixArk/Qwen3.8-27B-NVFP4(NVFP4-packed head), draftincoai/Qwen3.8-27B-DFlash2, greedy: both arms are byte-deterministic across fresh server boots (8/8 prompts each); spec vs target-only outputs fork only at near-tie tokens and 22/28 completed chains reach the same final answer — a stable numerics offset, not corruption.sgl-eval run gsm8k200q: 95.5% with spec vs 98.0% target-only.test_dflash_logits.py: 7/7 pass. The quant-path test assertsapply()runs on the packed weight, dominant padded garbage never reaches the candidates, and the logits handed to top-k are contiguous withsorted/deterministicset — the fake quant method returns a deliberately strided view and the top-k stub mirrors flashinfer's call contract, so an unmaterialized output fails the way the real kernel would. The TP test pins the per-shard org-vocab restriction, the global id offset, and the fp32 cast before the all-gather. A worker test pins the pre-capture screen: a gate-passing packed head is admitted to the folded selector sampler and attached before construction, an unsupported one stays eager. All mutation-verified: dropping the mask, the.contiguous(), the top-k flags, the id offset, the fp32 cast, or the worker admission each turns a test red. The dense-rejection test is kept for the negative branch.Speed Tests and Profiling
No effect on dense-head targets (same matmul, same screen outcome). Quantized targets go from refusing to serve to serving. Same cell (RTX 5090, fp8 KV, concurrency 1):
sglang.benchmark.servingrandom 8192/1024: TTFT 746.9 ms, median TPOT 7.10 ms, 129.5 output tok/s, accept 3.01 (DSPARK on the same cell: 7.73 ms, 116.5 tok/s, accept 2.59).Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ❌ Run #32313633532
Latest PR Test (Extra): ❌ Run #32313633314