Skip to content

Commit

Permalink
Merge branch 'introduce-asv-ci-workflow-883'
Browse files Browse the repository at this point in the history
  • Loading branch information
lapp0 committed May 26, 2024
2 parents c699d23 + 359b385 commit 592c884
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion benchmarks/bench_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from outlines.fsm.guide import RegexGuide # noqa: E402
from outlines.fsm.json_schema import build_regex_from_schema # noqa: E402

from .common import ensure_numba_compiled, setup_tokenizer # noqa: E402
from .common import ( # noqa: E402
clear_outlines_cache,
ensure_numba_compiled,
setup_tokenizer,
)

simple_schema = """{
"$defs": {
Expand Down Expand Up @@ -70,6 +74,7 @@ class JsonSchemaBenchmark:
params = schemas.keys()

def setup(self, schema_name):
clear_outlines_cache()
self.tokenizer = setup_tokenizer()
self.schema = schemas[schema_name]
ensure_numba_compiled(self.tokenizer)
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_numba_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import outlines

from .common import setup_tokenizer
from .common import clear_outlines_cache, setup_tokenizer

outlines.disable_cache()


class NumbaCompileBenchmark:
def setup(self):
clear_outlines_cache()
from outlines.fsm import regex

self.tokenizer = setup_tokenizer()
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/bench_regex_guide.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import outlines

from .common import ensure_numba_compiled, setup_tokenizer
from .common import clear_outlines_cache, ensure_numba_compiled, setup_tokenizer

outlines.disable_cache()

Expand All @@ -23,6 +23,7 @@ class RegexGuideBenchmark:
params = regex_samples.keys()

def setup(self, pattern_name):
clear_outlines_cache()
self.tokenizer = setup_tokenizer()
ensure_numba_compiled(self.tokenizer)
self.pattern = regex_samples[pattern_name]
Expand All @@ -35,6 +36,7 @@ class MemoryRegexGuideBenchmark:
params = ["simple_phone", "complex_span_constrained_relation_extraction"]

def setup(self, pattern_name):
clear_outlines_cache()
self.tokenizer = setup_tokenizer()
ensure_numba_compiled(self.tokenizer)
self.pattern = regex_samples[pattern_name]
Expand Down
5 changes: 5 additions & 0 deletions benchmarks/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from transformers import AutoTokenizer

import outlines.caching
from outlines.fsm.guide import RegexGuide
from outlines.models.transformers import TransformerTokenizer


def clear_outlines_cache():
outlines.caching.clear_cache()


def setup_tokenizer():
tokenizer = AutoTokenizer.from_pretrained("gpt2")
return TransformerTokenizer(tokenizer)
Expand Down

0 comments on commit 592c884

Please sign in to comment.