[Bugfix] Reject sampling params unsupported by diffusion models (#45418)

Signed-off-by: Guan-Ming (Wesley) Chiu <[email protected]>
This commit is contained in:
Guan-Ming Chiu
2026-07-07 11:25:36 +00:00
committed by GitHub
parent 48fcfc926c
commit ed051fab54
5 changed files with 78 additions and 0 deletions
+2
View File
@@ -380,6 +380,7 @@ steps:
- tests/test_outputs.py
- tests/test_pooling_params.py
- tests/test_ray_env.py
- tests/test_sampling_params.py
- tests/multimodal
- tests/renderers
- tests/standalone_tests/lazy_imports.py
@@ -395,6 +396,7 @@ steps:
- pytest -v -s test_outputs.py
- pytest -v -s test_pooling_params.py
- pytest -v -s test_ray_env.py
- pytest -v -s test_sampling_params.py
- pytest -v -s -m 'cpu_test' multimodal
- pytest -v -s renderers
- pytest -v -s tokenizers_
+2
View File
@@ -351,6 +351,7 @@ steps:
- tests/test_outputs.py
- tests/test_pooling_params.py
- tests/test_ray_env.py
- tests/test_sampling_params.py
- tests/multimodal
- tests/renderers
- tests/standalone_tests/lazy_imports.py
@@ -368,6 +369,7 @@ steps:
- pytest -v -s test_outputs.py
- pytest -v -s test_pooling_params.py
- pytest -v -s test_ray_env.py
- pytest -v -s test_sampling_params.py
- pytest -v -s -m 'cpu_test' multimodal
- pytest -v -s renderers
- pytest -v -s reasoning
+50
View File
@@ -0,0 +1,50 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from dataclasses import dataclass
import pytest
from vllm import SamplingParams
@dataclass
class MockModelConfig:
is_diffusion: bool = False
max_logprobs: int = 20
logits_processors: list | None = None
def get_vocab_size(self) -> int:
return 1024
@pytest.mark.parametrize(
"kwargs",
[
{"temperature": 0.7},
{"temperature": 0.0},
{"min_p": 0.1},
{"seed": 42},
{"min_tokens": 5},
{"logit_bias": {0: 1.0}},
{"bad_words": ["foo"]},
{"allowed_token_ids": [0, 1]},
],
)
def test_diffusion_rejects_unsupported_params(kwargs: dict):
params = SamplingParams(**kwargs)
with pytest.raises(ValueError, match="not yet supported with diffusion"):
params.verify(MockModelConfig(is_diffusion=True), None, None, None)
def test_diffusion_accepts_default_params():
SamplingParams().verify(MockModelConfig(is_diffusion=True), None, None, None)
def test_diffusion_accepts_top_k_top_p():
params = SamplingParams(top_p=0.9, top_k=10)
params.verify(MockModelConfig(is_diffusion=True), None, None, None)
def test_non_diffusion_models_unaffected():
params = SamplingParams(temperature=0.7, top_k=10, seed=42)
params.verify(MockModelConfig(), None, None, None)
+1
View File
@@ -85,6 +85,7 @@ def _model_config(vocab_size: int = 10):
return SimpleNamespace(
max_logprobs=20,
logits_processors=None,
is_diffusion=False,
get_vocab_size=lambda: vocab_size,
)
+23
View File
@@ -745,6 +745,7 @@ class SamplingParams(
self._validate_logits_processors(model_config)
self._validate_allowed_token_ids(tokenizer)
self._validate_spec_decode(speculative_config)
self._validate_diffusion(model_config)
self._validate_structured_outputs(
model_config, structured_outputs_config, tokenizer
)
@@ -878,6 +879,28 @@ class SamplingParams(
"are not yet supported with speculative decoding."
)
def _validate_diffusion(self, model_config: ModelConfig) -> None:
if not model_config.is_diffusion:
return
# Diffusion models denoise a whole canvas per step with a fixed
# temperature schedule, so per-request sampling parameters are not
# supported. Penalties are ignored by the sampler with a warning.
if (
self.temperature != 1.0
or self.min_p > _SAMPLING_EPS
or self.seed is not None
or self.min_tokens > 0
or self.logit_bias
or self.bad_words
or self.allowed_token_ids
):
raise ValueError(
"The temperature, min_p, seed, min_tokens, logit_bias, "
"bad_words, and allowed_token_ids sampling parameters "
"are not yet supported with diffusion models."
)
def _validate_structured_outputs(
self,
model_config: ModelConfig,