-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
[V1][Perf] Simpler request output queues #15156
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
Changes from all commits
e852802
8fe1e45
47e611d
af4e13b
7382f62
12b2758
639386c
4612dc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,46 @@ | |
| RequestStateStats) | ||
|
|
||
|
|
||
| class RequestOutputCollector: | ||
| """ | ||
| Collects streamed RequestOutputs per individual request, | ||
| for hand-off to the consuming asyncio generate task. | ||
|
|
||
| When streaming deltas, RequestOutputs are merged if the | ||
| producer gets ahead of the consumer. | ||
| """ | ||
|
|
||
| def __init__(self, output_kind: RequestOutputKind): | ||
| self.aggregate = output_kind == RequestOutputKind.DELTA | ||
| self.output: Optional[RequestOutput] = None | ||
| self.ready = asyncio.Event() | ||
|
|
||
| def put(self, output: RequestOutput) -> None: | ||
| if self.output is None: | ||
| self.output = output | ||
| self.ready.set() | ||
| elif self.aggregate: | ||
| # Coalesce the outputs in delta case. | ||
| self.output.add(output) | ||
| else: | ||
| # Just replace latest in non-delta case. | ||
| self.output = output | ||
|
|
||
| async def get(self) -> RequestOutput: | ||
|
Collaborator
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. Do you think we should have an invariant that
Member
Author
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. That is the case but I'm not sure what you're suggesting to add here? |
||
| while (output := self.output) is None: | ||
| await self.ready.wait() | ||
| self.output = None | ||
| self.ready.clear() | ||
| return output | ||
|
|
||
| def get_nowait(self) -> Optional[RequestOutput]: | ||
| output = self.output | ||
| if output is not None: | ||
| self.output = None | ||
| self.ready.clear() | ||
| return output | ||
|
|
||
|
|
||
| @dataclass | ||
| class OutputProcessorOutput: | ||
|
|
||
|
|
@@ -39,7 +79,7 @@ def __init__( | |
| detokenizer: IncrementalDetokenizer, | ||
| max_tokens_param: Optional[int], | ||
| arrival_time: float, | ||
| queue: Optional[asyncio.Queue[RequestOutput]], | ||
| queue: Optional[RequestOutputCollector], | ||
| log_stats: bool, | ||
| ): | ||
| self.request_id = request_id | ||
|
|
@@ -66,7 +106,7 @@ def from_new_request( | |
| request: EngineCoreRequest, | ||
| parent_req: Optional[ParentRequest], | ||
| request_index: int, | ||
| queue: Optional[asyncio.Queue[RequestOutput]], | ||
| queue: Optional[RequestOutputCollector], | ||
| log_stats: bool, | ||
| ) -> "RequestState": | ||
| if not request.sampling_params.detokenize: | ||
|
|
@@ -217,7 +257,7 @@ def add_request( | |
| request: EngineCoreRequest, | ||
| parent_req: Optional[ParentRequest] = None, | ||
| request_index: int = 0, | ||
| queue: Optional[asyncio.Queue[RequestOutput]] = None, | ||
| queue: Optional[RequestOutputCollector] = None, | ||
| ) -> None: | ||
| request_id = request.request_id | ||
| if request_id in self.request_states: | ||
|
|
@@ -300,7 +340,7 @@ def process_outputs( | |
| new_token_ids, finish_reason, stop_reason): | ||
| if req_state.queue is not None: | ||
| # AsyncLLM: put into queue for handling by generate(). | ||
| req_state.queue.put_nowait(request_output) | ||
| req_state.queue.put(request_output) | ||
| else: | ||
| # LLMEngine: return list of RequestOutputs. | ||
| request_outputs.append(request_output) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.