Enhancement: avoid computing full mask (+ adding types)#101
Merged
Saibo-creator merged 4 commits intoOct 22, 2024
Merged
Conversation
Collaborator
|
@nathanrchn This looks great. I think we could provide user two execution mode: In some cases, Once this is done, I'm ready to merge it ! |
Contributor
|
Won't this lead to the generation becoming deterministic (greedy decoding essentially) when the top token is valid? This will lead to e.g. strings in JSON (where almost all tokens are valid) almost aways being generated deterministically in this mode. |
Contributor
Author
|
Of course these changes works only when |
Collaborator
|
@nathanrchn Thank you again for the amazing work ;) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While running a generation using the CLI on the student JSON grammar with the Phi-3.5-mini-4bit model, I observed that the majority of tokens were already valid without applying a mask.
As evident in the screenshot above, the green tokens were sampled without constraints and were already valid.
I implemented the following logic in the
mask_logitsmethod:This minor modification resulted in a significant speed increase of 3 tokens per second.
As shown in the second screenshot, the impact of the
logits_processorhas been substantially reduced. It's worth noting that this improvement becomes more pronounced as the vocabulary size increases.