[Perf] Optimize the performance of structured output + reasoning (#33557)
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
@@ -83,6 +83,8 @@ class EngineCoreRequest(
|
||||
# Used in outputs and to support abort(req_id, internal=False).
|
||||
external_req_id: str | None = None
|
||||
|
||||
reasoning_ended: bool | None = None
|
||||
|
||||
@property
|
||||
def params(self) -> SamplingParams | PoolingParams:
|
||||
"""Return the processed params (sampling or pooling)."""
|
||||
|
||||
@@ -74,6 +74,7 @@ class Request:
|
||||
trace_headers: Mapping[str, str] | None = None,
|
||||
block_hasher: Callable[["Request"], list["BlockHash"]] | None = None,
|
||||
resumable: bool = False,
|
||||
reasoning_ended: bool | None = None,
|
||||
) -> None:
|
||||
self.request_id = request_id
|
||||
self.client_index = client_index
|
||||
@@ -86,6 +87,8 @@ class Request:
|
||||
self.structured_output_request = StructuredOutputRequest.from_sampling_params(
|
||||
sampling_params
|
||||
)
|
||||
if self.structured_output_request is not None:
|
||||
self.structured_output_request.reasoning_ended = reasoning_ended
|
||||
self.arrival_time = arrival_time if arrival_time is not None else time.time()
|
||||
|
||||
self.status = RequestStatus.WAITING
|
||||
@@ -195,6 +198,7 @@ class Request:
|
||||
trace_headers=request.trace_headers,
|
||||
block_hasher=block_hasher,
|
||||
resumable=request.resumable,
|
||||
reasoning_ended=request.reasoning_ended,
|
||||
)
|
||||
|
||||
def append_output_token_ids(
|
||||
|
||||
@@ -284,12 +284,15 @@ class StructuredOutputManager:
|
||||
# NOTE (Hanchen) if enable_in_reasoning is True, it means that
|
||||
# the model needs to be constrained in reasoning. So we should always
|
||||
# enable the bitmask filling.
|
||||
|
||||
if self.reasoner is not None:
|
||||
if self.enable_in_reasoning:
|
||||
return True
|
||||
assert request.structured_output_request is not None
|
||||
if request.structured_output_request.reasoning_ended is None:
|
||||
# This should be removed here, but since `openai_gptoss`
|
||||
# is an independent code path, it is kept for now.
|
||||
# After unifying the `openai_gptoss` and non-`openai_gptoss` styles,
|
||||
# it can be removed.
|
||||
request.structured_output_request.reasoning_ended = (
|
||||
self.reasoner.is_reasoning_end(request.prompt_token_ids or [])
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user