main
py 51 lines 1.75 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Tests that non-finite float values (NaN, Inf) are rejected by
4 SamplingParams validation, preventing them from propagating to GPU kernels.
5
6 Addresses advisory GHSA-7h4p-rffg-7823.
7 """
8
9 import math
10
11 import pytest
12
13 from vllm import SamplingParams
14 from vllm.exceptions import VLLMValidationError
15
16
17 class TestNonFiniteTemperature:
18 """Verify that NaN and Infinity temperature values are rejected."""
19
20 @pytest.mark.parametrize(
21 "value",
22 [float("nan"), float("inf"), float("-inf"), math.nan, math.inf],
23 ids=["nan", "inf", "-inf", "math.nan", "math.inf"],
24 )
25 def test_non_finite_temperature_rejected(self, value: float):
26 with pytest.raises(VLLMValidationError, match="temperature"):
27 SamplingParams(temperature=value)
28
29 def test_finite_temperature_accepted(self):
30 SamplingParams(temperature=0.0)
31 SamplingParams(temperature=0.5)
32 SamplingParams(temperature=1.0)
33 SamplingParams(temperature=2.0)
34
35
36 class TestNonFiniteRepetitionPenalty:
37 """Verify that NaN and Infinity repetition_penalty values are rejected."""
38
39 @pytest.mark.parametrize(
40 "value",
41 [float("nan"), float("inf"), float("-inf"), math.nan, math.inf],
42 ids=["nan", "inf", "-inf", "math.nan", "math.inf"],
43 )
44 def test_non_finite_repetition_penalty_rejected(self, value: float):
45 with pytest.raises(VLLMValidationError, match="repetition_penalty"):
46 SamplingParams(repetition_penalty=value)
47
48 def test_finite_repetition_penalty_accepted(self):
49 SamplingParams(repetition_penalty=0.5)
50 SamplingParams(repetition_penalty=1.0)
51 SamplingParams(repetition_penalty=2.0)