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

Grammar Support #146

Open
jcsoo opened this issue May 1, 2024 · 1 comment
Open

Grammar Support #146

jcsoo opened this issue May 1, 2024 · 1 comment

Comments

@jcsoo
Copy link
Contributor

jcsoo commented May 1, 2024

I've been working on a a native Rust GBNF parser that generates WhisperGrammarElementType arrays as needed for whisper-rs. It's not particularly complicated - about 40 lines of pest code and a few hundred lines to generate the arrays.

Would there be interest in adding this functionality to whisper-rs, perhaps as a separate subcrate?

I thought about whether this would be more useful as an external ggml grammar crate supporting both whisper.ccp and llama.cpp, but right now it seems like the implementation is copy-pasted between the two projects and there are no guarantees that they will not diverge, and I don't know if there is a single Rust llama implementation that it makes sense to integrate with.

This also brings up the question of what directions the dependencies should go. Right now my crate depends on whisper-rs in order to export WhisperGrammarElementType, but that doesn't seem ideal. An alternative could be to generate the raw buffers and pointers needed by whisper.cpp, perhaps as an opaque type, or to fill in caller-provided buffers.

Any thoughts?

@jcsoo
Copy link
Contributor Author

jcsoo commented May 2, 2024

In PR #145, I've updated set_grammar to take a simple Box<[u64]> with the following contents:

0: # of rules
1..N+1: index of rule N
N+2..: grammar elements

This allows us to pass around a single self-contained item that doesn't have any self-referential pointers. It's also simple enough so that we don't need dependencies between whisper-rs and the grammar parser, and it can also be used in llama.cpp derivatives.

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

No branches or pull requests

1 participant