Repository navigation
[Fix] speculative: FR-Spec (--speculative-token-map) with a quantized (FP8) target lm_head - #44277
AppNetDeveloper wants to merge 1 commit into
Conversation
…lm_head With an FP8 (compressed-tensors W8A8, per-channel) target lm_head, SGLang keeps the weight transposed ([K, V]), so `head.data[hot_token_id]` sliced K instead of the vocab (OOM at startup: 9.47 GiB for 40,960 ids on Qwen3.8-27B) and left the per-row scale full size. Add `prune_quantized_lm_head`, which builds a pruned copy of the target head slicing weight and per-row scale along the vocab axis (same dtype/layout), returns None for unquantized heads (existing path unchanged) and refuses layouts it cannot slice per row (block scales, sharded vocab) with a clear error. CPU unit tests included.
|
Rebased onto current What it fixes. What changes.
This does not overlap with #42424, #43249 and #43347, which handle a vocab-sharded head at TP>1. Here a quantized head whose weight holds only part of the vocab is refused with an explicit error (checked on CPU with a half-vocab shard). Whichever lands first, the other needs only a small rebase of How it was tested
Why it fits 1.0 (#50045). It fixes a startup crash in an existing speculative-decoding flag. Where it cannot handle a layout, it raises an explicit error instead of producing wrong logits. Nothing changes for unquantized heads. That matches the tracker's principles for core features until the branch cut: bug fixes, tests, and explicit errors for unsupported configurations. CI. The red checks on the previous head were all |
0611e5f to
0e5c814
Compare
Motivation
--speculative-token-map(FR-Spec) fails at startup when the target lm_head is quantized. With a compressed-tensors W8A8 FP8 (per-channel) lm_head, SGLang keeps the weight transposed ([K, V]), sohead.data = head.data[self.hot_token_id]inEagleDraftWorker.init_lm_headslices the K axis instead of the vocab: on Qwen3.8-27B (vocab 248,320, hidden 5,120) a 40,960-id map asks for a[40960, 248320]tensor and OOMs (9.47 GiB). The per-rowweight_scalewould also stay full size.Modifications
spec_utils.prune_quantized_lm_head(lm_head, hot_token_id): for a quantized lm_head, returns a shallow copy whoseweight/weight_scale/weight_scale_inv/biaskeep only the hot vocab rows, in the original dtype and layout (handles[V, ...]and the transposed[K, V]view). Per-tensor scales are shared. ReturnsNonefor unquantized heads, so the existing path is unchanged. Raises a clear error for layouts it cannot slice per row (block-wise scales, sharded/packed vocab) or for ids outside the vocab, instead of producing garbage. The target lm_head is never modified.EagleDraftWorker.init_lm_head: when the pruned head is available, hand it to the draft viaset_lm_head_from_target(with a clear error if the draft model can't take a target head).test/registered/unit/speculative/test_frspec_quantized_lm_head.py: CPU tests (shape/stride/dtype, logits equal to the hot rows of the full head, target untouched, unquantized → old path, block scales and out-of-range ids refused).Accuracy Tests
Real Qwen3.8-27B FP8 lm_head (248,320 × 5,120,
ThinkingCap-Qwen3.8-27B-NVFP4A4-AWQ, compressed-tensors): pruned logits == the corresponding rows of the full head (max |diff| = 0, top-1/top-4 identical) at M = 1/4/8/16. End to end with MTP (EAGLE 3/1/4) and a 40,000-id map: reasoning 48/48 (3 runs × 16, same as baseline), tool calls 24/24, needle 4/4; accept length ~3.0 vs ~3.1.Speed Tests and Profiling
RTX PRO 6000 (SM120), SGLang 0.5.21 (same code as this branch for these two files): draft lm_head 0.97–1.17 ms → 0.17–0.20 ms per call (3 calls per step). Single stream: +3.6 % at 45k context, +11.5 % at 141k; 4 concurrent: +8 %. Combined with other SM120 kernel changes (published separately, not part of this PR: https://github.com/AppNetDeveloper/sglang-sm120-fast-decode) it reached +22–38 % tokens/s on production traffic.
Checklist
base-a-test-cpu).--speculative-token-mapnow works with quantized heads).CI States
Latest PR Test (Base): ❌ Run #43592472292
Latest PR Test (Extra): ❌ Run #43592471960
Latest PR Test (AMD ROCm 10): ❌ Run #43592472193
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: