Skip to content

[BugFix][KVPool] Order Memcache bulk KV loads after block zeroing - #23195

Merged
kunpengW-code merged 1 commit into
vllm-project:mainfrom
tyy0829:codex/order-pooled-kv-reload
Nov 26, 2026
Merged

kunpengW-code merged 1 commit into
vllm-project:mainfrom
tyy0829:codex/order-pooled-kv-reload

Conversation

@tyy0829

@tyy0829 tyy0829 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

Fixes #22798 for synchronous Memcache bulk KV loads. PR #22488 orders native GET after block zeroing, but its Mooncake-only condition leaves Memcache exposed to the same race: a queued compute-stream zero can overwrite KV restored by the native transfer.

Remove the backend condition from the existing bulk worker helper. Preserve the not load_async and kv_producer / kv_both guards and both existing call sites (ordinary GET and TP-mismatch GET). No model-runner change is needed.

Extend the existing ordering tests to cover Mooncake and Memcache, including the asynchronous and consumer exclusions in the TP-mismatch path. LayerwiseKVPoolWorker is a sibling of the bulk worker and does not call this helper; this PR changes no layerwise code.

Does this PR introduce any user-facing change?

Yes. Synchronous Memcache bulk prefix hits no longer race with block zeroing. No new configuration is required. No release note fragment is included, as requested.

How was this patch tested?

Unit-tested source (Ascend base bb91cd3f3633dec28d1f44f4d58bd805c3f848ae; vLLM source c410543d9ffff03f5f6c4a8c0ae1d3ad082c4a15):

  • Regression first: with only the test changes, the ordinary-GET and TP-mismatch-GET tests failed because Memcache did not synchronize before GET (2 failed, 2 passed).
  • With the fix, TORCH_DEVICE_BACKEND_AUTOLOAD=0 pytest -q tests/ut/distributed/ascend_store/test_pool_worker.py: 184 passed. Run in an isolated checkout in the r136 container, selecting the above vLLM source through PYTHONPATH; the serving checkout was not modified.
  • Ruff 0.14.0 lint and format checks passed for both changed Python files; git diff --check passed.
  • Local bash format.sh ci could not fetch hooks because of the environment's certificate setup. Subsequently, CI run 45777731632 passed pre-commit and mypy. Its CPU test and test-selection jobs stopped before tests at a release-note modify/delete conflict while flattening the old merge history. The branch is now a single linear commit, rebased successfully onto e953b96e1; both changed files are byte-identical to the tested revision. Fresh CI on this rewritten head is still pending.

Hardware reproduction: equivalent backport, not an end-to-end run of current main. Both #22488 barriers with the backend condition removed were backported onto r136 Ascend 7a7ed073c481d5e3a2fc2194c5b879efb2d373c0, vLLM 4ba787ec9959e566d3b587a796dff07673324da5.

  • Model: DeepSeek-V4-Flash-DSpark-w4a8; Atlas 800I A3, four physical cards (eight logical devices), DP2 x TP4 with expert parallelism. This differs from the issue's DP2 x TP2 because TP2 did not have enough KV capacity for the input on this setup.
  • AscendStoreConnector, kv_both, Memcache Hybrid 1.3.0, local prefix caching disabled, async scheduling enabled. Speculation: DSpark, 5 draft tokens, draft eager mode. Target decode graph mode FULL_DECODE_ONLY; layerwise selects its supported mode. Max model length 36536, max sequences 32, max batched tokens 4096, memory utilization 0.93.
  • Frozen issue-reproduction input: 16393 tokens, temperature 0, 16 output tokens with EOS ignored, 2 sequences per round. Each mode ran one cold round followed by 25 warm rounds.
Mode Warm answer correct Warm full token sequence equals cold External hit / computed prefill per warm sequence
Bulk, adapted #22488 50/50 50/50 16384 / 9
Layerwise, adapted #22488 50/50 50/50 16384 / 9

Bulk recorded 200 successful native batch GETs. Layerwise used GVA batch_copy and recorded no native bulk GETs; its 50 warm outputs also matched the earlier layerwise run without the bulk barrier. Local prefix hits were zero in both runs.

The layerwise comparison retained two separate experimental changes for lazy initialization and persistent DSpark draft KV lifecycle, identically in both layerwise runs. Neither is included in this PR, and this comparison does not establish that unmodified r136 layerwise works. The prior runner-level implementation of this PR was absent from these hardware runs.

Evidence retained locally: pr22488-memcache-comparison-20261126.tar.gz, SHA256 d239c06300f7c9516bfc9258c8332a556da16c078011dfe8ca45b7e47014fc8a; report/logs in issue22798-pr22488-memcache-20261126. These are local artifacts, not public download links.

No throughput/latency improvement is claimed. The added synchronization may reduce overlap for synchronous Memcache prefill; dedicated performance measurements, other hardware, and asynchronous bulk loading were not hardware-tested. Profiling was configured for manual collection but no capture was started.


Checklist

  • Boundary / edge-case coverage: both supported backends and sync/async/role conditions.

  • Regression test: the two GET-ordering tests fail without this change.

  • Meaningful & reliable tests: assert synchronization occurs before the native GET.

  • Performance impact: correctness reproduction completed; dedicated throughput/latency benchmark pending.

  • vLLM main: vllm-project/vllm@c410543

@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 overrides the update_requests method in NPUModelRunner to synchronize the current NPU stream when new block IDs need to be zeroed and synchronous KV loads are present, and adds a corresponding unit test. The feedback suggests using getattr defensively when accessing these attributes on scheduler_output to avoid potential AttributeError exceptions in environments where they might not be defined.

Comment thread vllm_ascend/worker/v2/model_runner.py Resolved
@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.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [BugFix] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Total Coverage Diff Coverage
Total 158923 lines 1 line
Missing 45169 lines 0 lines
Coverage 72% 100%

More info see: Summary

@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 coordinate this with #22488 before both changes land? An MRV2 step with newly allocated blocks and a synchronous Mooncake prefix hit on kv_producer/kv_both can now synchronize in update_requests() and again immediately before GET. The current unit test stops at update_requests(), so it cannot catch the second wait. Could we reuse the synchronous GET fixture from #22488 in one runner-to-connector case that asserts zero → one wait → GET, and retain the connector-side coverage for MRV1, which does not use this override?

@tyy0829 tyy0829 changed the title [BugFix] Order KV block zeroing before synchronous external loads [BugFix][KVPool] Order KV block zeroing before synchronous external loads Nov 26, 2026
@tyy0829
tyy0829 requested a review from HF-001 as a code owner November 26, 2026 07:11
@tyy0829 tyy0829 changed the title [BugFix][KVPool] Order KV block zeroing before synchronous external loads [BugFix] Order Memcache bulk KV loads after block zeroing Nov 26, 2026
@tyy0829 tyy0829 changed the title [BugFix] Order Memcache bulk KV loads after block zeroing [BugFix][KVPool] Order Memcache bulk KV loads after block zeroing Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Last updated: 2026-11-26 17:46 UTC+8 for commit 2b9ef26.

ci-gate failed Resolved: the ci-gate passed for commit 2b9ef26. Keeping this comment so the history stays visible; it will be updated again if a later run on this commit fails.

@kunpengW-code kunpengW-code added the ready-precise run selected e2e test for pr label Nov 26, 2026
Extend the existing synchronous bulk GET barrier to Memcache. Keep asynchronous and consumer exclusions, and cover both backends in the ordinary and TP-mismatch ordering tests.

Signed-off-by: tyy0829 <1455207791@qq.com>
@tyy0829
tyy0829 force-pushed the codex/order-pooled-kv-reload branch from fbef22f to 2b9ef26 Compare November 26, 2026 09:14
@tyy0829

tyy0829 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 2b9ef26e98a7229a4d18fe5c8ca632b30354dbd9 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 26, 2026

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

LGTM

@kunpengW-code
kunpengW-code merged commit c795117 into vllm-project:main Nov 26, 2026
37 checks passed
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 module:tests ready-precise run selected e2e test for pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Ascend: staged request-metadata 的非阻塞 H2D 与 apply-write kernel 无序,导致 KV cache 命中请求答案错误

5 participants