@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 875d6def90
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 05:30 UTC

Add backward compatibility for `GuidedDecodingParams` (#25422)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Harry Mellor committed Sep 23, 2025 at 17:07 UTC 875d6def90f737f5f39eb484a29a940b117a9c79
2 files changed +59 -1
tests/v1/entrypoints/llm/test_struct_output_generate.py
+23 -1
@@ -5,6 +5,7 @@
5 from __future__ import annotations
6
7 import json
8 +from dataclasses import fields
9 from enum import Enum
10 from typing import TYPE_CHECKING, Any
11
@@ -21,7 +22,8 @@ from vllm.entrypoints.llm import LLM
22 from vllm.outputs import RequestOutput
23 from vllm.platforms import current_platform
24 from vllm.reasoning.abs_reasoning_parsers import ReasoningParserManager
24 -from vllm.sampling_params import SamplingParams, StructuredOutputsParams
25 +from vllm.sampling_params import (GuidedDecodingParams, SamplingParams,
26 + StructuredOutputsParams)
27
28 if TYPE_CHECKING:
29 from vllm.config import TokenizerMode
@@ -89,6 +91,26 @@ def _load_json(s: str, backend: str) -> str:
91 return json.loads(s)
92
93
94 +def test_guided_decoding_deprecated():
95 + with pytest.warns(DeprecationWarning,
96 + match="GuidedDecodingParams is deprecated.*"):
97 + guided_decoding = GuidedDecodingParams(json_object=True)
98 +
99 + structured_outputs = StructuredOutputsParams(json_object=True)
100 + assert fields(guided_decoding) == fields(structured_outputs)
101 +
102 + with pytest.warns(DeprecationWarning,
103 + match="guided_decoding is deprecated.*"):
104 + sp1 = SamplingParams(guided_decoding=guided_decoding)
105 +
106 + with pytest.warns(DeprecationWarning,
107 + match="guided_decoding is deprecated.*"):
108 + sp2 = SamplingParams.from_optional(guided_decoding=guided_decoding)
109 +
110 + assert sp1 == sp2
111 + assert sp1.structured_outputs == guided_decoding
112 +
113 +
114 @pytest.mark.skip_global_cleanup
115 @pytest.mark.parametrize(
116 "model_name, backend, tokenizer_mode, speculative_config",
vllm/sampling_params.py
+36
@@ -2,6 +2,7 @@
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Sampling parameters for text generation."""
4 import copy
5 +import warnings
6 from dataclasses import field
7 from enum import Enum, IntEnum
8 from functools import cached_property
@@ -59,6 +60,19 @@ class StructuredOutputsParams:
60 f"but multiple are specified: {self.__dict__}")
61
62
63 +@dataclass
64 +class GuidedDecodingParams(StructuredOutputsParams):
65 +
66 + def __post_init__(self):
67 + warnings.warn(
68 + "GuidedDecodingParams is deprecated. This will be removed in "
69 + "v0.12.0 or v1.0.0, which ever is soonest. Please use "
70 + "StructuredOutputsParams instead.",
71 + DeprecationWarning,
72 + stacklevel=2)
73 + return super().__post_init__()
74 +
75 +
76 class RequestOutputKind(Enum):
77 # Return entire output so far in every RequestOutput
78 CUMULATIVE = 0
@@ -179,6 +193,8 @@ class SamplingParams(
193 # Fields used to construct logits processors
194 structured_outputs: Optional[StructuredOutputsParams] = None
195 """Parameters for configuring structured outputs."""
196 + guided_decoding: Optional[GuidedDecodingParams] = None
197 + """Deprecated alias for structured_outputs."""
198 logit_bias: Optional[dict[int, float]] = None
199 """If provided, the engine will construct a logits processor that applies
200 these logit biases."""
@@ -227,6 +243,7 @@ class SamplingParams(
243 ge=-1)]] = None,
244 output_kind: RequestOutputKind = RequestOutputKind.CUMULATIVE,
245 structured_outputs: Optional[StructuredOutputsParams] = None,
246 + guided_decoding: Optional[GuidedDecodingParams] = None,
247 logit_bias: Optional[Union[dict[int, float], dict[str, float]]] = None,
248 allowed_token_ids: Optional[list[int]] = None,
249 extra_args: Optional[dict[str, Any]] = None,
@@ -238,6 +255,15 @@ class SamplingParams(
255 int(token): min(100.0, max(-100.0, bias))
256 for token, bias in logit_bias.items()
257 }
258 + if guided_decoding is not None:
259 + warnings.warn(
260 + "guided_decoding is deprecated. This will be removed in "
261 + "v0.12.0 or v1.0.0, which ever is soonest. Please use "
262 + "structured_outputs instead.",
263 + DeprecationWarning,
264 + stacklevel=2)
265 + structured_outputs = guided_decoding
266 + guided_decoding = None
267
268 return SamplingParams(
269 n=1 if n is None else n,
@@ -334,6 +360,16 @@ class SamplingParams(
360 # eos_token_id is added to this by the engine
361 self._all_stop_token_ids.update(self.stop_token_ids)
362
363 + if self.guided_decoding is not None:
364 + warnings.warn(
365 + "guided_decoding is deprecated. This will be removed in "
366 + "v0.12.0 or v1.0.0, which ever is soonest. Please use "
367 + "structured_outputs instead.",
368 + DeprecationWarning,
369 + stacklevel=2)
370 + self.structured_outputs = self.guided_decoding
371 + self.guided_decoding = None
372 +
373 def _verify_args(self) -> None:
374 if not isinstance(self.n, int):
375 raise ValueError(f"n must be an int, but is of "