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

Resync llama_grammar with llama.cpp implementation and use curly braces quantities instead of repetitions #1721

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gbloisi-openaire
Copy link

This PR resync recent changes from llama.cpp's json_schema_to_grammar.py

Initially I came to this patch because I noticed that generated json strings sometimes contained ascii control characters, hence causing json.loads to fail.
Then I noticed that sometimes unterminated json was generated because llama.cpp was producing very long and wrong replies. I believe this is caused by a bug in grammar management, however using curly braces quantities instead of code-generated repetitions alleviates this problem a lot, and it gets totally fixed by providing max_length of string fields in the json schema.
Something else I noticed is that without this change the generated json could contain newlines and tabs/spaces as separators between json elements, whereas the grammar would impose a sigle whitespace: that should be another sign of a bug in grammar management. Perhaps teh grammar was silently ignored and a json was generated anyway because the json schema was part of the prompt as well.

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.

1 participant