[V1][Frontend] Coalesce bunched RequestOutputs (#12298)

Signed-off-by: Nick Hill <nhill@redhat.com>
Co-authored-by: Robert Shaw <rshaw@neuralmagic.com>
This commit is contained in:
Nick Hill
2025-01-23 17:17:41 -08:00
committed by GitHub
co-authored by Robert Shaw
parent c5cffcd0cd
commit 24b0205f58
3 changed files with 65 additions and 18 deletions
+21 -1
View File
@@ -1,6 +1,6 @@
import time
from dataclasses import dataclass
from typing import Dict, Generic, List, Optional
from typing import Dict, Generic, List, MutableSequence, Optional
from typing import Sequence as GenericSequence
from typing import Union
@@ -162,6 +162,26 @@ class RequestOutput:
finished=finished,
)
def add(self, next_output: "RequestOutput") -> None:
"""Merge subsequent RequestOutput into this one"""
self.prompt = next_output.prompt
self.prompt_token_ids = next_output.prompt_token_ids
self.prompt_logprobs = next_output.prompt_logprobs
self.finished |= next_output.finished
#TODO assuming n == 1 for now
completion = self.outputs[0]
next_completion = next_output.outputs[0]
completion.text += next_completion.text
if not isinstance(completion.token_ids, MutableSequence):
completion.token_ids = list(completion.token_ids)
completion.token_ids.extend(next_completion.token_ids)
if next_completion.logprobs:
assert completion.logprobs is not None
completion.logprobs.extend(next_completion.logprobs)
completion.cumulative_logprob = next_completion.cumulative_logprob
@classmethod
def from_seq_group(
cls, seq_group: SequenceGroup, use_cache: bool,