Skip to content
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

[V1][Core] Generic mechanism for handling engine utility methods #13060

Merged
merged 13 commits into from
Feb 19, 2025

Conversation

njhill
Copy link
Member

@njhill njhill commented Feb 10, 2025

We now have a number of utility / "control" operations that need to be called on the engine (add_lora, profile, sleep, wakeup, ...). It should be possible to call these in a synchronous manner to know when the operation is complete and whether it succeeded. Some operations in future may require results to be returned.

These changes centralize the mechanism for doing this in V1, and add the result-returning part.

We now have a number of utility / "control" operations that need to be called on the engine (add_lora, profile, sleep, wakeup, ...). It should be possible to call these in a synchronous manner to know when the operation is complete and whether it succeeded. Some operations in future may require results to be returned.

These changes centralize the mechanism for doing this in V1, and add the result-returning part.

Signed-off-by: Nick Hill <[email protected]>
@njhill njhill requested a review from youkaichao February 10, 2025 23:54
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.

🚀

Copy link

mergify bot commented Feb 12, 2025

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

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 12, 2025
Signed-off-by: Nick Hill <[email protected]>
Signed-off-by: Nick Hill <[email protected]>

# Conflicts:
#	vllm/v1/engine/__init__.py
#	vllm/v1/engine/async_llm.py
@njhill njhill marked this pull request as ready for review February 13, 2025 01:40
@mergify mergify bot removed the needs-rebase label Feb 13, 2025
Signed-off-by: Nick Hill <[email protected]>
@njhill njhill added the ready ONLY add when PR is ready to merge/full CI is needed label Feb 13, 2025
Copy link

mergify bot commented Feb 14, 2025

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

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 14, 2025
…ty-funcs

# Conflicts:
#	vllm/v1/engine/__init__.py
#	vllm/v1/engine/core.py
#	vllm/v1/engine/core_client.py
Signed-off-by: Nick Hill <[email protected]>
@mergify mergify bot removed the needs-rebase label Feb 14, 2025
Signed-off-by: Nick Hill <[email protected]>
@njhill
Copy link
Member Author

njhill commented Feb 15, 2025

@youkaichao this should be ready to go 🤞

@youkaichao
Copy link
Member

@robertgshaw2-redhat can you help review this? I'm not familiar with this part of the code, but I will need it in #12987 🥺

Copy link

mergify bot commented Feb 15, 2025

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

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 15, 2025
@mergify mergify bot removed the needs-rebase label Feb 17, 2025
Comment on lines +388 to +390
msgspec.convert(v, type=p.annotation) if isclass(p.annotation)
and issubclass(p.annotation, msgspec.Struct)
and not isinstance(v, p.annotation) else v
Copy link
Contributor

Choose a reason for hiding this comment

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

Aesthetically, a helper function might clean up this code, i.e.

return tuple(msgspec.convert(v, type=p.annotation)
                      if needs_conversion(v,p) else v
                      for v, p in zip(args, arg_types))

however this is the engine core, perhaps multiple helper-function calls would be too costly.

Comment on lines 248 to 266
# Ensure that the outputs socket processing thread does not have
# a ref to the client which prevents gc.
output_socket = self.output_socket
decoder = self.decoder
utility_results = self.utility_results
outputs_queue = self.outputs_queue

(frame, ) = self.output_socket.recv_multipart(copy=False)
return self.decoder.decode(frame.buffer)
def process_outputs_socket():
while True:
(frame, ) = output_socket.recv_multipart(copy=False)
outputs = decoder.decode(frame.buffer)
if outputs.utility_output:
_process_utility_output(outputs.utility_output,
utility_results)
else:
outputs_queue.put_nowait(outputs)

# Process outputs from engine in separate thread.
Thread(target=process_outputs_socket, daemon=True).start()
Copy link
Contributor

@afeldman-nm afeldman-nm Feb 18, 2025

Choose a reason for hiding this comment

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

Not a strong opinion, but this code to launch the engine output processing thread could go in a separate helper function.

@@ -236,6 +275,17 @@ def _send_input(self, request_type: EngineCoreRequestType,
msg = (request_type.value, self.encoder.encode(request))
self.input_socket.send_multipart(msg, copy=False)

def _call_utility(self, method: str, *args, unary: bool = False) -> Any:
call_id = uuid.uuid1().int >> 64
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you use call_id = uuid.uuid1().int >> 64 in at least two places, perhaps makes sense to have a new_call_id() helper function?

method: str,
*args,
unary: bool = False) -> Any:
call_id = uuid.uuid1().int >> 64
Copy link
Contributor

Choose a reason for hiding this comment

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

Second occurrence which could be replaced with a helper function.

Copy link
Contributor

@afeldman-nm afeldman-nm left a comment

Choose a reason for hiding this comment

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

Hi Nick, I left a little bit of feedback. Thanks for the PR!

@njhill
Copy link
Member Author

njhill commented Feb 18, 2025

Thanks for the great comments @afeldman-nm. I've addressed some of them. Re helper functions it's a bit subjective but I personally lean towards being more selective; the indirection can make the code less readable, especially when the logic itself is trivial.

Copy link
Member

@youkaichao youkaichao left a comment

Choose a reason for hiding this comment

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

thank for the great work!

@youkaichao youkaichao merged commit caf7ff4 into vllm-project:main Feb 19, 2025
47 checks passed
@njhill njhill deleted the v1-utility-funcs branch February 19, 2025 15:40
xjpang pushed a commit to xjpang/vllm that referenced this pull request Feb 20, 2025
kerthcet pushed a commit to kerthcet/vllm that referenced this pull request Feb 21, 2025
Akshat-Tripathi pushed a commit to krai/vllm that referenced this pull request Mar 3, 2025
lk-chen pushed a commit to lk-chen/vllm that referenced this pull request Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed v1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants