Skip to content

[BugFix] Fix MultiConnector test after HMA changes #19291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions tests/v1/kv_connector/unit/test_multi_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def wrapper(*args, **kwargs):
if isinstance(arg, int):
to_log.append(str(arg))
elif isinstance(arg, KVCacheBlocks):
to_log.append(f"num_blocks={len(arg.blocks)}")
to_log.append(
f"num_blocks={[len(b) for b in arg.blocks]}")

# Log the event as a line to the file
try:
Expand Down Expand Up @@ -176,15 +177,15 @@ def test_multi_shared_storage_connector_consistency():
# on each connector in turn.
assert events["storage1-SCHEDULER"][:3] == [
'get_num_new_matched_tokens 0',
'update_state_after_alloc num_blocks=0 0', 'build_connector_meta'
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
]
assert events["storage1-WORKER"][:5] == [
'register_kv_caches', 'bind_connector_metadata', 'start_load_kv',
'wait_for_layer_load', 'save_kv_layer'
]
assert events["storage2-SCHEDULER"][:3] == [
'get_num_new_matched_tokens 0',
'update_state_after_alloc num_blocks=0 0', 'build_connector_meta'
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
]
assert events["storage2-WORKER"][:5] == [
'register_kv_caches', 'bind_connector_metadata', 'start_load_kv',
Expand All @@ -205,11 +206,11 @@ def test_multi_shared_storage_connector_consistency():
# chosen).
assert events["storage1-SCHEDULER"][:3] == [
'get_num_new_matched_tokens 0',
'update_state_after_alloc num_blocks=7 96', 'build_connector_meta'
'update_state_after_alloc num_blocks=[7] 96', 'build_connector_meta'
]
assert events["storage2-SCHEDULER"][:3] == [
'get_num_new_matched_tokens 0',
'update_state_after_alloc num_blocks=0 0', 'build_connector_meta'
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
]

# Delete storage1 connector state
Expand All @@ -229,11 +230,11 @@ def test_multi_shared_storage_connector_consistency():
# blocks for the second connector.
assert events["storage1-SCHEDULER"][:3] == [
'get_num_new_matched_tokens 0',
'update_state_after_alloc num_blocks=0 0', 'build_connector_meta'
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
]
assert events["storage2-SCHEDULER"][:3] == [
'get_num_new_matched_tokens 0',
'update_state_after_alloc num_blocks=7 96', 'build_connector_meta'
'update_state_after_alloc num_blocks=[7] 96', 'build_connector_meta'
]

# Clean up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ def update_state_after_alloc(self, request: "Request",
num_external_tokens: int):
chosen_connector = self._requests_to_connector.get(
request.request_id, -1)
empty_blocks = blocks.new_empty()
for i, c in enumerate(self._connectors):
if i == chosen_connector:
# Forward call to the chosen connector (if any).
c.update_state_after_alloc(request, blocks,
num_external_tokens)
else:
# Call with empty blocks for other connectors.
c.update_state_after_alloc(request,
KVCacheBlocks.create_empty(), 0)
c.update_state_after_alloc(request, empty_blocks, 0)

def build_connector_meta(
self,
Expand Down
4 changes: 4 additions & 0 deletions vllm/v1/core/kv_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def get_unhashed_block_ids(self) -> list[int]:
if block.block_hash is None
]

def new_empty(self) -> "KVCacheBlocks":
"""Creates a new KVCacheBlocks instance with no blocks."""
return KVCacheBlocks([[] for _ in range(len(self.blocks))])


class KVCacheManager:

Expand Down