Skip to content
2 changes: 2 additions & 0 deletions .buildkite/test-amd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/test_areas/misc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions tests/test_sampling_params.py
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tests/v1/sample/test_logprobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
23 changes: 23 additions & 0 deletions vllm/sampling_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ def verify(
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
)
Expand Down Expand Up @@ -878,6 +879,28 @@ def _validate_spec_decode(
"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,
Expand Down
Loading