[Misc] Use VLLMValidationError in offline inference input validation (#53432)

Signed-off-by: Jensen Chen <a1043904820@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jensen Chen
2026-08-23 08:43:51 -07:00
committed by GitHub
co-authored by Claude Opus 5
parent b26039b09f
commit 39eba6ac36
4 changed files with 67 additions and 7 deletions
+4 -3
View File
@@ -6,6 +6,7 @@ import weakref
import pytest
from vllm import LLM, SamplingParams
from vllm.exceptions import VLLMValidationError
MODEL_NAME = "distilbert/distilgpt2"
@@ -52,7 +53,7 @@ def test_multiple_sampling_params(llm: LLM):
assert len(PROMPTS) == len(outputs)
# Exception raised, if the size of params does not match the size of prompts
with pytest.raises(ValueError):
with pytest.raises(VLLMValidationError):
outputs = llm.generate(PROMPTS, sampling_params=sampling_params[:3])
# Single SamplingParams should be applied to every prompt
@@ -75,13 +76,13 @@ def test_multiple_priority(llm: LLM):
assert len(PROMPTS) == len(outputs)
# Exception raised, if the length of priority does not match the length of prompts
with pytest.raises(ValueError):
with pytest.raises(VLLMValidationError):
outputs = llm.generate(
PROMPTS, sampling_params=None, priority=[0] * (len(PROMPTS) - 1)
)
# Exception raised, if the priority list is empty
with pytest.raises(ValueError):
with pytest.raises(VLLMValidationError):
outputs = llm.generate(PROMPTS, sampling_params=None, priority=[])
+57
View File
@@ -0,0 +1,57 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
from vllm import SamplingParams
from vllm.entrypoints.offline_utils import OfflineInferenceMixin
from vllm.exceptions import VLLMValidationError
from vllm.lora.request import LoRARequest
@pytest.fixture
def mixin() -> OfflineInferenceMixin:
return object.__new__(OfflineInferenceMixin)
def test_rejects_mismatched_params(mixin: OfflineInferenceMixin):
with pytest.raises(VLLMValidationError) as exc_info:
mixin._params_to_seq([SamplingParams()], num_requests=2)
assert str(exc_info.value) == (
"The lengths of prompts (2) and params (1) must be the same."
)
assert exc_info.value.parameter is None
assert exc_info.value.value is None
def test_rejects_mismatched_lora_requests(mixin: OfflineInferenceMixin):
with pytest.raises(VLLMValidationError) as exc_info:
mixin._lora_request_to_seq([None], num_requests=2)
assert str(exc_info.value) == (
"The lengths of prompts (2) and lora_request (1) must be the same."
)
assert exc_info.value.parameter is None
assert exc_info.value.value is None
def test_rejects_mismatched_priority(mixin: OfflineInferenceMixin):
with pytest.raises(VLLMValidationError) as exc_info:
mixin._priority_to_seq([0], num_requests=2)
assert str(exc_info.value) == (
"The lengths of prompts (2) and priority (1) must be the same."
)
assert exc_info.value.parameter is None
assert exc_info.value.value is None
def test_matching_lengths_pass_through(mixin: OfflineInferenceMixin):
lora = LoRARequest("l", 1, "/tmp/l")
assert mixin._params_to_seq([SamplingParams()], num_requests=1) == [
SamplingParams()
]
assert mixin._lora_request_to_seq([lora], num_requests=1) == [lora]
assert mixin._priority_to_seq([3], num_requests=1) == [3]