Skip to content

[Feature] Support Latest Xgrammar Structural Tag#24708

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

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

Conversation

@Hanchenli
Copy link
Contributor

@Hanchenli Hanchenli commented Sep 12, 2025

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.

Copy link
Contributor

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

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.

Copy link
Collaborator

@aarnphm aarnphm left a comment

Choose a reason for hiding this comment

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

quick notes.

Copy link
Collaborator

@chaunceyjiang chaunceyjiang left a comment

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
Copy link
Collaborator

aarnphm commented Sep 12, 2025

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
Copy link

mergify bot commented Sep 18, 2025

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
Contributor Author

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

@aarnphm
Copy link
Collaborator

aarnphm commented Sep 28, 2025

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

@Hanchenli
Copy link
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.

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": {
Copy link
Collaborator

@chaunceyjiang chaunceyjiang Oct 9, 2025

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
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