@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 8ed039d527
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

Move `StructuredOutputsConfig` from `config/__init__.py` to `config/structured_outputs.py` (#25153)

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

Harry Mellor committed Sep 18, 2025 at 12:24 UTC 8ed039d52775aaee4a61663dd5d8c840f5eebd15
2 files changed +65 -60
vllm/config/__init__.py
+1 -60
@@ -42,6 +42,7 @@ from vllm.config.parallel import (DistributedExecutorBackend, EPLBConfig,
42 ParallelConfig)
43 from vllm.config.scheduler import SchedulerConfig, SchedulerPolicy
44 from vllm.config.speculative import SpeculativeConfig
45 +from vllm.config.structured_outputs import StructuredOutputsConfig
46 from vllm.config.utils import ConfigType, config
47 from vllm.logger import init_logger
48 from vllm.model_executor.layers.quantization import QuantizationMethods
@@ -2277,66 +2278,6 @@ def get_served_model_name(model: str,
2278 return served_model_name
2279
2280
2280 -StructuredOutputsBackend = Literal["auto", "xgrammar", "guidance", "outlines",
2281 - "lm-format-enforcer"]
2282 -
2283 -
2284 -@config
2285 -@dataclass
2286 -class StructuredOutputsConfig:
2287 - """Dataclass which contains structured outputs config for the engine."""
2288 -
2289 - backend: StructuredOutputsBackend = "auto"
2290 - """Which engine will be used for structured outputs (e.g. JSON schema,
2291 - regex, etc) by default. With "auto", we will make opinionated choices
2292 - based on request contents and what the backend libraries currently support,
2293 - so the behavior is subject to change in each release."""
2294 -
2295 - disable_fallback: bool = False
2296 - """If `True`, vLLM will not fallback to a different backend on error."""
2297 -
2298 - disable_any_whitespace: bool = False
2299 - """If `True`, the model will not generate any whitespace during structured
2300 - outputs. This is only supported for xgrammar and guidance backends."""
2301 -
2302 - disable_additional_properties: bool = False
2303 - """If `True`, the `guidance` backend will not use `additionalProperties`
2304 - in the JSON schema. This is only supported for the `guidance` backend and
2305 - is used to better align its behaviour with `outlines` and `xgrammar`."""
2306 -
2307 - reasoning_parser: str = ""
2308 - """Select the reasoning parser depending on the model that you're using.
2309 - This is used to parse the reasoning content into OpenAI API format."""
2310 -
2311 - def compute_hash(self) -> str:
2312 - """
2313 - WARNING: Whenever a new field is added to this config,
2314 - ensure that it is included in the factors list if
2315 - it affects the computation graph.
2316 -
2317 - Provide a hash that uniquely identifies all the configs
2318 - that affect the structure of the computation
2319 - graph from input ids/embeddings to the final hidden states,
2320 - excluding anything before input ids/embeddings and after
2321 - the final hidden states.
2322 - """
2323 - # no factors to consider.
2324 - # this config will not affect the computation graph.
2325 - factors: list[Any] = []
2326 - hash_str = hashlib.md5(str(factors).encode(),
2327 - usedforsecurity=False).hexdigest()
2328 - return hash_str
2329 -
2330 - def __post_init__(self):
2331 - if (self.disable_any_whitespace
2332 - and self.backend not in ("xgrammar", "guidance")):
2333 - raise ValueError("disable_any_whitespace is only supported for "
2334 - "xgrammar and guidance backends.")
2335 - if (self.disable_additional_properties and self.backend != "guidance"):
2336 - raise ValueError("disable_additional_properties is only supported "
2337 - "for the guidance backend.")
2338 -
2339 -
2281 DetailedTraceModules = Literal["model", "worker", "all"]
2282
2283
vllm/config/structured_outputs.py new
+64
@@ -0,0 +1,64 @@
1 +# SPDX-License-Identifier: Apache-2.0
2 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 +
4 +import hashlib
5 +from typing import Any, Literal
6 +
7 +from pydantic.dataclasses import dataclass
8 +
9 +from vllm.config.utils import config
10 +
11 +StructuredOutputsBackend = Literal["auto", "xgrammar", "guidance", "outlines",
12 + "lm-format-enforcer"]
13 +
14 +
15 +@config
16 +@dataclass
17 +class StructuredOutputsConfig:
18 + """Dataclass which contains structured outputs config for the engine."""
19 +
20 + backend: StructuredOutputsBackend = "auto"
21 + """Which engine will be used for structured outputs (e.g. JSON schema,
22 + regex, etc) by default. With "auto", we will make opinionated choices
23 + based on request contents and what the backend libraries currently support,
24 + so the behavior is subject to change in each release."""
25 + disable_fallback: bool = False
26 + """If `True`, vLLM will not fallback to a different backend on error."""
27 + disable_any_whitespace: bool = False
28 + """If `True`, the model will not generate any whitespace during structured
29 + outputs. This is only supported for xgrammar and guidance backends."""
30 + disable_additional_properties: bool = False
31 + """If `True`, the `guidance` backend will not use `additionalProperties`
32 + in the JSON schema. This is only supported for the `guidance` backend and
33 + is used to better align its behaviour with `outlines` and `xgrammar`."""
34 + reasoning_parser: str = ""
35 + """Select the reasoning parser depending on the model that you're using.
36 + This is used to parse the reasoning content into OpenAI API format."""
37 +
38 + def compute_hash(self) -> str:
39 + """
40 + WARNING: Whenever a new field is added to this config,
41 + ensure that it is included in the factors list if
42 + it affects the computation graph.
43 +
44 + Provide a hash that uniquely identifies all the configs
45 + that affect the structure of the computation
46 + graph from input ids/embeddings to the final hidden states,
47 + excluding anything before input ids/embeddings and after
48 + the final hidden states.
49 + """
50 + # no factors to consider.
51 + # this config will not affect the computation graph.
52 + factors: list[Any] = []
53 + hash_str = hashlib.md5(str(factors).encode(),
54 + usedforsecurity=False).hexdigest()
55 + return hash_str
56 +
57 + def __post_init__(self):
58 + if (self.disable_any_whitespace
59 + and self.backend not in ("xgrammar", "guidance")):
60 + raise ValueError("disable_any_whitespace is only supported for "
61 + "xgrammar and guidance backends.")
62 + if (self.disable_additional_properties and self.backend != "guidance"):
63 + raise ValueError("disable_additional_properties is only supported "
64 + "for the guidance backend.")