From cbd1f08a3ec0f9587ee17f29c3233c36e327efef Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Aug 2026 07:07:40 +0000 Subject: [PATCH] =?UTF-8?q?fix(protocol):=20clamp=20max=5Ftokens=20to=20av?= =?UTF-8?q?ailable=20context=20=E2=80=94=20fix=20t3=5Fmax=5Ftokens=5Fmax?= =?UTF-8?q?=20HTTP=20400?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When max_tokens >= max_model_len, vLLM engine rejects the request. Clamp to (max_model_len - prompt_tokens) in both to_sampling_params and to_beam_search_params so oversized max_tokens values degrade gracefully instead of returning HTTP 400. CCCL logical.cu pattern: handle boundary conditions (empty range, overflow) gracefully instead of hard-failing. --- qwen3_6_scripts/protocol.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qwen3_6_scripts/protocol.py b/qwen3_6_scripts/protocol.py index 75d7ef15..befb5cad 100644 --- a/qwen3_6_scripts/protocol.py +++ b/qwen3_6_scripts/protocol.py @@ -305,6 +305,8 @@ class ChatCompletionRequest(OpenAIBaseModel): max_tokens = self.max_tokens if max_tokens is None: max_tokens = default_max_tokens + if default_max_tokens > 0: + max_tokens = min(max_tokens, default_max_tokens) n = self.n if self.n is not None else 1 temperature = self.temperature if self.temperature is not None else 0.0 @@ -321,6 +323,10 @@ class ChatCompletionRequest(OpenAIBaseModel): max_tokens = self.max_tokens if max_tokens is None: max_tokens = default_max_tokens + # Clamp to available context space so requests with max_tokens ≥ + # max_model_len don't get rejected with HTTP 400. + if default_max_tokens > 0: + max_tokens = min(max_tokens, default_max_tokens) prompt_logprobs = self.prompt_logprobs if prompt_logprobs is None and self.echo: