@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / c84b519cf3
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 6, 21:45 UTC

[Bugfix] Fix negative max_tokens when input prompt is too long (#36789)

Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>

Isotr0py committed Mar 12, 2026 at 00:30 UTC c84b519cf314ad6568f0db6f762d82f356038309
2 files changed +19
tests/entrypoints/test_utils.py
+14
@@ -1,6 +1,8 @@
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 +import pytest
5 +
6 from vllm.entrypoints.utils import get_max_tokens, sanitize_message
7
8
@@ -80,3 +82,15 @@ class TestGetMaxTokens:
82 default_sampling_params={"max_tokens": 2048},
83 )
84 assert result == 512
85 +
86 + def test_input_length_exceeds_max_model_len(self):
87 + with pytest.raises(
88 + ValueError,
89 + match="Input length .* exceeds model's maximum context length .*",
90 + ):
91 + get_max_tokens(
92 + max_model_len=100,
93 + max_tokens=50,
94 + input_length=150,
95 + default_sampling_params={"max_tokens": 2048},
96 + )
vllm/entrypoints/utils.py
+5
@@ -178,6 +178,11 @@ def get_max_tokens(
178 default_sampling_params: dict,
179 override_max_tokens: int | None = None,
180 ) -> int:
181 + if max_model_len < input_length:
182 + raise ValueError(
183 + f"Input length ({input_length}) exceeds model's maximum "
184 + f"context length ({max_model_len})."
185 + )
186 model_max_tokens = max_model_len - input_length
187 platform_max_tokens = current_platform.get_max_output_tokens(input_length)
188 fallback_max_tokens = (