forked from dottxt-ai/outlines
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert tests/benchmarks/ pytest-benchmark benchmarks into benchmarks…
…/ asv benchmarks
- Loading branch information
Showing
5 changed files
with
60 additions
and
74 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
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,36 @@ | ||
import importlib | ||
|
||
import interegular | ||
import numba | ||
|
||
import outlines | ||
|
||
from .common import setup_tokenizer | ||
|
||
outlines.disable_cache() | ||
|
||
|
||
class NumbaCompileBenchmark: | ||
def setup(self): | ||
from outlines.fsm import regex | ||
|
||
self.tokenizer = setup_tokenizer() | ||
self.regex = regex | ||
original_njit = numba.njit | ||
|
||
def mock_njit(*args, **kwargs): | ||
kwargs["cache"] = False | ||
return original_njit(*args, **kwargs) | ||
|
||
self.original_njit = original_njit | ||
numba.njit = mock_njit | ||
importlib.reload(self.regex) | ||
self.regex_pattern, _ = self.regex.make_deterministic_fsm( | ||
interegular.parse_pattern("a").to_fsm().reduce() | ||
) | ||
|
||
def teardown(self): | ||
numba.njit = self.original_njit | ||
|
||
def time_compile_numba(self): | ||
self.regex.create_fsm_index_tokenizer(self.regex_pattern, 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
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 |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import pytest | ||
from transformers import AutoTokenizer | ||
|
||
from outlines.fsm.guide import RegexGuide | ||
from outlines.models.transformers import TransformerTokenizer | ||
|
||
|
||
@pytest.fixture | ||
def tokenizer(): | ||
def setup_tokenizer(): | ||
tokenizer = AutoTokenizer.from_pretrained("gpt2") | ||
return TransformerTokenizer(tokenizer) | ||
|
||
|
||
@pytest.fixture | ||
def ensure_numba_compiled(tokenizer): | ||
RegexGuide("a", tokenizer) | ||
return True |
This file was deleted.
Oops, something went wrong.