main
py 57 lines 1.88 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import pytest
5
6 from vllm import SamplingParams
7 from vllm.entrypoints.offline_utils import OfflineInferenceMixin
8 from vllm.exceptions import VLLMValidationError
9 from vllm.lora.request import LoRARequest
10
11
12 @pytest.fixture
13 def mixin() -> OfflineInferenceMixin:
14 return object.__new__(OfflineInferenceMixin)
15
16
17 def test_rejects_mismatched_params(mixin: OfflineInferenceMixin):
18 with pytest.raises(VLLMValidationError) as exc_info:
19 mixin._params_to_seq([SamplingParams()], num_requests=2)
20
21 assert str(exc_info.value) == (
22 "The lengths of prompts (2) and params (1) must be the same."
23 )
24 assert exc_info.value.parameter is None
25 assert exc_info.value.value is None
26
27
28 def test_rejects_mismatched_lora_requests(mixin: OfflineInferenceMixin):
29 with pytest.raises(VLLMValidationError) as exc_info:
30 mixin._lora_request_to_seq([None], num_requests=2)
31
32 assert str(exc_info.value) == (
33 "The lengths of prompts (2) and lora_request (1) must be the same."
34 )
35 assert exc_info.value.parameter is None
36 assert exc_info.value.value is None
37
38
39 def test_rejects_mismatched_priority(mixin: OfflineInferenceMixin):
40 with pytest.raises(VLLMValidationError) as exc_info:
41 mixin._priority_to_seq([0], num_requests=2)
42
43 assert str(exc_info.value) == (
44 "The lengths of prompts (2) and priority (1) must be the same."
45 )
46 assert exc_info.value.parameter is None
47 assert exc_info.value.value is None
48
49
50 def test_matching_lengths_pass_through(mixin: OfflineInferenceMixin):
51 lora = LoRARequest("l", 1, "/tmp/l")
52
53 assert mixin._params_to_seq([SamplingParams()], num_requests=1) == [
54 SamplingParams()
55 ]
56 assert mixin._lora_request_to_seq([lora], num_requests=1) == [lora]
57 assert mixin._priority_to_seq([3], num_requests=1) == [3]