Skip to content

[v0.26.0rc][BugFix][P/D] Backport async KV-delivery preemption fixes - #14723

Open
DavidJiang9 wants to merge 2 commits into
vllm-project:releases/v0.26.0rcfrom
DavidJiang9:backport-50297
Open

[v0.26.0rc][BugFix][P/D] Backport async KV-delivery preemption fixes#14723
DavidJiang9 wants to merge 2 commits into
vllm-project:releases/v0.26.0rcfrom
DavidJiang9:backport-50297

Conversation

@DavidJiang9

@DavidJiang9 DavidJiang9 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Purpose

Backport the async-preemption correctness fixes from upstream vLLM #48245 and #50297 to the v0.26 RC branch.

This fixes stale in-flight output accounting after preemption and prevents P/D producers from delivering outputs whose KV blocks have already been released under memory pressure. The change is needed for Mooncake KV transfer configurations using async scheduling.

Changes

  • track stale in-flight outputs across preemption without underflowing output placeholders;
  • drain ordinary stale outputs losslessly, while dropping/recomputing them when the connector requires reliable KV delivery;
  • add the requires_kv_delivery contract for KV connectors and aggregate it through MultiConnector;
  • mark Mooncake producer connectors and AscendStore as requiring KV delivery;
  • keep the AsyncScheduler-specific override in a dedicated patch module;
  • preserve the existing balance-scheduler deltas and add regression guards;
  • add CPU unit tests adapted from both upstream PRs.

Validation

  • git diff --check origin/releases/v0.26.0rc...HEAD — passed.
  • Targeted unit tests were attempted:
    python -m pytest -q tests/ut/patch/platform/test_kv_delivery_preemption.py tests/ut/patch/platform/test_patch_balance_schedule.py
    • the default environment stopped during collection because vllm is not installed;
    • using the local vLLM checkout via PYTHONPATH also stopped during collection because the installed Torch does not expose torch.library.infer_schema.
    • No test assertion was reached; CI should run these tests with the branch's supported vLLM/Torch environment.

Upstream

Signed-off-by: jiangkaiqiang <jiangkaiqiang@huawei.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request backports critical correctness fixes from upstream vLLM regarding async KV-delivery preemption. The changes ensure that in-flight output accounting remains consistent during preemption and prevents the delivery of outputs whose KV blocks have been released, which is vital for maintaining stability in Mooncake KV transfer configurations using async scheduling.

Highlights

  • Stale Output Handling: Backported stale-output handling for async preemption from upstream vLLM to ensure accurate in-flight output accounting.
  • KV Delivery Contract: Implemented the requires_kv_delivery contract for KV connectors to manage reliable delivery during memory pressure and preemption.
  • Connector Updates: Updated Mooncake and AscendStore connectors to correctly report KV delivery requirements.
  • Regression Testing: Added comprehensive CPU unit tests to verify the compatibility-boundary state transitions and logic fixes.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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


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

Suggested PR Title:\n\nmarkdown\n[Ops][Feature] Backport vLLM #48245 and #50297 stale-output handling and KV delivery preemption\n\n\nSuggested PR Summary:\n\nmarkdown\n### What this PR does / why we need it?\nThis PR backports the stale-output handling from vLLM #48245 and the KV delivery preemption contract from vLLM #50297. It introduces `patch_async_scheduler.py` to handle stale outputs losslessly in async scheduling, updates `patch_balance_schedule.py` with the new preemption and scheduling logic, and adds `requires_kv_delivery` properties to the connectors.\n\nFeedback from the review suggests:\n- Adding defensive programming checks using `getattr` when accessing `_kv_transfer_config` and `requires_kv_delivery` on connectors to prevent potential `AttributeError`s.\n- Forwarding the `is_stale` argument in the `super` call within `_update_request_with_output` in `patch_async_scheduler.py` to ensure correct inheritance behavior.\n\n### Does this PR introduce _any_ user-facing change?\nNo.\n\n### How was this patch tested?\nTested with new CPU regression tests in `tests/ut/patch/platform/test_kv_delivery_preemption.py` and updated AST checks in `tests/ut/patch/platform/test_patch_balance_schedule.py`.\n

Comment on lines +99 to +101
def _requires_kv_delivery(connector: KVConnectorBase_V1) -> bool:
"""Match the producer-role default introduced by vLLM #50297."""
return connector._kv_transfer_config.is_kv_producer

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.

high

Defensive programming check: If connector does not have the _kv_transfer_config attribute, or if it is None, accessing connector._kv_transfer_config.is_kv_producer will raise an AttributeError and crash the scheduler during initialization. Using getattr with a default value prevents this potential runtime crash.

Suggested change
def _requires_kv_delivery(connector: KVConnectorBase_V1) -> bool:
"""Match the producer-role default introduced by vLLM #50297."""
return connector._kv_transfer_config.is_kv_producer
def _requires_kv_delivery(connector: KVConnectorBase_V1) -> bool:
"""Match the producer-role default introduced by vLLM #50297."""
config = getattr(connector, "_kv_transfer_config", None)
return config.is_kv_producer if config is not None else False

Comment on lines +104 to +106
def _multi_requires_kv_delivery(connector: MultiConnector) -> bool:
"""A MultiConnector must preserve every reliable child hand-off."""
return any(child.requires_kv_delivery for child in connector._connectors)

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.

high

Defensive programming check: To prevent potential AttributeError if any child connector in _connectors does not implement or have the requires_kv_delivery attribute, use getattr with a default of False.

Suggested change
def _multi_requires_kv_delivery(connector: MultiConnector) -> bool:
"""A MultiConnector must preserve every reliable child hand-off."""
return any(child.requires_kv_delivery for child in connector._connectors)
def _multi_requires_kv_delivery(connector: MultiConnector) -> bool:
"""A MultiConnector must preserve every reliable child hand-off."""
return any(getattr(child, "requires_kv_delivery", False) for child in connector._connectors)

self._use_consumer_partial_group_hits = not bool(
kv_transfer_config is not None and kv_transfer_config.is_kv_producer
)
self.requires_kv_delivery = bool(self.connector is not None and self.connector.requires_kv_delivery)

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.

high

Defensive programming check: Use getattr to safely retrieve requires_kv_delivery from self.connector to avoid potential AttributeError if a custom or third-party connector is used that does not implement this property.

Suggested change
self.requires_kv_delivery = bool(self.connector is not None and self.connector.requires_kv_delivery)
self.requires_kv_delivery = bool(self.connector is not None and getattr(self.connector, "requires_kv_delivery", False))

is_stale: bool = False,
) -> tuple[list[int], bool]:
status_before_update = request.status
new_token_ids, stopped = super(AsyncScheduler, self)._update_request_with_output(request, new_token_ids)

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.

high

For robustness and correctness of the inheritance chain, the overridden _update_request_with_output method should forward the is_stale argument to the super call, ensuring any parent class or mixin that relies on this parameter receives the correct state.

Suggested change
new_token_ids, stopped = super(AsyncScheduler, self)._update_request_with_output(request, new_token_ids)
new_token_ids, stopped = super(AsyncScheduler, self)._update_request_with_output(
request, new_token_ids, is_stale=is_stale
)

Signed-off-by: jiangkaiqiang <jiangkaiqiang@huawei.com>
@DavidJiang9
DavidJiang9 marked this pull request as ready for review August 21, 2026 08:03
@kunpengW-code kunpengW-code added the ready run e2e test for non-main branch label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:tests ready run e2e test for non-main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants