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 using xgrammar to get json output #12870

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

MeouSker77
Copy link
Contributor

Description

support using xgrammar to get json output

1. Why the change?

2. User API changes

pip install xgrammar==0.1.13
tokenizer = ...
model = ...
schema = ...

from ipex_llm.transformers.xgrammar import create_json_logits_processor, reset_json_logits_processor

json_processor = create_json_logits_processor(tokenizer, model.config.vocab_size, schema)

for prompt in [prompts]:
    input_ids = tokenizer.apply_chat_template(prompt, return_tensors="pt", add_generation_prompt=True)
    json_processor = reset_json_logits_processor(json_processor)
    model.generate(
        input_ids,
        ...
        logits_processor=[json_processor]
    )

@MeouSker77 MeouSker77 requested a review from rnwang04 February 21, 2025 07:52
@MeouSker77 MeouSker77 merged commit 3f6ecce into intel:main Feb 24, 2025
1 check passed
@MeouSker77 MeouSker77 deleted the support-xgrammar branch February 24, 2025 06:11
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