Repository navigation
[BugFix] Fix tpu_model_runner block_id concatenation - #19228
Conversation
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>
There was a problem hiding this comment.
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_runnerrelated 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_runnerto use the samezip-based approach for block ID concatenation as the correctedtpu_model_runner, improving code consistency.
Changelog
- vllm/v1/worker/gpu_model_runner.py
- Refactored block ID concatenation logic in
_update_statesto usezipfor iterating overreq_state.block_idsandreq_data.new_block_ids(lines 463-466), aligning with the fix intpu_model_runnerfor consistency.
- Refactored block ID concatenation logic in
- vllm/v1/worker/tpu_model_runner.py
- Fixed bug in
_update_stateswhere 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
zipand extend them individually (lines 410-413).
- Fixed bug in
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
-
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. ↩
There was a problem hiding this comment.
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.pywhere 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
zipwithstrict=Trueimproves the readability and safety of the code in bothgpu_model_runner.pyandtpu_model_runner.pyby 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.
| 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) |
There was a problem hiding this comment.
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)| 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) |
There was a problem hiding this comment.
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)|
👋 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 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 🚀 |
yaochengji
left a comment
There was a problem hiding this comment.
LGTM, thanks for fixing this!
|
https://buildkite.com/vllm/ci/builds/21527#019741fe-6ddd-4c64-8081-a983b0faebb0/1917-2248 |
Signed-off-by: Nick Hill <nhill@redhat.com>
Signed-off-by: Nick Hill <nhill@redhat.com>
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.