ValueError
vllm.SamplingParams.__init__.ValueError
Stack trace
Traceback (most recent call last):
File "app.py", line 12, in <module>
params = SamplingParams(temperature=1.5)
File "/usr/local/lib/python3.10/site-packages/vllm/sampling_params.py", line 45, in __init__
raise ValueError(f"Invalid temperature {temperature}: must be between 0.0 and 1.0")
ValueError: Invalid temperature 1.5: must be between 0.0 and 1.0 Why it happens
vLLM's SamplingParams enforces that temperature values must be between 0.0 and 1.0 inclusive. Passing a value outside this range triggers a ValueError to prevent invalid sampling behavior during generation.
Detection
Validate temperature values before constructing SamplingParams or catch ValueError exceptions to log invalid parameter usage and prevent runtime crashes.
Causes & fixes
Temperature parameter passed to SamplingParams is greater than 1.0 or less than 0.0
Ensure the temperature argument is a float within the inclusive range 0.0 to 1.0 before passing it to SamplingParams.
Temperature value is mistakenly set as an integer or string outside valid range
Convert temperature to float and validate its range before creating SamplingParams, rejecting or correcting invalid inputs.
Using default or legacy code that assumes temperature can be >1.0 for more randomness
Update code to comply with vLLM's current API constraints where temperature must be between 0.0 and 1.0.
Code: broken vs fixed
from vllm import LLM, SamplingParams
params = SamplingParams(temperature=1.5) # Invalid temperature, triggers ValueError
llm = LLM()
response = llm.generate("Hello", sampling_params=params)
print(response) import os
from vllm import LLM, SamplingParams
# Fixed: temperature set within valid range [0.0, 1.0]
temperature_value = 0.7
params = SamplingParams(temperature=temperature_value)
llm = LLM()
response = llm.generate("Hello", sampling_params=params)
print(response) # Works without error Workaround
Wrap SamplingParams creation in try/except ValueError, and fallback to a default valid temperature like 0.7 if an invalid value is detected.
Prevention
Implement input validation for all SamplingParams arguments before instantiation, and use type hints or config schemas to enforce valid ranges automatically.