Skip to content
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

Support constrained decoding #1038

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft

Conversation

Taka152
Copy link

@Taka152 Taka152 commented Nov 6, 2024

This PR adds constrained decoding feature that user can provide regex or json schema to guide the decoding process. This can enable function calls or further increase the quality of the response.

The API looks like the following code, currently it only accepts regex and json_schema type, though context free grammar could be considered in the future.

# python
params.set_guidance("json_schema", json.dumps(json_schema))
// cpp
params->SetGuidance("json_schema", json_str);

The overhead brought by this feature is about 3-5% latency increase, and could further optimized after continuous decoding feature, it can even accelerate generation by jump forward tokens that is fixed in guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants