Skip to content

[Feature][SpecDecode][MRV2] Support prefill_context_kv_only for DFlash-family P/D prefill - #22892

Open
Liuchenbing-2026 wants to merge 3 commits into
vllm-project:mainfrom
Liuchenbing-2026:feat/prefill-context-kv-only-mrv2
Open

Liuchenbing-2026 wants to merge 3 commits into
vllm-project:mainfrom
Liuchenbing-2026:feat/prefill-context-kv-only-mrv2

Conversation

@Liuchenbing-2026

@Liuchenbing-2026 Liuchenbing-2026 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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.), reserves OProjBufferPool, 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

  • MRV2 prefill_context_kv_only framework & Qwen3-DFlash:
    • Hooks context_kv_modules() in vllm_ascend/patch/worker/patch_qwen3_dflash.py (preserving hidden_norm, attention layers, fc, k_norm, and unfused _context_qkv_projs while safely falling back to [self] for unannotated subclasses).
    • Guards builderless draft attention groups (getattr(group, "metadata_builders", True)) across attention, runner, mamba-hybrid, warmup, device-metadata, and flashmla paths; clamps all 12 outputs of prepare_dflash_inputs when num_reqs * Q > max_num_tokens; skips draft JIT warmup and draft ACLGraph/LM-head TP wrapping under context_kv_only.
    • The runner and draft models read the upstream context-KV flags directly. On v0.34.0, missing flags default to false and workers use the configured draft count. An explicit scheduled count of zero is preserved. The DFlash input adapter follows the upstream prepare_dflash_inputs signature.
  • DSpark per-model context_kv_modules() & OProjBufferPool gating (DeepSeek-V4, DeepSeek-V4.1, Kimi-K3):
    • vllm_ascend/models/deepseek_v4/dspark.py & vllm_ascend/models/deepseek_v41/dspark.py: implement context_kv_modules() on both *DSparkModel and *ForCausalLM, and skip reserve_oproj_buffers when prefill_context_kv_only is enabled.
    • vllm_ascend/models/kimi_k3/kimi_k3_dspark.py: implement context_kv_modules() on AscendK3DSparkModel (covering both PROLOG_V3 writer and standard prefill paths) and AscendK3DSparkForCausalLM.
    • Remaining 2 DSpark models (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.
  • Behavioral unit tests & release note:
    • tests/ut/spec_decode/test_prefill_context_kv_only.py: covers real DFlashSpeculator.free_unused_weights, real NPUModelRunner.__init__, empty metadata_builders, Triton clamp, dual-baseline v0.34.0 vs main, DeepSeek-V4/V4.1 context_kv_modules() + reserve_oproj_buffers gating, and Kimi-K3 PROLOG_V3 branches.
    • Added user-facing release note in 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": true in speculative_config (default false; requires --kv-transfer-config with kv_producer or kv_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 in release_notes/fragments/22892.yaml.

How was this patch tested?

  • Static & dual-baseline CPU checks on the earlier revision (e61c82632577, linearly rebased onto main 7ce009c0befd, 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 (Py 3.10/3.11/3.12: 0 issues across 56 prod + 3 test files), and DCO all PASS.
    • Dual-baseline CPU 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): targeted test_prefill_context_kv_only.py 23 passed; full suite 1283 passed, 5 skipped, 0 failed.
      • vllm@c410543d9ffff03f5f6c4a8c0ae1d3ad082c4a15 (VLLM_VERSION=0.34.0.dev0): targeted test_prefill_context_kv_only.py 23 passed; full suite 1288 passed, 0 skipped, 0 failed.
  • Atlas A3 1P1D NPU baseline (Qwen3-4B + Qwen3-4B-DFlash-b16, MRV2, TP1, --enforce-eager, MooncakeConnectorV1, 601 in / 128 out, C1/C2/C4/C8):
    • Prefill weights 8.57 -> 7.63 GiB (-0.94 GiB freed); KV cache 34.05 -> 34.99 GiB.
    • 128/128 HTTP 200, 100% SHA256-identical outputs; decode acceptance 86.11% (avg 2.583); 3 mid-stream abort loops recovered cleanly.
  • Atlas A3 16-die NPU A/B (DeepSeek-V4.1 DSpark):
    • Prefill weights reduced by -0.60 GiB/die, expanding Prefill KV cache by +25,484 tokens (+7.62%).
  • Atlas A3 TP8 NPU regression A/B (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, acceptance 52.75%–53.87%.
  • Untested boundaries & dependencies:
    • Atlas A3 NPU measurements were captured prior to the final rebase onto 7ce009c0befd (runtime-equivalent on vllm@c410543d9f; not re-run on NPU after this rebase). Upstream CI E2E is triggered via /run (awaits ready-precise).
    • Paired baselines: pinned release tag v0.34.0 and vLLM main c410543d9ffff03f5f6c4a8c0ae1d3ad082c4a15.

Checklist

Testing

  • Boundary / edge-case coverage: Covered Qwen3-DFlash, DeepSeek-V4, DeepSeek-V4.1 (oproj buffer gating), and Kimi-K3 (PROLOG_V3 True/False) context_kv_modules(), unannotated subclass [self] fallbacks, num_reqs * Q > max_num_tokens masking, empty metadata_builders, and bool/non-int num_scheduled_spec_tokens.
  • Regression test: Added behavioral init/profile/model UTs in tests/ut/spec_decode/test_prefill_context_kv_only.py (23 cases) plus prior Atlas A3 1P1D and 16-die/TP8 regression verification.
  • Error / failure path coverage: Verified invalid config rejection, unannotated subclass fallback without AttributeError, and client-abort recovery without restart.
  • Meaningful & reliable tests: Exercised real init/profile/pruning paths across vllm@v0.34.0 and vllm@c410543d9f.
  • Performance impact: Measured -0.94 GiB prefill HBM savings on Qwen3-4B-DFlash and -0.60 GiB/die (+7.62% KV tokens) on 16-die DeepSeek-V4.1.

Co-authored-by: zhenwenqi2024 zhenwenqi_2022@qq.com

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

🤖 How to trigger CI

CI runs automatically when the PR is opened or reopened. Pushing a new commit no longer re-runs the E2E CI (to save NPU runner resources), so use the comment commands below when needed. They are available to the PR author and users with triage permission or above:

  • /run — run the full PR CI gate on the latest commit.
  • /rerun — re-run the failed CI jobs (e.g. after a flaky failure).
  • /e2e — run selected E2E tests instead of the full gate.
  • /nightly / /presmoke / /weekly — run the corresponding large-scale tests (triage permission or above; blocked during the nightly maintenance window).
  • /cancel — cancel a running CI on this PR.

Note

Until the CI gate has run on a commit, the required ci-gate check stays pending and the PR cannot merge — remember to comment /run after pushing.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Liuchenbing-2026 Liuchenbing-2026 changed the title [Spec Decode][MRV2] Support prefill_context_kv_only for DFlash-family P/D prefill [Feature][SpecDecode][MRV2] Support prefill_context_kv_only for DFlash-family P/D prefill Nov 23, 2026

@zhenwenqi2024 zhenwenqi2024 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Liuchenbing-2026

Copy link
Copy Markdown
Contributor Author

@zhenwenqi2024 Thanks for the review! Updated in e588de2: replaced the AST-slicing test_sync_spec_pp_cpu_counts_assignment_is_self_contained test with parameterized behavioral test test_npu_model_runner_init_sync_spec_pp_cpu_counts through the real NPUModelRunner.__init__ PP path and downstream PP sync gates (_can_skip_spec_cpu_length_sync and postprocess_num_computed_tokens), covering explicit 0, positive live counts, absent/None/mock profiling fallback, and boolean values (True/False).

@Liuchenbing-2026

Liuchenbing-2026 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit e588de221407f96b9a4185ccb6b65585b3c6656c of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added the ci-run E2E requested manually on the latest commit label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Last updated: 2026-12-04 00:48 UTC+8 for commit dd15415.

ci-gate failed. Reason:

pre-commit failed (lint / markdownlint / mypy / gitleaks). Open the failed 'pre-commit' job above, fix the reported issues in your PR, and push again. No test label is needed for this failure.

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).

@Liuchenbing-2026
Liuchenbing-2026 force-pushed the feat/prefill-context-kv-only-mrv2 branch from e588de2 to 259c50a Compare November 23, 2026 16:47
@Liuchenbing-2026

Liuchenbing-2026 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 259c50a8cc59feb522727d44dd4e6a039d5c9d2b of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Total Coverage Diff Coverage
Total 166854 lines 163 lines
Missing 45199 lines 18 lines
Coverage 73% 88%

More info see: Summary

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Dec 1, 2026
@zhenwenqi2024
zhenwenqi2024 force-pushed the feat/prefill-context-kv-only-mrv2 branch from fc14b55 to e84b8f2 Compare December 1, 2026 03:36

Copy link
Copy Markdown
Collaborator

@Liuchenbing-2026 I rebased the three PR commits onto 40fcc1444 and pushed e84b8f2fe. The linear history keeps your original authorship and carries both PP fixture changes in the commit that needs them, so CI can replay it.

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.

zhenwenqi2024 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

/run
[Bot]: run command accepted. E2E has been queued on the latest commit e84b8f2feef82c29ab98c46e2e75405ab4fa02b3 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Dec 1, 2026

Copy link
Copy Markdown
Collaborator

@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 c410543d9f, the helpers use the upstream values directly, including a scheduled count of zero. Both object shapes are now tested without overriding the version string. Ruff, 136 focused PP cases and 48 source-isolated compatibility cases passed locally.

zhenwenqi2024 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 8d578bca9fc39f5b2197a0d2eac8a8d32d7b9ea0 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Dec 1, 2026

zhenwenqi2024 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

@Liuchenbing-2026 In d3c332b I removed the new helpers from vllm_ascend/utils.py. Callers now read the upstream context-KV flags directly, and a scheduled draft count of zero still skips drafting. I also replaced the 0.34 checks in DFlash and its tests with checks for the upstream API.

zhenwenqi2024 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

/run
[Bot]: run command accepted. E2E has been queued on the latest commit d3c332b6122cd5596172b8b0a0333815009d1a5a of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

Copy link
Copy Markdown
Collaborator

@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.

zhenwenqi2024 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

/run
[Bot]: run command accepted. E2E has been queued on the latest commit e8f5072ae0ed8d4cb410f7d05080e581233d1ca7 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

Copy link
Copy Markdown
Collaborator

@Liuchenbing-2026 In 04a7662 I moved builder filtering to the start of build_attn_metadata. DCP, TurboQuant and the metadata builders now use the same filtered groups. An all-empty build returns {} before DCP config lookup, and live groups keep their original cache indices.

zhenwenqi2024 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 04a76622129b0133921ac50a42295b0e371cfb53 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

Copy link
Copy Markdown
Collaborator

@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.

zhenwenqi2024 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 085175d36d4ef06649ad866be43e5b0c5959620c of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

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>
@Liuchenbing-2026

Liuchenbing-2026 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 7cdf9225d312f3ceaccd4129ed18ef08bfb1a8d5 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@Liuchenbing-2026

Liuchenbing-2026 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

/rerun
[Bot]: rerun completed.

Rerun (failed jobs only):

  • E2E

… 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>
@Liuchenbing-2026

Liuchenbing-2026 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 836522ec0909c12288efc83a59b2ef96a65bc0f3 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

…ts.md

Signed-off-by: liuchenbing <chenliumail@163.com>
@Liuchenbing-2026

Liuchenbing-2026 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit dd15415d394e7eac7c5443ed638d38acc3d78fbf of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-run E2E requested manually on the latest commit documentation Improvements or additions to documentation module:ops module:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants