Repository navigation
[Feature][SpecDecode][MRV2] Support prefill_context_kv_only for DFlash-family P/D prefill - #22892
Liuchenbing-2026 wants to merge 3 commits into
Conversation
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. 🤖 How to trigger CI
Note Until the CI gate has run on a commit, the required |
There was a problem hiding this comment.
Code Review
This pull request introduces support for prefill_context_kv_only across multiple Ascend models and speculative decoding components, including logic to gate operations and adjust metadata building. Comprehensive unit tests were added to validate these changes. A review comment highlighted a potential bug regarding boolean type checking in mamba_hybrid.py, which has been addressed with a suggested fix.
zhenwenqi2024
left a comment
There was a problem hiding this comment.
Could we replace test_sync_spec_pp_cpu_counts_assignment_is_self_contained with a behavioral test through the real initialization/profile path? Extracting and executing one AST assignment can still pass if the real PP path stops reaching it. A small parameterized case can verify that explicit zero and a positive live count propagate, absent values take the profiling fallback, and booleans are not treated as token counts.
|
@zhenwenqi2024 Thanks for the review! Updated in |
|
/run |
|
Last updated: 2026-12-04 00:48 UTC+8 for commit ci-gate failed. Reason:
See the workflow run for full logs. This comment is updated in place on each new failure and marked as passed once the gate passes (it is kept for history, not deleted). |
e588de2 to
259c50a
Compare
|
/run |
Coverage
More info see: Summary |
fc14b55 to
e84b8f2
Compare
|
@Liuchenbing-2026 I rebased the three PR commits onto The DSA conflict involved two different counts. A context-only prefill with zero scheduled drafts skips draft scratch allocation. A decoding worker still sizes the sliding-window buffer from the query layout on main. With a window of 124 and four draft tokens, the two layouts allocate widths of 128 and 256 respectively. Both passed the CPU regression checks, along with 136 PP cases and 48 source-isolated compatibility cases. GitHub now reports the branch can be merged without conflicts. |
|
/run |
|
@Liuchenbing-2026 I simplified the three context-KV helpers in 8d578bca9 and updated the PR description. The v0.34.0 release lacks these fields, so its flags default to false and the runner uses its configured draft count. On the main2main pin |
|
/run |
|
@Liuchenbing-2026 In d3c332b I removed the new helpers from |
|
/run |
|
@Liuchenbing-2026 In e8f5072 I removed the extra builder check in the target FlashMLA probe. Its existing layer-name filter already skips draft-only groups before accessing a builder. The KV initialization test now checks that path directly. |
|
/run |
|
@Liuchenbing-2026 In 04a7662 I moved builder filtering to the start of |
|
/run |
|
@Liuchenbing-2026 Both CPU lanes hit the same DCP assertion test. In 085175d I restored the config check for an empty cache layout while keeping the early return for builderless draft groups. Both failing parameters now pass locally on both pins. |
|
/run |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
…h-family P/D prefill
- Reuse upstream Qwen3-DFlash context KV projection via _normalize_context_states and patch context_kv_modules() (with full-weight fallback for unannotated subclasses) under vllm_version_is("0.34.0") gating; add context_kv_modules() and draft-only oproj buffer gating for DeepSeek-V4, DeepSeek-V4.1, and Kimi-K3 DSpark models.
- Adapt MRV2 DFlash, DSpark, and LiLiCorr speculators to bypass draft LM-head TP wrapping/validation, route context-KV-only LiLiCorr loading through the common Ascend DFlash loader before candidate embedding/LM-head checks, and relax eager guards when context_kv_only is enabled.
- Forward no_attn_metadata_layer_names through Ascend's initialize_kv_cache override on vLLM main via vllm_version_is("0.34.0") gating, filter builderless groups at build_attn_metadata entry while preserving DCP config validation on empty cache layouts, and guard DSA/RoPE scratch sizing, FlashMLA, kernel warmup, triton input preparation, length sync, device metadata, and MambaHybrid speculative state against builderless draft groups and num_scheduled_spec_tokens=0.
Signed-off-by: liuchenbing <chenliumail@163.com>
|
/run |
|
/rerun Rerun (failed jobs only):
|
… add warmup UT - Update prepare_dflash_inputs.md constraints and test cases to document the prefill_context_kv_only query overflow clamp contract and confirm 0 new JIT specialization variants. - Add a focused regression test in tests/ut/model_executor/warmup/test_kernel_warmup.py verifying that kernel_warmup skips DSpark draft warmup registration when prefill_context_kv_only=True or draft metadata_builders are empty. Signed-off-by: liuchenbing <chenliumail@163.com>
|
/run |
…ts.md Signed-off-by: liuchenbing <chenliumail@163.com>
|
/run |
What this PR does / why we need it?
In disaggregated P/D speculative decoding (DFlash / DSpark), Prefill workers only compute Context KV once and transfer it to Decode workers, while all draft-and-verify decoding runs strictly on Decode. Without
prefill_context_kv_only, Prefill still loads decode-only draft weights (o_proj, MLP, draft-decoding layers,embed_tokens,lm_head,markov_head, etc.), reservesOProjBufferPool, captures draft ACLGraphs, warms up SWA Triton kernels, and runs unused draft decode steps—wasting HBM and reducing Prefill KV cache capacity.This PR adds Ascend MRV2 support for
speculative_config.prefill_context_kv_only: Prefill still configures DFlash/DSpark and retains Context KV projection weights (context_kv_modules()) plus Context KV cache for P→D transfer, while freeing unused decode-only draft weights and skipping draft ACLGraph capture, JIT warmup, and draft propose execution.Key Changes
prefill_context_kv_onlyframework & Qwen3-DFlash:context_kv_modules()invllm_ascend/patch/worker/patch_qwen3_dflash.py(preservinghidden_norm, attention layers,fc,k_norm, and unfused_context_qkv_projswhile safely falling back to[self]for unannotated subclasses).getattr(group, "metadata_builders", True)) across attention, runner, mamba-hybrid, warmup, device-metadata, and flashmla paths; clamps all 12 outputs ofprepare_dflash_inputswhennum_reqs * Q > max_num_tokens; skips draft JIT warmup and draft ACLGraph/LM-head TP wrapping undercontext_kv_only.prepare_dflash_inputssignature.context_kv_modules()&OProjBufferPoolgating (DeepSeek-V4, DeepSeek-V4.1, Kimi-K3):vllm_ascend/models/deepseek_v4/dspark.py&vllm_ascend/models/deepseek_v41/dspark.py: implementcontext_kv_modules()on both*DSparkModeland*ForCausalLM, and skipreserve_oproj_bufferswhenprefill_context_kv_onlyis enabled.vllm_ascend/models/kimi_k3/kimi_k3_dspark.py: implementcontext_kv_modules()onAscendK3DSparkModel(covering bothPROLOG_V3writer and standard prefill paths) andAscendK3DSparkForCausalLM.glm5_dspark.py,minimax_m3_dspark.py) are deferred to a small follow-up PR; until then they safely retain full weights via[self]fallback while still benefiting from skipped draft capture/decode.tests/ut/spec_decode/test_prefill_context_kv_only.py: covers realDFlashSpeculator.free_unused_weights, realNPUModelRunner.__init__, emptymetadata_builders, Triton clamp, dual-baselinev0.34.0vsmain, DeepSeek-V4/V4.1context_kv_modules()+reserve_oproj_buffersgating, and Kimi-K3PROLOG_V3branches.release_notes/fragments/22892.yaml.Part of #22613
Does this PR introduce any user-facing change?
Yes. Users deploying Ascend MRV2 P/D disaggregation with DFlash/DSpark speculative decoding can set
"prefill_context_kv_only": trueinspeculative_config(defaultfalse; requires--kv-transfer-configwithkv_producerorkv_both) to keep only Context KV projections and KV cache on Prefill while freeing decode-only draft weights on Qwen3-DFlash, DeepSeek-V4, DeepSeek-V4.1, and Kimi-K3. Release note added inrelease_notes/fragments/22892.yaml.How was this patch tested?
e61c82632577, linearly rebased ontomain7ce009c0befd,21 files, +692/-48):ruff 0.14.0(check+format --check), 5 repo static hooks (check_python_src_init,check_logger,check_forbidden_imports,check_boolean_context_manager,check_long_functions),mypy 1.11.1(Py3.10/3.11/3.12:0issues across 56 prod + 3 test files), and DCO all PASS.pytest(tests/ut/spec_decode/,tests/ut/worker/v2/,test_spec_pp_cpu_counts.py,test_kimi_k3_pp_sp.py):vllm@v0.34.0(VLLM_VERSION=0.34.0): targetedtest_prefill_context_kv_only.py23 passed; full suite 1283 passed, 5 skipped, 0 failed.vllm@c410543d9ffff03f5f6c4a8c0ae1d3ad082c4a15(VLLM_VERSION=0.34.0.dev0): targetedtest_prefill_context_kv_only.py23 passed; full suite 1288 passed, 0 skipped, 0 failed.Qwen3-4B+Qwen3-4B-DFlash-b16, MRV2,TP1,--enforce-eager,MooncakeConnectorV1, 601 in / 128 out, C1/C2/C4/C8):8.57 -> 7.63 GiB(-0.94 GiBfreed); KV cache34.05 -> 34.99 GiB.128/128HTTP 200, 100% SHA256-identical outputs; decode acceptance86.11%(avg2.583); 3 mid-stream abort loops recovered cleanly.DeepSeek-V4.1DSpark):-0.60 GiB/die, expanding Prefill KV cache by+25,484 tokens (+7.62%).DeepSeek-V4.1-Flash W4A8+DSpark K=5,FULL_DECODE_ONLY, 512 out):C1:37.01 -> 104.40 tok/s(2.82x);C2:70.09 -> 175.49(2.50x);C4:136.47 -> 300.70(2.20x);C8:266.65 -> 493.42(1.85x),100%HTTP 200, acceptance52.75%–53.87%.7ce009c0befd(runtime-equivalent onvllm@c410543d9f; not re-run on NPU after this rebase). Upstream CI E2E is triggered via/run(awaitsready-precise).v0.34.0and vLLM mainc410543d9ffff03f5f6c4a8c0ae1d3ad082c4a15.Checklist
Testing
oprojbuffer gating), and Kimi-K3 (PROLOG_V3True/False)context_kv_modules(), unannotated subclass[self]fallbacks,num_reqs * Q > max_num_tokensmasking, emptymetadata_builders, andbool/non-intnum_scheduled_spec_tokens.tests/ut/spec_decode/test_prefill_context_kv_only.py(23 cases) plus prior Atlas A3 1P1D and 16-die/TP8 regression verification.AttributeError, and client-abort recovery without restart.vllm@v0.34.0andvllm@c410543d9f.-0.94 GiBprefill HBM savings onQwen3-4B-DFlashand-0.60 GiB/die(+7.62%KV tokens) on 16-dieDeepSeek-V4.1.Co-authored-by: zhenwenqi2024 zhenwenqi_2022@qq.com