Skip to content

[P/D] Update output of get_finished to newly defined class KVConnectorFinishOutput#21790

Closed
lk-chen wants to merge 20 commits intovllm-project:mainfrom
lk-chen:nixl_xfer_log
Closed

[P/D] Update output of get_finished to newly defined class KVConnectorFinishOutput#21790
lk-chen wants to merge 20 commits intovllm-project:mainfrom
lk-chen:nixl_xfer_log

Conversation

@lk-chen
Copy link
Collaborator

@lk-chen lk-chen commented Jul 28, 2025

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.

This PR is on top of #21785

Purpose

We need to pipe more information from kv_connector implementations to model_runner (e.g. finished_loading_dict in #21534 needed by #19329 , and metrics to be added in #21784 ). It's not sustainable to append ad-hoc fields along with existing ones everywhere (ModelRunnerOutput, IntermediateTensors etc.). This PR aggregates all these info into a new class.

Test Plan

CI unit tests

Test Result

(Optional) Documentation Update

lk-chen added 4 commits July 25, 2025 13:01
Signed-off-by: Linkun <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
@github-actions
Copy link

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

🚀

@mergify mergify bot added the v1 label Jul 28, 2025
@mergify
Copy link

mergify bot commented Jul 28, 2025

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

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

@mergify mergify bot added tpu Related to Google TPUs needs-rebase labels Jul 28, 2025
Copy link
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 introduces a new KVConnectorFinishOutput class to standardize the output from kv_connector implementations, which is a great step towards improving code clarity and maintainability. The removal of the V0 connector code is also a welcome cleanup.

I've found a few critical issues that need to be addressed. The __init__ method of the new KVConnectorFinishOutput class has an incorrect return type hint. Additionally, several connectors are not providing all the required arguments when instantiating this new class, which would lead to runtime errors. I've provided specific suggestions for these issues in the comments. Addressing these will ensure the refactoring is robust and correct.

finished_sending: set[str],
finished_recving: set[str],
finished_loading_num_tokens: dict[str, int],
) -> "KVConnectorBase_V1.KVConnectorFinishOutput":
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The __init__ method in Python should always return None. Specifying a return type hint other than None is incorrect and will cause a TypeError at runtime.

Suggested change
) -> "KVConnectorBase_V1.KVConnectorFinishOutput":
) -> None:

Comment on lines +104 to +108
finished_sending, finished_recving = self._lmcache_engine.get_finished(
finished_req_ids)
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=finished_sending,
finished_recving=finished_recving)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The KVConnectorFinishOutput constructor is missing the required keyword argument finished_loading_num_tokens. This will cause a TypeError at runtime.

        return KVConnectorBase_V1.KVConnectorFinishOutput(
            finished_sending=finished_sending,
            finished_recving=finished_recving,
            finished_loading_num_tokens={})

Comment on lines 111 to 113
finished_sending: set[str] = set()
finished_recving: set[str] = set()
for c in self._connectors:
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

With the change of the return type of get_finished to KVConnectorFinishOutput, the unpacking on line 114 (sending, recving = c.get_finished(finished_req_ids)) will raise a TypeError because get_finished no longer returns a tuple. You need to update the loop body to handle the new return type.

For example:

output = c.get_finished(finished_req_ids)
sending = output.finished_sending
recving = output.finished_recving

Comment on lines +141 to +143
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=finished_sending,
finished_recving=finished_recving)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The KVConnectorFinishOutput constructor is missing the required keyword argument finished_loading_num_tokens. This will cause a TypeError at runtime.

Suggested change
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=finished_sending,
finished_recving=finished_recving)
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=finished_sending,
finished_recving=finished_recving,
finished_loading_num_tokens={})

Comment on lines +1037 to +1038
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=done_sending, finished_recving=done_recving)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The KVConnectorFinishOutput constructor is missing the required keyword argument finished_loading_num_tokens. This will cause a TypeError at runtime.

Suggested change
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=done_sending, finished_recving=done_recving)
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=done_sending, finished_recving=done_recving, finished_loading_num_tokens={})

Comment on lines +273 to +278
finished_sending, finished_recving = self.p2p_nccl_engine.get_finished(
finished_req_ids, no_compile_layers)
return KVConnectorBase_V1.KVConnectorFinishOutput(
finished_sending=finished_sending or set(),
finished_recving=finished_recving or set(),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The KVConnectorFinishOutput constructor is missing the required keyword argument finished_loading_num_tokens. This will cause a TypeError at runtime.

        return KVConnectorBase_V1.KVConnectorFinishOutput(
            finished_sending=finished_sending or set(),
            finished_recving=finished_recving or set(),
            finished_loading_num_tokens={},
        )

Signed-off-by: Linkun Chen <github@lkchen.net>
@mergify mergify bot removed the needs-rebase label Jul 28, 2025
Signed-off-by: Linkun Chen <github@lkchen.net>
@lk-chen lk-chen added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 29, 2025
lk-chen added 3 commits July 29, 2025 10:18
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
@sdavidbd
Copy link
Contributor

Hi @lk-chen, I completely agree on the need to encapsulate KV connector output in a structured way. I introduced a similar concept in #19330 — see KVConnectorOutput.

In that PR, I didn’t yet propagate this class through ModelRunnerOutput or IntermediateTensors, as doing so would require broader refactoring that goes beyond the scope of the current change. There are also ongoing efforts to generalize and unify the structure of these fields, which are being discussed in #19330 and #19555. Would be great to align these directions going forward.

lk-chen added 4 commits July 29, 2025 13:05
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
lk-chen added 4 commits July 30, 2025 15:43
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
Signed-off-by: Linkun Chen <github@lkchen.net>
@mergify mergify bot added the ci/build label Jul 30, 2025
@mergify
Copy link

mergify bot commented Aug 5, 2025

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

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 Aug 5, 2025
@lk-chen
Copy link
Collaborator Author

lk-chen commented Aug 5, 2025

KVConnectorOutput introduced in #21980

@lk-chen lk-chen closed this Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build needs-rebase 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.

2 participants