From b7c69280a462d8706795f7e3308bb6e06006b464 Mon Sep 17 00:00:00 2001 From: Harry Mellor <19981378+hmellor@users.noreply.github.com> Date: Mon, 22 Sep 2025 23:48:32 +0200 Subject: [PATCH 1/2] Add backward compatibility for `GuidedDecodingParams` Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> --- vllm/sampling_params.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vllm/sampling_params.py b/vllm/sampling_params.py index efe70d019ccc..35e82a5b9b52 100644 --- a/vllm/sampling_params.py +++ b/vllm/sampling_params.py @@ -59,6 +59,17 @@ def __post_init__(self): f"but multiple are specified: {self.__dict__}") +@dataclass +class GuidedDecodingParams(StructuredOutputsParams): + + def __post_init__(self): + logger.warning( + "GuidedDecodingParams is deprecated. This will be removed in " + "v0.12.0 or v1.0.0, which ever is soonest. Please use " + "StructuredOutputsParams instead.") + return super().__post_init__() + + class RequestOutputKind(Enum): # Return entire output so far in every RequestOutput CUMULATIVE = 0 @@ -179,6 +190,8 @@ class SamplingParams( # Fields used to construct logits processors structured_outputs: Optional[StructuredOutputsParams] = None """Parameters for configuring structured outputs.""" + guided_decoding: Optional[GuidedDecodingParams] = None + """Deprecated alias for structured_outputs.""" logit_bias: Optional[dict[int, float]] = None """If provided, the engine will construct a logits processor that applies these logit biases.""" @@ -227,6 +240,7 @@ def from_optional( ge=-1)]] = None, output_kind: RequestOutputKind = RequestOutputKind.CUMULATIVE, structured_outputs: Optional[StructuredOutputsParams] = None, + guided_decoding: Optional[GuidedDecodingParams] = None, logit_bias: Optional[Union[dict[int, float], dict[str, float]]] = None, allowed_token_ids: Optional[list[int]] = None, extra_args: Optional[dict[str, Any]] = None, @@ -238,6 +252,13 @@ def from_optional( int(token): min(100.0, max(-100.0, bias)) for token, bias in logit_bias.items() } + if guided_decoding is not None: + logger.warning( + "GuidedDecodingParams is deprecated. This will be removed in " + "v0.12.0 or v1.0.0, which ever is soonest. Please use " + "StructuredOutputsParams instead.") + structured_outputs = guided_decoding + guided_decoding = None return SamplingParams( n=1 if n is None else n, @@ -334,6 +355,14 @@ def __post_init__(self) -> None: # eos_token_id is added to this by the engine self._all_stop_token_ids.update(self.stop_token_ids) + if self.guided_decoding is not None: + logger.warning( + "GuidedDecodingParams is deprecated. This will be removed in " + "v0.12.0 or v1.0.0, which ever is soonest. Please use " + "StructuredOutputsParams instead.") + self.structured_outputs = self.guided_decoding + self.guided_decoding = None + def _verify_args(self) -> None: if not isinstance(self.n, int): raise ValueError(f"n must be an int, but is of " From ed53a5ae76c4012899cf193e3481cb851d90833e Mon Sep 17 00:00:00 2001 From: Harry Mellor <19981378+hmellor@users.noreply.github.com> Date: Tue, 23 Sep 2025 00:12:31 +0200 Subject: [PATCH 2/2] Add test Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> --- .../llm/test_struct_output_generate.py | 24 ++++++++++++++++++- vllm/sampling_params.py | 23 +++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/tests/v1/entrypoints/llm/test_struct_output_generate.py b/tests/v1/entrypoints/llm/test_struct_output_generate.py index 4b0f3b2d9967..e2c686928cea 100644 --- a/tests/v1/entrypoints/llm/test_struct_output_generate.py +++ b/tests/v1/entrypoints/llm/test_struct_output_generate.py @@ -5,6 +5,7 @@ from __future__ import annotations import json +from dataclasses import fields from enum import Enum from typing import TYPE_CHECKING, Any @@ -21,7 +22,8 @@ from vllm.outputs import RequestOutput from vllm.platforms import current_platform from vllm.reasoning.abs_reasoning_parsers import ReasoningParserManager -from vllm.sampling_params import SamplingParams, StructuredOutputsParams +from vllm.sampling_params import (GuidedDecodingParams, SamplingParams, + StructuredOutputsParams) if TYPE_CHECKING: from vllm.config import TokenizerMode @@ -89,6 +91,26 @@ def _load_json(s: str, backend: str) -> str: return json.loads(s) +def test_guided_decoding_deprecated(): + with pytest.warns(DeprecationWarning, + match="GuidedDecodingParams is deprecated.*"): + guided_decoding = GuidedDecodingParams(json_object=True) + + structured_outputs = StructuredOutputsParams(json_object=True) + assert fields(guided_decoding) == fields(structured_outputs) + + with pytest.warns(DeprecationWarning, + match="guided_decoding is deprecated.*"): + sp1 = SamplingParams(guided_decoding=guided_decoding) + + with pytest.warns(DeprecationWarning, + match="guided_decoding is deprecated.*"): + sp2 = SamplingParams.from_optional(guided_decoding=guided_decoding) + + assert sp1 == sp2 + assert sp1.structured_outputs == guided_decoding + + @pytest.mark.skip_global_cleanup @pytest.mark.parametrize( "model_name, backend, tokenizer_mode, speculative_config", diff --git a/vllm/sampling_params.py b/vllm/sampling_params.py index 35e82a5b9b52..f424682f9dfa 100644 --- a/vllm/sampling_params.py +++ b/vllm/sampling_params.py @@ -2,6 +2,7 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Sampling parameters for text generation.""" import copy +import warnings from dataclasses import field from enum import Enum, IntEnum from functools import cached_property @@ -63,10 +64,12 @@ def __post_init__(self): class GuidedDecodingParams(StructuredOutputsParams): def __post_init__(self): - logger.warning( + warnings.warn( "GuidedDecodingParams is deprecated. This will be removed in " "v0.12.0 or v1.0.0, which ever is soonest. Please use " - "StructuredOutputsParams instead.") + "StructuredOutputsParams instead.", + DeprecationWarning, + stacklevel=2) return super().__post_init__() @@ -253,10 +256,12 @@ def from_optional( for token, bias in logit_bias.items() } if guided_decoding is not None: - logger.warning( - "GuidedDecodingParams is deprecated. This will be removed in " + warnings.warn( + "guided_decoding is deprecated. This will be removed in " "v0.12.0 or v1.0.0, which ever is soonest. Please use " - "StructuredOutputsParams instead.") + "structured_outputs instead.", + DeprecationWarning, + stacklevel=2) structured_outputs = guided_decoding guided_decoding = None @@ -356,10 +361,12 @@ def __post_init__(self) -> None: self._all_stop_token_ids.update(self.stop_token_ids) if self.guided_decoding is not None: - logger.warning( - "GuidedDecodingParams is deprecated. This will be removed in " + warnings.warn( + "guided_decoding is deprecated. This will be removed in " "v0.12.0 or v1.0.0, which ever is soonest. Please use " - "StructuredOutputsParams instead.") + "structured_outputs instead.", + DeprecationWarning, + stacklevel=2) self.structured_outputs = self.guided_decoding self.guided_decoding = None