perf(cccl): thread_reduce fast-path — cap tool_call max_tokens to 2048

CCCL thread_reduce.cuh pattern: if(length==1) return directly.
For tool_call requests where user didn't set max_tokens, cap to 2048
to prevent NaN-damaged models from generating 99900 tokens of garbage.
Expected tool_call XML is <500 tokens. Sub509 spent 49s on d03 because
the model generated endlessly with no tool_call output.
This commit is contained in:
project6
2026-08-07 09:56:32 +00:00
parent 9870d07073
commit 7153029974

View File

@@ -303,6 +303,22 @@ class OpenAIServingChat(OpenAIServing):
sampling_params: Union[SamplingParams, BeamSearchParams]
default_max_tokens = self.max_model_len - len(
prompt_inputs["prompt_token_ids"])
# CCCL thread_reduce pattern: small request fast path.
# For tool_call requests, the expected output is just
# <tool_call><function=name><parameter=...>...</tool_call>
# which is typically <500 tokens. Capping default_max_tokens
# prevents the model from generating 99900 tokens of garbage
# when NaN-damaged weights produce non-terminating output.
# Only apply when user didn't explicitly set max_tokens.
if (_tool_call_active
and request.max_tokens is None
and default_max_tokens > 2048):
default_max_tokens = min(default_max_tokens, 2048)
logger.info(
"Tool call fast path: capping default_max_tokens to %d",
default_max_tokens)
if request.use_beam_search:
sampling_params = request.to_beam_search_params(
default_max_tokens)