Skip to content

[core] invoke save_new_computed_blocks when computed blocks are not empty#1568

Merged
AlpinDale merged 1 commit into
mainfrom
save_blocks
Nov 4, 2025
Merged

[core] invoke save_new_computed_blocks when computed blocks are not empty#1568
AlpinDale merged 1 commit into
mainfrom
save_blocks

Conversation

@AlpinDale

Copy link
Copy Markdown
Member

No description provided.

… empty

Signed-off-by: AlpinDale <alpindale@gmail.com>

@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 aims to prevent an unnecessary call to save_new_computed_blocks when there are no new computed blocks. This is a good optimization. The accompanying change in single_type_kv_cache_manager.py correctly prevents a KeyError that would otherwise be introduced. However, the condition added in kv_cache_manager.py relies on an object identity check which is not fully reliable for determining if the block list is empty. I've provided a suggestion for a more robust emptiness check.

# Append the new computed blocks to the request blocks until now to
# avoid the case where the new blocks cannot be allocated.
self.coordinator.save_new_computed_blocks(request.request_id, new_computed_block_list)
if new_computed_block_list is not self.empty_kv_cache_blocks.blocks:

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

The condition new_computed_block_list is not self.empty_kv_cache_blocks.blocks checks for object identity, but it doesn't robustly check for emptiness. new_computed_block_list could be a different object that still represents an empty list of blocks (e.g., a tuple of empty lists ([], []) vs the empty tuple of tuples ((), ())). This can lead to unnecessary calls to save_new_computed_blocks.

A more reliable way to check if there are any blocks is to iterate through the outer tuple and check if any of the inner sequences are non-empty. Using a generator expression with any() is an efficient way to do this.

Suggested change
if new_computed_block_list is not self.empty_kv_cache_blocks.blocks:
if any(g for g in new_computed_block_list):

@AlpinDale AlpinDale merged commit 75464d0 into main Nov 4, 2025
0 of 4 checks passed
@AlpinDale AlpinDale deleted the save_blocks branch November 4, 2025 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant