[fix] baseline7 fix git add qwen3_6_scripts/serving_chat.py!
This commit is contained in:
@@ -118,25 +118,19 @@ def _sequential_greedy_fanout_count(
|
||||
request: ChatCompletionRequest,
|
||||
max_num_seqs: int,
|
||||
) -> int:
|
||||
"""Return the supported fan-out width, or zero.
|
||||
|
||||
When max_num_seqs is too small to schedule n choices in a single
|
||||
batch, we sequentially issue n independent n=1 requests and merge
|
||||
the results. This works for any temperature and for both streaming
|
||||
and non-streaming modes — the only hard exclusions are beam search
|
||||
(which requires internal cross-sequence scoring) and best_of
|
||||
(which implies server-side ranking over >n candidates).
|
||||
"""
|
||||
"""Return the supported deterministic fan-out width, or zero."""
|
||||
n = request.n if request.n is not None else 1
|
||||
if n <= max_num_seqs:
|
||||
return 0 # vLLM can handle natively
|
||||
if n > 16:
|
||||
return 0 # sanity cap
|
||||
if request.use_beam_search:
|
||||
return 0 # beam search cannot be split
|
||||
if request.best_of is not None:
|
||||
return 0 # best_of needs cross-comparison
|
||||
return n
|
||||
if (
|
||||
max_num_seqs == 1
|
||||
and n == 2
|
||||
and request.temperature == 0
|
||||
and not request.stream
|
||||
and not request.use_beam_search
|
||||
and request.best_of is None
|
||||
and request.prompt_logprobs is None
|
||||
):
|
||||
return n
|
||||
return 0
|
||||
|
||||
|
||||
def _merge_sequential_chat_responses(
|
||||
@@ -290,9 +284,10 @@ class OpenAIServingChat(OpenAIServing):
|
||||
if self.engine_client.errored:
|
||||
raise self.engine_client.dead_error
|
||||
|
||||
# When max_num_seqs is too small for n choices, sequentially execute
|
||||
# n independent n=1 requests and merge. Works for any temperature,
|
||||
# stream or non-stream.
|
||||
# The fixed competition command uses max_num_seqs=1. Native vLLM
|
||||
# cannot schedule n=2 in that configuration and also rejects greedy
|
||||
# n>1. Two greedy choices are identical by definition, so execute two
|
||||
# isolated n=1 requests and merge only this exact deterministic shape.
|
||||
if request.n is not None and request.n > 1:
|
||||
scheduler_config = await self.engine_client.get_scheduler_config()
|
||||
max_num_seqs = scheduler_config.max_num_seqs
|
||||
@@ -300,17 +295,8 @@ class OpenAIServingChat(OpenAIServing):
|
||||
fanout_count = _sequential_greedy_fanout_count(
|
||||
request, max_num_seqs)
|
||||
if fanout_count:
|
||||
# Force non-streaming for child requests; if the original
|
||||
# request was streaming, wrap the merged result afterwards.
|
||||
was_stream = request.stream
|
||||
fanout_request = request.model_copy(
|
||||
deep=True, update={"stream": False})
|
||||
result = await self._create_sequential_greedy_fanout(
|
||||
fanout_request, raw_request, fanout_count)
|
||||
if was_stream and isinstance(
|
||||
result, ChatCompletionResponse):
|
||||
return self._fanout_to_stream(result)
|
||||
return result
|
||||
return await self._create_sequential_greedy_fanout(
|
||||
request, raw_request, fanout_count)
|
||||
return self.create_error_response(
|
||||
f"n={request.n} exceeds max_num_seqs={max_num_seqs}. "
|
||||
f"Use n<={max_num_seqs} or omit n.")
|
||||
@@ -535,39 +521,6 @@ class OpenAIServingChat(OpenAIServing):
|
||||
)
|
||||
return response
|
||||
|
||||
@staticmethod
|
||||
async def _fanout_to_stream(
|
||||
response: ChatCompletionResponse,
|
||||
) -> AsyncGenerator[str, None]:
|
||||
"""Wrap a complete ChatCompletionResponse as an SSE stream.
|
||||
|
||||
Used when n>1 fan-out was requested with stream=True. The child
|
||||
requests ran non-streaming; we emit one chunk per choice containing
|
||||
the full text, then a final [DONE].
|
||||
"""
|
||||
for choice in response.choices:
|
||||
delta = DeltaMessage(
|
||||
role="assistant",
|
||||
content=getattr(choice.message, "content", None),
|
||||
)
|
||||
chunk = ChatCompletionStreamResponse(
|
||||
id=response.id,
|
||||
created=response.created,
|
||||
model=response.model,
|
||||
choices=[
|
||||
ChatCompletionResponseStreamChoice(
|
||||
index=choice.index,
|
||||
delta=delta,
|
||||
finish_reason=choice.finish_reason,
|
||||
stop_reason=choice.stop_reason,
|
||||
)
|
||||
],
|
||||
usage=response.usage,
|
||||
)
|
||||
data = chunk.model_dump_json(exclude_unset=True)
|
||||
yield f"data: {data}\n\n"
|
||||
yield "data: [DONE]\n\n"
|
||||
|
||||
def get_chat_request_role(self, request: ChatCompletionRequest) -> str:
|
||||
if request.add_generation_prompt:
|
||||
return self.response_role
|
||||
@@ -1405,4 +1358,4 @@ class OpenAIServingChat(OpenAIServing):
|
||||
and delta_message.tool_calls and delta_message.tool_calls[0]
|
||||
and delta_message.tool_calls[0].function
|
||||
and delta_message.tool_calls[0].function.arguments is not None
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user