Skip to content

[BugFix][KV Pool] Fix PCP/DCP hybrid prefix restoration - #23873

Open
MAyang38 wants to merge 5 commits into
vllm-project:mainfrom
MAyang38:fix/memcache-pcp-dcp-shards
Open

MAyang38 wants to merge 5 commits into
vllm-project:mainfrom
MAyang38:fix/memcache-pcp-dcp-shards

Conversation

@MAyang38

@MAyang38 MAyang38 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

Fix incorrect external prefix restoration with context parallelism. In
TP1/PP4/PCP8/DCP8, different token shards can address the same Memcache
object. Hybrid pooling also treated recurrent state as token-sharded:
a 12,288-token prefix could select state-table column 0 instead of Core's
column 7 when the Mamba block size is 1,536.

  • Isolate token-sharded objects by DCP rank and retain the real PCP head
    partitions for recurrent state, including partial objects and all-shard
    readability checks.
  • Resolve per-group token spans with Core's sharding rule in both scheduler
    and worker. Mamba and other unsharded groups retain their original spans.
  • Reject invalid store/load reachability masks before unchecked pages can
    be transferred; do not fall back to an unrestricted mask after an invariant fails.
  • Use a new Memcache CP layout identity covering normalized model, cache,
    speculative and loader configurations, PP partitions, CP interleave,
    parallel sizes and resolved spans. Worker-local layer membership does
    not enter the hash. Also invalidate bulk objects affected by the old
    state-span rule.

The layout/configuration hashes are computed when binding keys, outside
the per-layer transfer loop. No device kernel, sampling, environment
variable or user configuration is added.

Related fixes #16498, #23565 and #22830 do not cover the TP1 collision or
this Core/Store state-span mismatch. The independent Indexer writer change
in #23774 is not included. The observed repeated-output cases still need
post-fix model validation; this PR does not claim that every anomaly has
been attributed or eliminated.

Does this PR introduce any user-facing change?

Yes. Prevent shard overwrites and incorrectly positioned recurrent-state
restoration in affected CP layouts. Invalid reachability masks now abort
the forward step instead of allowing unchecked cache state.

Upgrade all participating readers and writers together. The new
memcache-cp-v2 layout excludes the earlier
memcache-pcp-dcp-v1 objects. Affected bulk state objects also use a new
namespace. Existing affected prefixes become cold automatically; no
pool-wide deletion or additional setting is required. Attention-only
TP-backed DCP retains its existing key format.

Updated the AscendStore migration guide and
release_notes/fragments/23873.yaml.

How was this patch tested?

Based on Ascend main cedeae55d2d92c8ed6086da65bcc0c435354e2fb.
All work for this follow-up was performed on Windows; no serving container
or running service was changed.

  • Source-isolated CPU regression file:
    python -m pytest --noconftest -q -p no:cacheprovider tests/ut/distributed/ascend_store/test_memcache_pcp_dcp_cpu.py.
    Together with the selected metadata tests below: 91 passed, 30 subtests
    passed, 1 deselected
    .
  • Metadata selection used
    tests/ut/distributed/ascend_store/test_metadata.py -k "not sharded_mamba_groups_exclude_tp_replicas".
    The excluded existing no-vLLM mock test calls dataclasses.replace
    on a non-dataclass fake Mamba spec. The new CPU tests independently
    cover Mamba state coordinates and plain/uniform spec representations.
  • The CPU harness extracts production span, key, mask and address builders
    and Core's effective-span method, substituting external types. Byte
    checks use distinct CPU buffers and production transfer descriptors.
    Coverage includes CP sizes 1/2/4/8, PP1/PP4, missing-shard rejection,
    partial/state objects, old-object exclusion, layout changes, normalized
    scheduler/worker config equivalence, bulk namespace migration and mask
    failures. These are not installed-vLLM, SDK or NPU results.
  • Negative control using the prior production span calculation:
    the state-byte regression fails for DCP2/4/8 with columns 0 instead of
    1/3/7; the DCP1 control remains correct. The previous token-shard
    overwrite negative control is retained from the initial patch.
  • Memcache and namespace module import smoke checks passed with the
    repository's CPU dependency mocks. Broader backend/worker collection
    needs the installed-vLLM dependency environment.
  • Ruff check/format, codespell, typos, Markdown lint, filename/package-init,
    logger, forbidden-import, boolean-context-manager, long-function,
    symbolic-meta and whitespace checks passed for changed files.
    Focused hooks used Windows-compatible launchers.
  • Full bash format.sh ci was attempted but did not finish installing
    actionlint's Go environment and was interrupted. Gitleaks could not run
    because the local binary and wget are unavailable. These checks remain
    for CI; no workflow files or secrets are added.

Pending before merge: NPU/SDK save-and-restore with distinct shard and
checkpoint contents, forced external-cache model replay with local HBM
prefix misses, repeated-output regression cases at 30/60 concurrency, and
matched performance/storage measurements. No model accuracy or
performance improvement is claimed from CPU checks.


Checklist

Testing

  • Boundary / edge-case coverage

  • Regression test and previous-code negative control

  • Error / failure path coverage

  • CPU byte restoration and Core/Store span consistency

  • NPU/SDK and model inference validation

  • Performance impact: matched hardware validation pending

  • vLLM main: vllm-project/vllm@c410543

@github-actions github-actions Bot added documentation Improvements or additions to documentation module:tests labels Nov 30, 2026
@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!

@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 Memcache with matching PCP and DCP sizes when using layerwise transfer and a tensor parallel size of 1, utilizing separate pool objects for each DCP rank. It includes documentation updates, CPU-runnable unit tests, and key builder modifications. The review feedback correctly identifies a Python 3.9 compatibility issue where the PEP 604 union operator | is used in type annotations without from __future__ import annotations, which would cause a TypeError at import time.

@MAyang38 MAyang38 changed the title [BugFix][KV Pool] Isolate Memcache objects for PCP-backed DCP shards [BugFix][KV Pool] Fix PCP/DCP hybrid prefix restoration Nov 30, 2026
@MAyang38
MAyang38 marked this pull request as ready for review November 30, 2026 15:43
@weijinqian0
weijinqian0 enabled auto-merge (squash) November 30, 2026 15:46
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Last updated: 2026-12-01 02:14 UTC+8 for commit d3a1ab9.

ci-gate failed. Reason:

CODEOWNERS approval gate failed: at least one changed file has no approval from its owner(s). Open the 'CODEOWNERS' steps above to see which files are missing approvals and who can approve.
select-tests failed. Open the failed 'select-tests' job above to see which step failed (checkout/rebase, coverage config validation, or test selection).

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

Missing owner approvals. Every changed file needs one approval from its CODEOWNERS owner(s):

  • docs/source/user_guide/feature_guide/kv_cache_pool_ascend_store.md: waiting for approval from one of: @liqian79

Copy link
Copy Markdown
Contributor
  1. Mamba state keeps its original token span under DCP. Multiply grouped_block_size by dcp_size only for groups that Core marks as dcp_sharded.
  2. With TP=1, PCP=8, DCP=8, self.put_step is 1, so the layerwise builder skips the DCP shard-offset branch. Each DCP shard starts at offset zero and needs its own Memcache key.

@Dawn952 Dawn952 added the ready-precise run selected e2e test for pr label Nov 30, 2026
auto-merge was automatically disabled November 30, 2026 17:28

Head branch was pushed to by a user without write access

MAyang38 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 8c8036b2c4d274a4005c8a451305d11347009226 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 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage

Total Coverage Diff Coverage
Total 162841 lines 94 lines
Missing 44359 lines 33 lines
Coverage 73% 64%

More info see: Summary

MAyang38 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

MAyang38 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit d3a1ab9775354cb9b215b84fba0c61e2524ed7f1 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 30, 2026
Give token-sharded KV separate DCP objects for TP1 with matching PCP and DCP sizes. Preserve PCP head partitions for recurrent state, require every shard during lookup, and use a new namespace to exclude overwritten legacy entries. Carry shard coordinates through partial saves.

Validate with CPU byte-copy regressions and legacy key checks. NPU model and performance validation remain pending.

Signed-off-by: MAyang38 <mafajun0328@gmail.com>
Signed-off-by: MAyang38 <mafajun0328@gmail.com>
DCP hybrid prefix hits can restore the wrong recurrent checkpoint because
the pool scales state pages as token shards. Resolve each group's span
with Core's rule and invalidate objects written at the old boundaries.

Version Memcache CP identities by normalized model/cache configuration
and partition, and reject invalid reachability masks before transfer.

Validation: 91 selected CPU tests and 30 subtests passed; the previous
span rule fails the DCP2/4/8 byte regression. NPU/SDK replay remains pending.

Signed-off-by: MAyang38 <mafajun0328@gmail.com>
The source-isolated CPU regression fails CI mypy on all supported target
versions. Declare AST statement lists, the shared production namespace
and NumPy buffers, and parse the wrapper class to support AST differences
between Python 3.10, 3.11 and 3.12.

Validation: targeted mypy passes for all three versions; 15 CPU tests and
20 subtests pass. Applicable lint hooks pass. Full format.sh ci was blocked
while installing the local actionlint environment; CI verification remains.

Signed-off-by: MAyang38 <mafajun0328@gmail.com>
The namespace tests exercise the non-HiSparse fallback with a minimal
VllmConfig fake. The new group-span check reads cache_config.block_size,
which the fake omitted. Supply that field to match the real config.

Validation: all nine CI failures reproduce before the fixture change and
pass afterward using the existing tests with source-isolated production
namespace builders. Applicable lint hooks pass; full CPU UT awaits CI.

Signed-off-by: MAyang38 <mafajun0328@gmail.com>
@MAyang38
MAyang38 force-pushed the fix/memcache-pcp-dcp-shards branch from d3a1ab9 to 31f1f85 Compare November 30, 2026 18:15

MAyang38 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

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:tests ready-precise run selected e2e test for pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants