-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
[V1][Core] Generic mechanism for handling engine utility methods #13060
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9b99de3
[V1][Core] Generic mechanism for handling engine utility methods
njhill d018da2
add tests and fixes
njhill f59db2e
Merge remote-tracking branch 'origin/main' into v1-utility-funcs
njhill 3bba546
fix GC issue
njhill fe6f1a3
Merge remote-tracking branch 'origin/main' into v1-utility-funcs
njhill 370a880
fixes
njhill 81c9cca
Merge remote-tracking branch 'origin/main' into v1-utility-funcs
njhill 8fef5a4
Merge remote-tracking branch 'refs/remotes/origin/main' into v1-utili…
njhill bb5a3f5
more fixes
njhill cf33034
clean up comment
njhill e1180a2
Merge remote-tracking branch 'origin/main' into v1-utility-funcs
njhill 8b0dbe9
Address @afeldman-nm's comments
njhill ebd8d0c
Merge remote-tracking branch 'origin/main' into v1-utility-funcs
njhill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,11 @@ | |
| import threading | ||
| import time | ||
| from concurrent.futures import Future | ||
| from inspect import isclass, signature | ||
| from multiprocessing.connection import Connection | ||
| from typing import Any, List, Optional, Tuple, Type | ||
|
|
||
| import msgspec | ||
| import psutil | ||
| import zmq | ||
| import zmq.asyncio | ||
|
|
@@ -21,7 +23,7 @@ | |
| from vllm.v1.core.kv_cache_utils import get_kv_cache_configs | ||
| from vllm.v1.core.scheduler import Scheduler, SchedulerOutput | ||
| from vllm.v1.engine import (EngineCoreOutputs, EngineCoreRequest, | ||
| EngineCoreRequestType) | ||
| EngineCoreRequestType, UtilityOutput) | ||
| from vllm.v1.engine.mm_input_cache import MMInputCacheServer | ||
| from vllm.v1.executor.abstract import Executor | ||
| from vllm.v1.outputs import ModelRunnerOutput | ||
|
|
@@ -330,19 +332,39 @@ def _handle_client_request(self, request_type: EngineCoreRequestType, | |
| self.add_request(request) | ||
| elif request_type == EngineCoreRequestType.ABORT: | ||
| self.abort_requests(request) | ||
| elif request_type == EngineCoreRequestType.RESET_PREFIX_CACHE: | ||
| self.reset_prefix_cache() | ||
| elif request_type == EngineCoreRequestType.PROFILE: | ||
| self.model_executor.profile(request) | ||
| elif request_type == EngineCoreRequestType.ADD_LORA: | ||
| self.model_executor.add_lora(request) | ||
| elif request_type == EngineCoreRequestType.UTILITY: | ||
| call_id, method_name, args = request | ||
| output = UtilityOutput(call_id) | ||
| try: | ||
| method = getattr(self, method_name) | ||
| output.result = method( | ||
| *self._convert_msgspec_args(method, args)) | ||
| except BaseException as e: | ||
| logger.exception("Invocation of %s method failed", method_name) | ||
| output.failure_message = (f"Call to {method_name} method" | ||
| f" failed: {str(e)}") | ||
| self.output_queue.put_nowait( | ||
| EngineCoreOutputs(utility_output=output)) | ||
|
|
||
| @staticmethod | ||
| def _convert_msgspec_args(method, args): | ||
| """If a provided arg type doesn't match corresponding target method | ||
| arg type, try converting to msgspec object.""" | ||
| if not args: | ||
| return args | ||
| arg_types = signature(method).parameters.values() | ||
| assert len(args) <= len(arg_types) | ||
| return tuple( | ||
| msgspec.convert(v, type=p.annotation) if isclass(p.annotation) | ||
| and issubclass(p.annotation, msgspec.Struct) | ||
| and not isinstance(v, p.annotation) else v | ||
|
Comment on lines
+358
to
+360
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aesthetically, a helper function might clean up this code, i.e. however this is the engine core, perhaps multiple helper-function calls would be too costly. |
||
| for v, p in zip(args, arg_types)) | ||
|
|
||
| def process_input_socket(self, input_path: str): | ||
| """Input socket IO thread.""" | ||
|
|
||
| # Msgpack serialization decoding. | ||
| add_request_decoder = MsgpackDecoder(EngineCoreRequest) | ||
| add_lora_decoder = MsgpackDecoder(LoRARequest) | ||
| generic_decoder = MsgpackDecoder() | ||
|
|
||
| with zmq_socket_ctx(input_path, zmq.constants.PULL) as socket: | ||
|
|
@@ -352,14 +374,9 @@ def process_input_socket(self, input_path: str): | |
| request_type = EngineCoreRequestType(bytes(type_frame.buffer)) | ||
|
|
||
| # Deserialize the request data. | ||
| decoder = None | ||
| if request_type == EngineCoreRequestType.ADD: | ||
| decoder = add_request_decoder | ||
| elif request_type == EngineCoreRequestType.ADD_LORA: | ||
| decoder = add_lora_decoder | ||
| else: | ||
| decoder = generic_decoder | ||
|
|
||
| decoder = add_request_decoder if ( | ||
| request_type | ||
| == EngineCoreRequestType.ADD) else generic_decoder | ||
| request = decoder.decode(data_frame.buffer) | ||
|
|
||
| # Push to input queue for core busy loop. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.