Skip to content

Conversation

Hanchenli
Copy link
Contributor

@Hanchenli Hanchenli commented Aug 27, 2025

fix #23347

Purpose

This PR is to fix for #23347. The bug is due to that when requests are evicted due to low priority and not enough KV space, scheduled_running_reqs are not updated. This PR adds the line to update scheduled_running_reqs and an example test case for scheduler from #23346 .

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link
Contributor

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

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 addresses a crash in priority scheduling during preemption by updating the scheduled_running_reqs list. The fix is correct in principle, and the accompanying test case is a valuable addition for verifying this scenario. However, the implementation of the fix in vllm/v1/core/sched/scheduler.py has a flaw that could lead to a ValueError, as it attempts to remove an item from a list without first verifying its presence. This could cause a crash under certain conditions, which I've detailed in a specific comment.

@@ -253,6 +253,7 @@ def schedule(self) -> SchedulerOutput:
key=lambda r: (r.priority, r.arrival_time),
)
self.running.remove(preempted_req)
scheduled_running_reqs.remove(preempted_req)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This line can cause a ValueError if preempted_req has not been scheduled yet in the current schedule() call, and is therefore not present in scheduled_running_reqs. This can happen if a request being processed triggers its own preemption, or preempts another request that hasn't been processed yet in the current scheduling iteration.

To prevent a crash, you should check if the request is in the list before attempting to remove it.

Suggested change
scheduled_running_reqs.remove(preempted_req)
if preempted_req in scheduled_running_reqs:
scheduled_running_reqs.remove(preempted_req)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Hanchenli I think this make sense. Can you double check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@heheda12345 Hi, I think this makes sense. I just updated.

Copy link
Collaborator

@heheda12345 heheda12345 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the fix.

@heheda12345 heheda12345 enabled auto-merge (squash) August 27, 2025 21:57
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 27, 2025
@heheda12345 heheda12345 merged commit 5da4f5d into vllm-project:main Aug 28, 2025
36 checks passed
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
dumb0002 pushed a commit to dumb0002/vllm that referenced this pull request Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed v1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: V1 priority scheduling crashes at preemption
2 participants