Skip to content

[Feature] Support Latest Xgrammar Structural Tag#24708

Closed
Hanchenli wants to merge 12 commits into
vllm-project:mainfrom
Hanchenli:lhc/xgrammar_release
Closed

[Feature] Support Latest Xgrammar Structural Tag#24708
Hanchenli wants to merge 12 commits into
vllm-project:mainfrom
Hanchenli:lhc/xgrammar_release

Conversation

@Hanchenli

@Hanchenli Hanchenli commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

Purpose

This PR is created to support the upcoming XGrammar Structural Tag feature. The latest tags may be in the format of:

{
"type": "structural_tag",
"format": {
"type":
"triggered_tags",
"tags": [{
"begin": "hello_flag",
"content": {
"type": "any_text"
},
"end": "hello"
}],
"triggers": ["hello"],
"stop_after_first":
False
}
}

This requires us to update the format checking for the API format and the construction of structural tag at XGrammar Backend.

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for a new structural tag format in XGrammar, including updates to the API protocol and the backend implementation. The changes introduce backward compatibility for the legacy format while enabling the new one. My review focuses on improving the type safety of the new API definition and reducing code duplication in the backend logic. I've identified two high-severity issues related to these points.

Comment thread vllm/entrypoints/openai/protocol.py
Comment thread vllm/v1/structured_output/backend_xgrammar.py Outdated

@aarnphm aarnphm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick notes.

Comment thread vllm/entrypoints/openai/protocol.py
Comment thread .gitignore Outdated

@chaunceyjiang chaunceyjiang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xgrammar has not officially released this feature yet. Should we wait for the official release before integrating this new feature?

@aarnphm

aarnphm commented Sep 12, 2025

Copy link
Copy Markdown
Collaborator

Xgrammar has not officially released this feature yet. Should we wait for the official release before integrating this new feature?

yes, this should be held, at least after 0.10.2

@mergify

mergify Bot commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @Hanchenli.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

Signed-off-by: Hanchenli <lihanc2002@gmail.com>
@mergify mergify Bot removed the needs-rebase label Sep 24, 2025
Signed-off-by: Hanchenli <lihanc2002@gmail.com>
@Hanchenli

Copy link
Copy Markdown
Contributor Author

I did some merging and XGrammar version has been bumped. Maybe we can merge this now after review? @aarnphm @chaunceyjiang

@aarnphm

aarnphm commented Sep 28, 2025

Copy link
Copy Markdown
Collaborator

Can you check the failure? has to do with the args rename recently.

@Hanchenli

Copy link
Copy Markdown
Contributor Author

Can you check the failure? has to do with the args rename recently.

The tests seem to be passing for me in local.

Comment thread tests/v1/entrypoints/llm/test_struct_output_generate.py Outdated
aarnphm and others added 6 commits October 3, 2025 23:18
Co-authored-by: Benjamin Chislett <chislett.ben@gmail.com>
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
Signed-off-by: Hanchenli <61769611+Hanchenli@users.noreply.github.com>
Signed-off-by: Hanchenli <lihanc2002@gmail.com>
Signed-off-by: Hanchenli <lihanc2002@gmail.com>

structural_tag_config = {
"type": "structural_tag",
"format": {

@chaunceyjiang chaunceyjiang Oct 9, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding some usage examples in the examples directory.

@Hanchenli

Copy link
Copy Markdown
Contributor Author

Closing as the functionality has been added through #25515

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants