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

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open

Conversation

Taka152
Copy link
Contributor

@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 response quality.

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 jump forward steps with only one candidate.

src/ort_genai_c.cpp Show resolved Hide resolved
src/smartptrs.h Outdated Show resolved Hide resolved
src/logits_processor.cpp Show resolved Hide resolved
src/logits_processor.cpp Show resolved Hide resolved
src/logits_processor.cpp Outdated Show resolved Hide resolved
src/logits_processor.cpp Outdated Show resolved Hide resolved
@natke natke self-requested a review December 21, 2024 00:49
Copy link
Contributor

@natke natke left a comment

Choose a reason for hiding this comment

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

We will postpone merging this until we resolve the rust dependency

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.

5 participants