High severity beginner · Fix: 2-5 min

ValueError

vllm.SamplingParams.__init__.ValueError

What this error means
The vLLM SamplingParams constructor received an invalid temperature value outside the allowed range [0.0, 1.0].

Stack trace

traceback
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
QUICK FIX
Set temperature to a float value between 0.0 and 1.0 when creating SamplingParams to avoid the ValueError.

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

1

Temperature parameter passed to SamplingParams is greater than 1.0 or less than 0.0

✓ Fix

Ensure the temperature argument is a float within the inclusive range 0.0 to 1.0 before passing it to SamplingParams.

2

Temperature value is mistakenly set as an integer or string outside valid range

✓ Fix

Convert temperature to float and validate its range before creating SamplingParams, rejecting or correcting invalid inputs.

3

Using default or legacy code that assumes temperature can be >1.0 for more randomness

✓ Fix

Update code to comply with vLLM's current API constraints where temperature must be between 0.0 and 1.0.

Code: broken vs fixed

Broken - triggers the error
python
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)
Fixed - works correctly
python
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
Corrected the temperature parameter to a valid float within the allowed range, preventing the ValueError during SamplingParams initialization.

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.

Python 3.9+ · vllm >=0.1.0 · tested on 0.3.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.