[Feature] Support user-specified "trigger" token before starting structured decoding #12995
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.
This PR allows the user to specify a "trigger token" that needs to be produced before xgrammar is applied to structured decoding. For example, when generating with r1-like models, the end-of-thought token
</think>
can be the trigger token, as seen in the example in the added unit test.Additional work might be required to:
JSON Output:
or\boxed
in math prompts) as the trigger for structured decoding.FIX #12619
I was not aware of #12955 from Saturday morning before I started working on this PR on Sunday- I apologize to @gaocegege if this PR partially overlapped with their contribution. From what I understand, the main difference between these two PR is the handling of
batch_size
inxgrammar_decoding
, in case more than one stream of generations are being sent through this logic processor at a time. Though it is unclear whether that would ever be the case in the current setup.