Skip to content

[Bugfix]Stop zero-progress preemption cascades for deferred KV frees - #16265

Open
luoxiaolin712 wants to merge 2 commits into
vllm-project:releases/v0.27.1rcfrom
luoxiaolin712:kv_pool_0.27.1
Open

luoxiaolin712 wants to merge 2 commits into
vllm-project:releases/v0.27.1rcfrom
luoxiaolin712:kv_pool_0.27.1

Conversation

@luoxiaolin712

@luoxiaolin712 luoxiaolin712 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

vllm fix PR
This PR fixes one known zero-progress transition in the running-request
allocation retry. It does not change the deferred-free safety fence, model
output semantics, or FCFS/PRIORITY victim-selection policy.

Does this PR introduce any user-facing change?

NA

How was this patch tested?

vllm serve /mnt/share/MiniMax-M3-MXFP8 \
  --host 0.0.0.0 \
  --served-model-name minimax \
  --trust-remote-code \
  --distributed-executor-backend mp \
  --tensor-parallel-size 4 \
  --data-parallel-size 2 \
  --enable-expert-parallel \
  --dtype bfloat16 \
  --quantization mxfp8 \
  --max-model-len 140000 \
  --max-num-batched-tokens 16384 \
  --kv-cache-dtype fp8 \
  --max-num-seqs 500 \
  --enable-prefix-caching \
  --async-scheduling \
  --api-server-count=1 \
  --reasoning-parser minimax_m3 \
  --compilation-config '{"cudagraph_mode":"FULL_DECODE_ONLY"}' \
  --additional-config '{"enable_cpu_binding":true,"ascend_compilation_config":{"fuse_qknorm_rope":false,"fuse_norm_quant":false,"enable_static_kernel":false},"multistream_overlap_shared_expert":true,"enable_shared_expert_dp":true,"enable_reduce_sample":false}' \
  --speculative-config '{"method":"eagle3","model":"/mnt/share/MiniMax-M3-EAGLE","num_speculative_tokens":3,"kv_cache_dtype": "bfloat16"}' \
  --safetensors-load-strategy prefetch \
  --port 10086 \
  --gpu-memory-utilization 0.92 \
  --kv-transfer-config '{
    "kv_connector": "AscendStoreConnector",
    "kv_role": "kv_both",
    "kv_connector_extra_config": {
        "backend": "mooncake",
        "lookup_rpc_port": "0"
        }
    }' \

… frees

Backport vLLM PR #49675 (fix/zero-reclaim-preemption-cascade) as a
platform patch. With deferred block freeing enabled (async scheduling +
PD KV-consumer), the schedule() allocation retry loop could pick a
preemption victim whose blocks are still fenced by an in-flight step:
freeing them is deferred, so the retry allocate_slots keeps failing and
preempts the running requests one by one, stalling the engine.

The patch ports the three PR deltas onto vllm-ascend:
- the retry loop selects the victim before removing it and breaks out
  when _should_defer_request_block_free(victim) is true (retried on a
  later step instead of cascading);
- new Scheduler._should_defer_request_block_free helper;
- _free_request_blocks refactored onto the same helper.

schedule() is an ~800-line method, so (as in patch_balance_schedule.py)
the whole body is copied verbatim from the pinned release tag
(.github/vllm-release-tag.commit = v0.27.1) with only the
preemption-loop delta, adapted to the pin's bookkeeping. Install is
guarded: skip when the installed vLLM already ships the fix, fail
loudly when the installed schedule() signature no longer matches the
pin. Behavior is unchanged when defer_block_free is disabled.

Signed-off-by: lty <linhebiwen@gmail.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 introduces a critical bugfix for the vLLM scheduler, specifically addressing a preemption cascade issue encountered when using async scheduling and deferred KV block freeing. By backporting logic from upstream vLLM, the patch ensures that the scheduler avoids preempting requests whose blocks are still in use by pending GPU steps, thereby preventing engine stalls. The implementation includes a new helper method and a carefully guarded patch to the scheduler's main loop to maintain compatibility with the current pinned vLLM release.

Highlights

  • Preemption Cascade Fix: Backported vLLM PR #49675 to prevent zero-progress preemption cascades that occur when deferred block freeing is enabled.
  • Scheduler Logic Update: Modified the scheduler's allocation retry loop to select preemption victims before removal and bail out if blocks are still fenced by in-flight steps.
  • Safety and Guardrails: Added import-time guards to ensure the patch is only applied if the installed vLLM version does not already contain the fix and matches the expected signature.
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

This pull request backports vLLM PR #49675 to introduce a defer-aware preemption retry mechanism, preventing zero-reclaim preemption cascades when deferred block freeing is enabled. However, a critical issue was identified where this patch completely overwrites Scheduler.schedule, silently disabling the previously imported patch_balance_schedule.py patch. It is recommended to merge these patches or dynamically chain the schedule method.

Suggested PR Title:

[Ops][BugFix] Backport defer-aware preemption retry from vLLM PR #49675

Suggested PR Summary:

### What this PR does / why we need it?
This PR backports vLLM PR #49675 to introduce a defer-aware preemption retry mechanism. This prevents a zero-reclaim preemption cascade and engine stalls when deferred block freeing is enabled (async scheduling + PD KV-consumer). It patches `Scheduler.schedule`, `Scheduler._free_request_blocks`, and adds `Scheduler._should_defer_request_block_free`.

However, there is a critical issue: this patch completely overwrites `Scheduler.schedule`, which is also patched by `patch_balance_schedule.py`. Since this patch is imported after, it silently disables the balance scheduling feature. These patches should be merged or refactored to dynamically chain/wrap the original method.

### Does this PR introduce _any_ user-facing change?
No, this is an internal scheduling optimization and bug fix.

### How was this patch tested?
CI passed with existing tests.

)
Scheduler._should_defer_request_block_free = _should_defer_request_block_free
Scheduler._free_request_blocks = _free_request_blocks
Scheduler.schedule = _defer_free_aware_schedule

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.

critical

Both patch_balance_schedule.py and patch_defer_block_free_schedule.py monkey-patch Scheduler.schedule by completely overwriting Scheduler.schedule with their respective implementations.

Because patch_defer_block_free_schedule is imported after patch_balance_schedule in vllm_ascend/patch/platform/__init__.py, it completely overwrites Scheduler.schedule, silently disabling the balance scheduling feature even if enable_balance_scheduling is set to True.

To resolve this, you should either:

  1. Merge the two scheduling patches into a single patch file that handles both balance scheduling and deferred block freeing.
  2. Dynamically chain/wrap the original schedule method or each other's patched methods instead of copying and overwriting the entire 800-line method verbatim twice.

Import patch_defer_block_free_schedule before patch_balance_schedule so it patches the original Scheduler base class. Previously it ran after balance had swapped the module-level Scheduler name to BalanceScheduler, silently overwriting BalanceScheduler.schedule (including the balance-enabled path) with the defer-aware copy. Patching the base first lets BalanceScheduler inherit the fix via super().schedule() on its disabled path.

Signed-off-by: lty <linhebiwen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-precise run selected e2e test for pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants