-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add asv PR benchmark workflow, Migrate benchmarks from pytest-benchma…
…rk to asv, add memory benchmarks
- Loading branch information
Showing
9 changed files
with
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Benchmark PR | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
env: | ||
PYTHON_VERSION: "3.10" | ||
WORKING_DIR: ${{ github.workspace }}/benchmarks | ||
|
||
FAIL_THRSHOLD: 1.1 | ||
|
||
jobs: | ||
benchmark-pr: | ||
runs-on: ubuntu-latest | ||
if: contains(github.event.pull_request.labels.*.name, 'run_benchmarks') || github.event_name == 'workflow_dispatch' | ||
|
||
defaults: | ||
run: | ||
working-directory: ${{ env.WORKING_DIR }} | ||
|
||
steps: | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install asv virtualenv lf-asv-formatter | ||
- name: Create ASV machine config file | ||
run: asv machine --machine gh-runner --yes | ||
|
||
- name: Save comparison of PR against main branch | ||
run: | | ||
# prepare main branch for comparison | ||
git remote add upstream https://github.com/${{ github.repository }}.git | ||
git fetch upstream main | ||
# Run benchmarks, writing comment contents to ./output | ||
asv continuous upstream/main HEAD \ | ||
--factor 1.1 --sort ratio --split --interleave-rounds -a repeat=3 | ||
asv compare upstream/main HEAD --sort ratio --split | tee output | ||
python -m lf_asv_formatter --asv_version "$(echo asv --version)" | ||
printf "Benchmark Suite Results:\n\n" >> comment_body | ||
cat output >> comment_body | ||
- name: Upload benchmark results | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: benchmark-results-${{ github.sha }} | ||
path: comment_body | ||
|
||
- name: Create summary with artifact link | ||
run: | | ||
echo "### Benchmark Results" >> $GITHUB_STEP_SUMMARY | ||
echo "The benchmark results are available as an artifact. You can download them [here](../actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY |
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ docs/build | |
.idea/ | ||
*.gguf | ||
.venv | ||
benchmarks/results |
Empty file.
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,20 @@ | ||
{ | ||
"version": 1, | ||
"project": "Outlines", | ||
"project_url": "https://outlines-dev.github.io/outlines/", | ||
"repo": "..", | ||
"branches": [ | ||
"HEAD" | ||
], | ||
"build_command": [ | ||
"pip install .[test]", | ||
"python -m build --wheel -o {build_cache_dir} {build_dir}" | ||
], | ||
"environment_type": "virtualenv", | ||
"show_commit_url": "https://github.com/lapp0/outlines/commit/", | ||
"benchmark_dir": ".", | ||
"env_dir": "env", | ||
"results_dir": "results", | ||
"html_dir": "html", | ||
"build_cache_size": 8 | ||
} |
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,37 @@ | ||
import importlib | ||
|
||
import interegular | ||
import numba | ||
|
||
import outlines | ||
|
||
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() | ||
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,19 @@ | ||
import pytest | ||
from transformers import AutoTokenizer | ||
|
||
import outlines.caching | ||
from outlines.fsm.guide import RegexGuide | ||
from outlines.models.transformers import TransformerTokenizer | ||
|
||
|
||
@pytest.fixture | ||
def tokenizer(): | ||
def clear_outlines_cache(): | ||
outlines.caching.clear_cache() | ||
|
||
|
||
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.