feat(yoco): add --kv-sharing-fast-prefill server arg + validators (PR-A/3) - #11
Draft
pyc96 wants to merge 1 commit into
Draft
feat(yoco): add --kv-sharing-fast-prefill server arg + validators (PR-A/3)#11pyc96 wants to merge 1 commit into
pyc96 wants to merge 1 commit into
Conversation
…-A/3)
Introduce an opt-in server flag for the YOCO-style fast-prefill optimization
that vLLM ships for Gemma-4 (Gemma4SelfDecoderLayers / Gemma4CrossDecoderLayers
in vllm/model_executor/models/gemma4.py). When enabled, the last
num_kv_shared_layers decoder layers will eventually run only on the
per-request last-extend-token rows during EXTEND-mode forwards (model-side
implementation lands in the follow-up PR).
This first PR in a stack of three contains only the flag plumbing and the
cross-cutting validators that don't depend on the live model.
Changes:
* ServerArgs.kv_sharing_fast_prefill: bool dataclass field (default False)
* argparse --kv-sharing-fast-prefill (store_true)
* ModelConfig.__init__ accepts kv_sharing_fast_prefill keyword
* ModelConfig.from_server_args propagates the flag
* Gemma-4 branch of _handle_model_specific_adjustments validates:
- triton backend (prefill + decode) when the flag is on
- num_kv_shared_layers > 0 on the served model's text config
- logs 'KV-sharing fast prefill enabled for <arch>' on success
* ServerArgs._validate_kv_sharing_fast_prefill_combos (new helper)
rejects --speculative-algorithm EAGLE / EAGLE3 with the flag on.
Called from check_server_args(); factored out so it's unit-testable
without a live HF config.
* test/registered/unit/server_args/test_kv_sharing_fast_prefill.py:
8 unit tests covering the dataclass default, CLI parsing, argparse
registration, ModelConfig plumbing, and all four validator branches
(EAGLE rejected, EAGLE3 rejected, NEXTN accepted, flag-off skipped).
Default-off, opt-in only; no behavior change for existing deployments.
The diff in server_args.py contains some auto-format noise (assert (cond),
'msg' -> assert cond, ('msg')) from a ruff format rule that triggers on
save. The real changes are the four blocks cited above.
Stack base: pyc/sota-gemma4-31b-mm-disabled @ 3a3195b
Next: PR-B (model-side YOCO branch in Gemma4TextModel.forward) and
PR-C (benchmark + tuning).
Plan: .humanize/yoco-gemma4/refined-plan.md
Co-authored-by: Claude
This was referenced May 24, 2026
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.
Summary
Stack of 3 PRs that port vLLM's YOCO fast-prefill optimization for Gemma-4 to SGLang. This is PR-A/3: flag plumbing + validators only, no model behavior change.
Background
vLLM's Gemma-4 implementation (
vllm/model_executor/models/gemma4.py:759-952, 1190-1273) splits the decoder into two halves: the firstK = N - num_kv_shared_layerslayers run on the full extend-token batch (the "self-decoder"), and the lastnum_kv_shared_layerslayers (the "cross-decoder") run only on the per-request last-extend-token rows. Because those last layers reuse K/V from earlier layers and never write KV themselves, their compute is only needed at the positions that feed the LM head.For Gemma-4 31B-IT on H100+TP=2+triton+MTP, the current SGLang summ 8000/1000 throughput is 331 tok/s vs vLLM 868 tok/s (gap -62%). The vLLM-vs-SGLang audit at `agent-pod/runs/20260523_gemma4_31b_it_h100_sota_humanize/yoco/{draft,plan}.md` shows YOCO is the structural source of vLLM's prefill advantage; this stack ports it to SGLang.
What's in PR-A
Flag plumbing + cross-cutting validators. No model behavior change — the YOCO branch lands in PR-B and the benchmarks in PR-C.
Behavior
Tests
```
python test/registered/unit/server_args/test_kv_sharing_fast_prefill.py
...
Ran 8 tests in 0.860s
OK
```
Benchmark / MMLU
No runtime change — these will appear in PR-C. For reference, the current SGLang best on the campaign workload (`google/gemma-4-31B-it`, H100+TP=2+triton+MTP, 80 prompts, warmup 2, seed 1) on the parent branch `pyc/sota-gemma4-31b-mm-disabled` is:
This stack targets the summ tok/s and TTFT gap. PR-C will report new numbers.
Diff noise note
`python/sglang/srt/server_args.py` shows 401 lines changed (255 inserts / 146 deletes) but only ~50 of those are my real changes. The rest is an auto-format reflow (`assert (cond), "msg"` → `assert cond, ("msg")`) triggered by a recent ruff format rule on every edit-and-save in this repo. The real changes are the four blocks at lines ~684 (field), ~6213 (argparse), ~2240 (Gemma-4 branch validators), and ~7109 (helper + call). Easy to audit by greping for `kv_sharing`.
Stack
Stack base: `pyc/sota-gemma4-31b-mm-disabled` @ `3a3195b30`
Plan: `.humanize/yoco-gemma4/refined-plan.md` (also at `runs/20260523_gemma4_31b_it_h100_sota_humanize/yoco/plan.md`)
CI States
Latest PR Test (Base): ❌ Missing
run-cilabel -- add it to run CI tests.Latest PR Test (Extra): ❌ Blocked --
run-ciis required first.