Skip to content

[BugFix] Fix tpu_model_runner block_id concatenation - #19228

Merged
njhill merged 4 commits into
vllm-project:mainfrom
njhill:fix-tpu-preempt
Jun 6, 2025
Merged

njhill merged 4 commits into
vllm-project:mainfrom
njhill:fix-tpu-preempt

Conversation

@njhill

@njhill njhill commented Jun 5, 2025 •

Copy link
Copy Markdown
Member

This was an oversight when adding support for multiple kv cache groups. The inner block_id lists should be extended, not the outer per-cache group list.

This had been done correctly in gpu_model_runner but I've also updated that to use zip for consistency.

This was an oversight when adding support for multiple kv cache groups. The inner block_id lists should be extended, not the outer per-cache group list.

This had been done correctly in gpu_model_runner but I've also updated that to use zip for consistency.

Signed-off-by: Nick Hill <nhill@redhat.com>
@njhill
njhill requested a review from heheda12345 June 5, 2025 17:41
@njhill njhill added the bug Something isn't working label Jun 5, 2025

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

Hello @njhill, 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!

Summary of Changes

Hello! Gemini or gemini-code-assist here, providing a summary of this pull request. This PR addresses a bug in the tpu_model_runner where the block IDs for requests were being incorrectly concatenated. When supporting multiple KV cache groups, the block IDs should be extended within each group's list, not the main list containing the groups themselves. This PR fixes this by iterating through the inner block ID lists and extending them individually using zip. Additionally, the gpu_model_runner, which already handled this correctly, has been updated to also use the zip approach for consistency across runners.

Highlights

  • Bug Fix: Fixes a bug in tpu_model_runner related to the incorrect concatenation of block IDs when handling multiple KV cache groups.
  • Correct Block ID Handling: Ensures that new block IDs are appended to the correct inner lists corresponding to KV cache groups, rather than the outer list.
  • Code Consistency: Updates the gpu_model_runner to use the same zip-based approach for block ID concatenation as the corrected tpu_model_runner, improving code consistency.

Changelog

  • vllm/v1/worker/gpu_model_runner.py
    • Refactored block ID concatenation logic in _update_states to use zip for iterating over req_state.block_ids and req_data.new_block_ids (lines 463-466), aligning with the fix in tpu_model_runner for consistency.
  • vllm/v1/worker/tpu_model_runner.py
    • Fixed bug in _update_states where block IDs were incorrectly extended at the outer list level (line 410).
    • Updated block ID concatenation logic to correctly iterate through inner block ID lists using zip and extend them individually (lines 410-413).
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


List grows the wrong way,
Inner groups need new blocks now,
Zip aligns the path.

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

@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 effectively addresses a bug related to the concatenation of block IDs when multiple KV cache groups are enabled. The use of zip with strict=True is a clean and safe way to iterate over the corresponding lists and ensures correctness. The change in gpu_model_runner.py aligns the implementation style with the fix in tpu_model_runner.py, which is a good consistency improvement.

Summary of Findings

  • Bug Fix: Incorrect Block ID Concatenation: The primary finding is the fix for a bug in tpu_model_runner.py where block IDs were incorrectly concatenated when multiple KV cache groups were used. The original code extended the outer list instead of the inner lists, leading to incorrect state updates.
  • Code Readability and Safety: The use of zip with strict=True improves the readability and safety of the code in both gpu_model_runner.py and tpu_model_runner.py by making the pairing of lists explicit and adding a check for equal lengths.

Merge Readiness

This pull request fixes a high-severity bug in the TPU model runner and improves consistency in the GPU model runner. The changes are well-implemented and directly address the issue. Based on my review, the code is in good shape to be merged. Please note that I am unable to directly approve the pull request; other reviewers should review and approve this code before merging.

Comment thread vllm/v1/worker/tpu_model_runner.py Outdated
Comment on lines +410 to +413
for block_ids, new_block_ids in zip(req_state.block_ids,
req_data.new_block_ids,
strict=True):
block_ids.extend(new_block_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

This change correctly fixes the bug where the outer list req_state.block_ids was being extended with the inner lists from req_data.new_block_ids. The new code iterates through the inner lists using zip and extends them individually, which is the correct behavior for handling multiple KV cache groups. This addresses a high-severity correctness issue.

for block_ids, new_block_ids in zip(req_state.block_ids,
                                                    req_data.new_block_ids,
                                                    strict=True):
                    block_ids.extend(new_block_ids)

Comment thread vllm/v1/worker/gpu_model_runner.py Outdated
Comment on lines +463 to +466
for block_ids, new_block_ids in zip(req_state.block_ids,
req_data.new_block_ids,
strict=True):
block_ids.extend(new_block_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.

medium

Replacing the range(len(...)) loop with zip is a nice improvement for readability and directly expresses the intent of iterating over pairs of lists. Using strict=True is also a good practice to catch potential data inconsistencies early.

for block_ids, new_block_ids in zip(req_state.block_ids,
                                                    req_data.new_block_ids,
                                                    strict=True):
                    block_ids.extend(new_block_ids)

@mergify mergify Bot added v1 tpu Related to Google TPUs labels Jun 5, 2025
@github-actions

github-actions Bot commented Jun 5, 2025

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

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

LGTM, thanks for fixing this!

@njhill njhill added the ready ONLY add when PR is ready to merge/full CI is needed label Jun 5, 2025

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

LGTM!

@heheda12345
heheda12345 enabled auto-merge (squash) June 6, 2025 02:03
@heheda12345
heheda12345 disabled auto-merge June 6, 2025 02:30
@heheda12345

Copy link
Copy Markdown
Contributor

https://buildkite.com/vllm/ci/builds/21527#019741fe-6ddd-4c64-8081-a983b0faebb0/1917-2248
Seems to be a CI failure related to this PR.

@njhill
njhill merged commit 46ecc57 into vllm-project:main Jun 6, 2025
@njhill
njhill deleted the fix-tpu-preempt branch June 6, 2025 23:28
0826joyce pushed a commit to 0826joyce/vllm-serving-optimization that referenced this pull request May 19, 2026
philippesic pushed a commit to philippesic/vllm-semantic-cache that referenced this pull request Jul 19, 2026
plasticchris pushed a commit to plasticchris/vllm that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready ONLY add when PR is ready to merge/full CI is needed tpu Related to Google TPUs v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants