-
-
Notifications
You must be signed in to change notification settings - Fork 11k
[Chore] Cleanup guided namespace, move to structured outputs config #22772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DarkLight1337
merged 50 commits into
vllm-project:main
from
aarnphm:feat/decoding-args-rename-all
Sep 18, 2025
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
69068cd
chore: finalize cleanup from v0
aarnphm 47ef968
fix: remove unecessary frontmatter
aarnphm f5d594c
fix: tests to use correct CLI args
aarnphm 0365951
Merge branch 'main' into pr/aarnphm/22772
hmellor bb884cd
Sweep for `guided_{choice/regex/json/grammar}`
hmellor f2cd9e0
`gd_params` -> `so_params`
hmellor 8f37583
`g` -> `grammar`
hmellor 6e972b8
Fix `config/__init__.py`
hmellor 8810d84
`engine_level_backend` -> `backend`
hmellor 03962b2
`guided_decoding` -> `structured_outputs`
hmellor ea86735
Fix `protocol.py`
hmellor fc0ce57
Missing docstring
hmellor 36772c6
Add missing backend selection
hmellor 6ac63c6
Remove last references to `guided_`
hmellor 17c574d
Fix arg utils
hmellor b0c2916
`reasoning_backend` -> `reasoning_parser`, fix `args.reasoning_parser`
hmellor c0ace42
Merge branch 'main' into pr/aarnphm/22772
hmellor 48328d7
Replace more instances of guided/guided decoding
hmellor 8b35c08
Remove `StructuredOutputsParams.from_optional` as it's not necessary
hmellor f8947e1
Fix tests
hmellor ec81c2b
pre-commit
hmellor b991f92
Fix tests
hmellor ce73903
Fix test pipeline for removed file
hmellor 37e7751
`--reasoning-parser` -> `--structured-outputs-config.reasoning_parser`
hmellor 0e62898
Merge branch 'main' into feat/decoding-args-rename-all
hmellor eefd512
Merge branch 'main' into pr/aarnphm/22772
hmellor f85abd7
Add reasoning parser back as an `InitVar`
hmellor 85b3b43
`pre-commit`
hmellor b4f70f7
Reinstate deprecated guided decoding CLI args
hmellor b52aab9
`--structured-outputs-config.reasoning_parser` -> `--reasoning-parser`
hmellor ac75b2a
`InitVar` didn't work
hmellor 2929036
`pre-commit`
hmellor 295ac17
`sample_choices` -> `sample_structured_outputs_choices`
hmellor 6954712
Update mergify path
hmellor 49b6d89
Fix wrong kwarg
hmellor e361772
Simplify dict -> config
hmellor 94a2e74
Simplify request validation
hmellor 02ef1a7
Small typo
hmellor a2b0c18
Fix type checking of `structured_outputs` in protocol
hmellor 176ecce
Fix incorrect condition for enabling disable_any_whitespace in test
hmellor 553d7a5
Fix opinionated backend selection when `backend="auto"`
hmellor bd5ef94
Remove badly merged change
hmellor 8b38bc4
Fix opinionated backend selection part 2
hmellor 76cb011
Fix comment
hmellor 87488f5
Merge branch 'main' into pr/aarnphm/22772
hmellor f869f9c
Make failing test less flaky
hmellor ec94b4a
Fix structured output being enabled by response format and tool calling
hmellor 2f2f3bc
Merge branch 'main' into feat/decoding-args-rename-all
hmellor 476950a
Merge branch 'main' into feat/decoding-args-rename-all
DarkLight1337 5872fe7
Fix test
hmellor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,23 +12,23 @@ You can generate structured outputs using the OpenAI's [Completions](https://pla | |
|
|
||
| The following parameters are supported, which must be added as extra parameters: | ||
|
|
||
| - `guided_choice`: the output will be exactly one of the choices. | ||
| - `guided_regex`: the output will follow the regex pattern. | ||
| - `guided_json`: the output will follow the JSON schema. | ||
| - `guided_grammar`: the output will follow the context free grammar. | ||
| - `choice`: the output will be exactly one of the choices. | ||
| - `regex`: the output will follow the regex pattern. | ||
| - `json`: the output will follow the JSON schema. | ||
| - `grammar`: the output will follow the context free grammar. | ||
| - `structural_tag`: Follow a JSON schema within a set of specified tags within the generated text. | ||
|
|
||
| You can see the complete list of supported parameters on the [OpenAI-Compatible Server](../serving/openai_compatible_server.md) page. | ||
|
|
||
| Structured outputs are supported by default in the OpenAI-Compatible Server. You | ||
| may choose to specify the backend to use by setting the | ||
| `--guided-decoding-backend` flag to `vllm serve`. The default backend is `auto`, | ||
| `--structured-outputs-config.backend` flag to `vllm serve`. The default backend is `auto`, | ||
| which will try to choose an appropriate backend based on the details of the | ||
| request. You may also choose a specific backend, along with | ||
| some options. A full set of options is available in the `vllm serve --help` | ||
| text. | ||
|
|
||
| Now let´s see an example for each of the cases, starting with the `guided_choice`, as it´s the easiest one: | ||
| Now let´s see an example for each of the cases, starting with the `choice`, as it´s the easiest one: | ||
|
|
||
| ??? code | ||
|
|
||
|
|
@@ -45,12 +45,12 @@ Now let´s see an example for each of the cases, starting with the `guided_choic | |
| messages=[ | ||
| {"role": "user", "content": "Classify this sentiment: vLLM is wonderful!"} | ||
| ], | ||
| extra_body={"guided_choice": ["positive", "negative"]}, | ||
| extra_body={"structured_outputs": {"choice": ["positive", "negative"]}}, | ||
| ) | ||
| print(completion.choices[0].message.content) | ||
| ``` | ||
|
|
||
| The next example shows how to use the `guided_regex`. The idea is to generate an email address, given a simple regex template: | ||
| The next example shows how to use the `regex`. The idea is to generate an email address, given a simple regex template: | ||
|
|
||
| ??? code | ||
|
|
||
|
|
@@ -63,18 +63,18 @@ The next example shows how to use the `guided_regex`. The idea is to generate an | |
| "content": "Generate an example email address for Alan Turing, who works in Enigma. End in .com and new line. Example result: [email protected]\n", | ||
| } | ||
| ], | ||
| extra_body={"guided_regex": r"\w+@\w+\.com\n", "stop": ["\n"]}, | ||
| extra_body={"structured_outputs": {"regex": r"\w+@\w+\.com\n"}, "stop": ["\n"]}, | ||
| ) | ||
| print(completion.choices[0].message.content) | ||
| ``` | ||
|
|
||
| One of the most relevant features in structured text generation is the option to generate a valid JSON with pre-defined fields and formats. | ||
| For this we can use the `guided_json` parameter in two different ways: | ||
| For this we can use the `json` parameter in two different ways: | ||
|
|
||
| - Using directly a [JSON Schema](https://json-schema.org/) | ||
| - Defining a [Pydantic model](https://docs.pydantic.dev/latest/) and then extracting the JSON Schema from it (which is normally an easier option). | ||
|
|
||
| The next example shows how to use the `guided_json` parameter with a Pydantic model: | ||
| The next example shows how to use the `response_format` parameter with a Pydantic model: | ||
|
|
||
| ??? code | ||
|
|
||
|
|
@@ -119,7 +119,7 @@ The next example shows how to use the `guided_json` parameter with a Pydantic mo | |
| JSON schema and how the fields should be populated. This can improve the | ||
| results notably in most cases. | ||
|
|
||
| Finally we have the `guided_grammar` option, which is probably the most | ||
| Finally we have the `grammar` option, which is probably the most | ||
| difficult to use, but it´s really powerful. It allows us to define complete | ||
| languages like SQL queries. It works by using a context free EBNF grammar. | ||
| As an example, we can use to define a specific format of simplified SQL queries: | ||
|
|
@@ -149,7 +149,7 @@ As an example, we can use to define a specific format of simplified SQL queries: | |
| "content": "Generate an SQL query to show the 'username' and 'email' from the 'users' table.", | ||
| } | ||
| ], | ||
| extra_body={"guided_grammar": simplified_sql_grammar}, | ||
| extra_body={"structured_outputs": {"grammar": simplified_sql_grammar}}, | ||
| ) | ||
| print(completion.choices[0].message.content) | ||
| ``` | ||
|
|
@@ -292,8 +292,8 @@ An example of using `structural_tag` can be found here: <gh-file:examples/online | |
| ## Offline Inference | ||
|
|
||
| Offline inference allows for the same types of structured outputs. | ||
| To use it, we´ll need to configure the guided decoding using the class `GuidedDecodingParams` inside `SamplingParams`. | ||
| The main available options inside `GuidedDecodingParams` are: | ||
| To use it, we´ll need to configure the structured outputs using the class `StructuredOutputsParams` inside `SamplingParams`. | ||
| The main available options inside `StructuredOutputsParams` are: | ||
|
|
||
| - `json` | ||
| - `regex` | ||
|
|
@@ -309,12 +309,12 @@ shown below: | |
|
|
||
| ```python | ||
| from vllm import LLM, SamplingParams | ||
| from vllm.sampling_params import GuidedDecodingParams | ||
| from vllm.sampling_params import StructuredOutputsParams | ||
|
|
||
| llm = LLM(model="HuggingFaceTB/SmolLM2-1.7B-Instruct") | ||
|
|
||
| guided_decoding_params = GuidedDecodingParams(choice=["Positive", "Negative"]) | ||
| sampling_params = SamplingParams(guided_decoding=guided_decoding_params) | ||
| structured_outputs_params = StructuredOutputsParams(choice=["Positive", "Negative"]) | ||
| sampling_params = SamplingParams(structured_outputs=structured_outputs_params) | ||
| outputs = llm.generate( | ||
| prompts="Classify this sentiment: vLLM is wonderful!", | ||
| sampling_params=sampling_params, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.