Skip to content

[KVConnector] Handle KV events from multiple connectors#31811

Closed
hickeyma wants to merge 9 commits intovllm-project:mainfrom
hickeyma:add-kv-events-multiconn
Closed

[KVConnector] Handle KV events from multiple connectors#31811
hickeyma wants to merge 9 commits intovllm-project:mainfrom
hickeyma:add-kv-events-multiconn

Conversation

@hickeyma
Copy link
Copy Markdown
Contributor

@hickeyma hickeyma commented Jan 6, 2026

Purpose

This is a follow on PR to #28309. It was raised by @NickLucche in #28309 (review) to request support for KV events for multiple connectors.

Test Plan

pytest tests/v1/kv_connector/unit/test_multi_connector.py -v

Test using vLLM and LMCache from CLI:

PYTHONHASHSEED=0 LMCACHE_CONFIG_FILE=lmcache_config.yaml vllm serve Qwen/Qwen3-14B --kv-transfer-config '{"kv_connector":"MultiConnector", "kv_role":"kv_both", "kv_connector_extra_config":{"connectors":[{ "kv_connector": "LMCacheConnectorV1", "kv_role": "kv_both" }, { "kv_connector": "ExampleConnector", "kv_role": "kv_both" }]}}' --disable-log-requests --no-enable-prefix-caching --kv-events-config '{"enable_kv_cache_events": "True", "publisher": "zmq", "topic": "kv-events"}' --tensor-parallel-size 2

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.

Note

Adds per-connector KV event handling and aggregation for MultiConnector and across workers.

  • Introduces MultiConnectorKVEvents to hold KV events keyed by connector type
  • Implements MultiConnector.get_kv_connector_kv_cache_events() to group events by connector; update_connector_output() now dispatches per-connector events downstream
  • Updates KVOutputAggregator to merge MultiConnectorKVEvents across workers while preserving per-connector boundaries
  • Adds comprehensive unit tests for event grouping/merging and edge cases in test_multi_connector.py

Written by Cursor Bugbot for commit b34f6a8a3760a496e0181ad4a5c399e4bf5ceb8a. This will update automatically on new commits. Configure here.


Note

Cursor Bugbot is generating a summary for commit 6041228d3729cc70f0c4d92534f26913729453e1. Configure here.


Note

Introduces per-connector KV cache event plumbing for multi-connector setups and aggregates events across workers while preserving connector boundaries.

  • New MultiConnectorKVEvents to hold per-connector KVConnectorKVEvents
  • MultiConnector.get_kv_connector_kv_cache_events() groups events by connector type; update_connector_output() dispatches per-connector events to each connector
  • KVOutputAggregator in kv_connector/utils.py merges MultiConnectorKVEvents across workers (including mixed single/multi cases)
  • Unit tests added in tests/v1/kv_connector/unit/test_multi_connector.py for event grouping, merging, and edge cases

Written by Cursor Bugbot for commit 6041228d3729cc70f0c4d92534f26913729453e1. This will update automatically on new commits. Configure here.


Note

Adds per-connector KV cache event plumbing to multi-connector setups and preserves connector boundaries during aggregation.

  • New MultiConnectorKVEvents container to hold per-connector KVConnectorKVEvents
  • MultiConnector.get_kv_connector_kv_cache_events() groups events by connector type; update_connector_output() dispatches per-connector events to each connector
  • KVOutputAggregator in kv_connector/utils.py merges MultiConnectorKVEvents across workers (also handles mixed single/multi cases)
  • Unit tests in test_multi_connector.py for event grouping, merging, and edge cases

Written by Cursor Bugbot for commit 43b8ec71f51294bc09afb37f73df1a6ab1b165ba. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
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 adds support for handling KV cache events from multiple connectors, which is a valuable enhancement. The implementation introduces MultiConnectorKVEvents and updates the aggregation logic accordingly. While the overall approach is sound, I've identified several areas for improvement. My review focuses on simplifying the new tests, which are currently overly complex, removing redundant code in the event aggregation logic, and addressing a potential performance bottleneck by replacing a deepcopy operation with a more efficient alternative. These changes will improve the code's readability, maintainability, and performance.

@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from 8e5aaf7 to a1f3883 Compare January 6, 2026 14:48
@mergify
Copy link
Copy Markdown

mergify bot commented Jan 6, 2026

Hi @hickeyma, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@hickeyma hickeyma marked this pull request as draft January 6, 2026 15:30
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from a1f3883 to 1041602 Compare January 7, 2026 11:41
@mergify
Copy link
Copy Markdown

mergify bot commented Jan 8, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @hickeyma.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Jan 8, 2026
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from 1041602 to 866588d Compare January 12, 2026 10:07
@mergify mergify bot removed the needs-rebase label Jan 12, 2026
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from 8fa9c0d to 00e3b50 Compare January 12, 2026 11:42
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from a426db6 to a87f816 Compare January 12, 2026 14:43
@hickeyma hickeyma marked this pull request as ready for review January 12, 2026 15:54
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from b34f6a8 to 6041228 Compare January 12, 2026 16:48
Copy link
Copy Markdown
Collaborator

@NickLucche NickLucche left a comment

Choose a reason for hiding this comment

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

Thanks for the followup @hickeyma .

It appears current impl is devaiating somewhat from my expected model (eg MultiKVConnectorStats). What's preventing us from implementing the abstract methods in MultiConnectorKVEvents and let the system program to that interface as it was no different from an LMCacheKVEvents instance?

@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from 43b8ec7 to 4a770fc Compare January 19, 2026 14:18
@mergify
Copy link
Copy Markdown

mergify bot commented Jan 19, 2026

Hi @hickeyma, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@hickeyma
Copy link
Copy Markdown
Contributor Author

It appears current impl is devaiating somewhat from my expected model (eg MultiKVConnectorStats). What's preventing us from implementing the abstract methods in MultiConnectorKVEvents and let the system program to that interface as it was no different from an LMCacheKVEvents instance?

This is to handle Multiple connectors (different types) that generate KV events. Each connector type may process thier events differently before making them available to scheduler for publishing and therefore the specific connector KVConnectorKVEvents implementation needs to be called. MultiConnectorKVEvents is essentially only a contaner to pass the events.

eicherseiji added a commit to eicherseiji/vllm that referenced this pull request Jan 30, 2026
Address PR feedback: the current merge logic doesn't properly group
events by connector. Remove the implementation and restore the TODO
comment pointing to PR vllm-project#31811 which implements this properly.

Signed-off-by: Seiji Eicher <seiji@anyscale.com>
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from 84f7c28 to 5b61971 Compare February 3, 2026 12:15
@hickeyma hickeyma requested a review from orozery as a code owner February 3, 2026 12:15
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 3, 2026
Co-authored with gemini-code-assist ion:

- vllm-project#31811 (comment)
- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 3, 2026
Co-authored with cursor:

- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 3, 2026
Review comments:
- vllm-project#31811 (review)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 3, 2026
…KVEvents

Add support for KV cache events in MultiConnector by implementing the
relevant KVConnectorKVEvents interface methods.
Changes:
- Add ConnectorKVCacheEvents class that wraps events per connector type,
extending KVCacheEvent for serialization compatibility
- Implement get_all_events() to return events grouped by connector as
a list of ConnectorKVCacheEvents
- Implement add_events() to dispatch incoming ConnectorKVCacheEvents
to their respective underlying connector event containers
- Implement increment_workers() as no-op since worker tracking is
delegated to individual connectors via add_events()
- Add get_connector_events() helper method

This allows KVOutputAggregator to handle MultiConnectorKVEvents using
the standard interface without adding special logic for multi-connectors,
simplifying the aggregation logic in utils.py.

Update following review comment:
- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 3, 2026
Comments:
- vllm-project#31811 (review)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
@hickeyma hickeyma requested a review from NickLucche February 3, 2026 14:47
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from 77ee8fc to dbe9fb1 Compare February 6, 2026 14:06
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 6, 2026
Co-authored with gemini-code-assist ion:

- vllm-project#31811 (comment)
- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 6, 2026
Co-authored with cursor:

- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 6, 2026
Review comments:
- vllm-project#31811 (review)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 6, 2026
…KVEvents

Add support for KV cache events in MultiConnector by implementing the
relevant KVConnectorKVEvents interface methods.
Changes:
- Add ConnectorKVCacheEvents class that wraps events per connector type,
extending KVCacheEvent for serialization compatibility
- Implement get_all_events() to return events grouped by connector as
a list of ConnectorKVCacheEvents
- Implement add_events() to dispatch incoming ConnectorKVCacheEvents
to their respective underlying connector event containers
- Implement increment_workers() as no-op since worker tracking is
delegated to individual connectors via add_events()
- Add get_connector_events() helper method

This allows KVOutputAggregator to handle MultiConnectorKVEvents using
the standard interface without adding special logic for multi-connectors,
simplifying the aggregation logic in utils.py.

Update following review comment:
- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
hickeyma added a commit to hickeyma/vllm that referenced this pull request Feb 6, 2026
Comments:
- vllm-project#31811 (review)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
@mergify
Copy link
Copy Markdown

mergify bot commented Feb 6, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @hickeyma.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Feb 6, 2026
This is a follow on PR to vllm-project#28309.
It was raised by @NickLucche in
vllm-project#28309 (review)
to provide support for KV events for multiple conectors.

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
The use of copy.deepcopy() on connector_output.kv_cache_events can lead to significant performance overhead,
especially if the number of events is large.

A better approach is to avoid modifying the connector_output object directly in the loop. Instead, create a temporary,
shallow copy of connector_output for each sub-connector, replacing kv_cache_events with the appropriate subset of events.
This can be done efficiently using dataclasses.replace. This avoids the expensive deep copy and makes the code's intent clearer.

Co-authored with gemini-code-assist

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Co-authored with gemini-code-assist ion:

- vllm-project#31811 (comment)
- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Rempve unnecessary patching from test functions.

Co-authored with gemini-code-assist

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Co-authored with cursor:

- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Review comments:
- vllm-project#31811 (review)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
…KVEvents

Add support for KV cache events in MultiConnector by implementing the
relevant KVConnectorKVEvents interface methods.
Changes:
- Add ConnectorKVCacheEvents class that wraps events per connector type,
extending KVCacheEvent for serialization compatibility
- Implement get_all_events() to return events grouped by connector as
a list of ConnectorKVCacheEvents
- Implement add_events() to dispatch incoming ConnectorKVCacheEvents
to their respective underlying connector event containers
- Implement increment_workers() as no-op since worker tracking is
delegated to individual connectors via add_events()
- Add get_connector_events() helper method

This allows KVOutputAggregator to handle MultiConnectorKVEvents using
the standard interface without adding special logic for multi-connectors,
simplifying the aggregation logic in utils.py.

Update following review comment:
- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Comments:
- vllm-project#31811 (review)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
@hickeyma hickeyma force-pushed the add-kv-events-multiconn branch from dbe9fb1 to 2193699 Compare February 9, 2026 10:26
@mergify mergify bot removed the needs-rebase label Feb 9, 2026
From code review comment:
- vllm-project#31811 (comment)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
@hickeyma
Copy link
Copy Markdown
Contributor Author

Superseded by #34522

@hickeyma hickeyma closed this Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants