Skip to content

Commit

Permalink
Add benchmark tests (pytorch#6082)
Browse files Browse the repository at this point in the history
  • Loading branch information
frgossen authored Dec 11, 2023
1 parent dbd3e33 commit bbe1a8d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/benchmarks/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function run_make_tests {
}

function run_python_tests {
python3 "$CDIR/test_experiment_runner.py"
python3 "$CDIR/test_benchmark_experiment.py"
python3 "$CDIR/test_benchmark_model.py"
}

function run_tests {
Expand Down
18 changes: 18 additions & 0 deletions test/benchmarks/test_benchmark_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest

from benchmark_model import BenchmarkModel


class BenchmarkModelTest(unittest.TestCase):

def test_to_dict(self):
bm = BenchmarkModel("torchbench or other", "super_deep_model",
"placeholder")
actual = bm.to_dict()
self.assertEqual(2, len(actual))
self.assertEqual("torchbench or other", actual["suite_name"])
self.assertEqual("super_deep_model", actual["model_name"])


if __name__ == '__main__':
unittest.main()
32 changes: 32 additions & 0 deletions test/benchmarks/test_experiment_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest

import subprocess

import experiment_runner

EXPERIMENT_RUNNER_PY = experiment_runner.__file__


class ExperimentRunnerTest(unittest.TestCase):

def test_alexnet_dry_run(self):
child = subprocess.run([
"python", EXPERIMENT_RUNNER_PY, "--dynamo=openxla", "--dynamo=inductor",
"--xla=PJRT", "--xla=None", "--test=eval", "--test=train",
"--suite-name=torchbench", "--accelerator=cpu", "--filter=^alexnet$",
"--dry-run"
],
capture_output=True,
text=True)
expected_in_stderr = [
"Number of selected experiment configs: 2",
"Number of selected model configs: 1",
"'--experiment-config={\"accelerator\": \"cpu\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"eval\"}', '--model-config={\"model_name\": \"alexnet\"}'",
"'--experiment-config={\"accelerator\": \"cpu\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"train\"}', '--model-config={\"model_name\": \"alexnet\"}'",
]
for expected in expected_in_stderr:
self.assertTrue(expected in child.stderr)


if __name__ == '__main__':
unittest.main()

0 comments on commit bbe1a8d

Please sign in to comment.