-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
115 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from transformers import AutoTokenizer | ||
|
||
from outlines.caching import cache_disabled | ||
from outlines.fsm.regex import reduced_vocabulary | ||
from outlines.models.transformers import TransformerTokenizer | ||
|
||
from .common import ensure_numba_compiled | ||
|
||
tokenizer_uris = { | ||
"gpt2": "gpt2", | ||
"llama3": "unsloth/Meta-Llama-3.1-8B", | ||
"byt5": "google/byt5-small", | ||
} | ||
|
||
|
||
def reduced_vocabulary_uncached(*args, **kwargs): | ||
return reduced_vocabulary.__wrapped__(*args, **kwargs) | ||
|
||
|
||
class RegexReducedVocabularyBenchmark: | ||
params = ["gpt2", "llama3", "byt5"] | ||
|
||
def setup(self, tokenizer_name): | ||
ensure_numba_compiled( | ||
TransformerTokenizer( | ||
AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct") | ||
) | ||
) | ||
self.tokenizer = TransformerTokenizer( | ||
AutoTokenizer.from_pretrained(tokenizer_uris[tokenizer_name]) | ||
) | ||
|
||
@cache_disabled() | ||
def time_reduced_vocabulary(self, _): | ||
reduced_vocabulary_uncached(self.tokenizer) |
This file contains 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