|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +if Path().resolve().name == "scripts": |
| 6 | + os.chdir("..") |
| 7 | + |
| 8 | +sys.path.append("src/discord-cluster-manager") |
| 9 | + |
| 10 | +from leaderboard_eval import py_eval |
| 11 | +from run_eval import run_pytorch_script |
| 12 | + |
| 13 | +ref = Path("examples/identity_py/reference.py") |
| 14 | + |
| 15 | + |
| 16 | +def test_does_not_import(): |
| 17 | + # input_tt is a typo, so this won't compile |
| 18 | + sub = """ |
| 19 | + this is a syntax error |
| 20 | + """ |
| 21 | + |
| 22 | + run = run_pytorch_script(py_eval, ref.read_text(), sub, arch=None) |
| 23 | + assert run.success is False |
| 24 | + assert run.exit_code == 1 |
| 25 | + assert "IndentationError: unexpected indent\n" in run.stderr |
| 26 | + |
| 27 | + |
| 28 | +def test_error(): |
| 29 | + # no-op, runs fine but isn't correct |
| 30 | + sub = """ |
| 31 | +import torch |
| 32 | +def custom_kernel(input): |
| 33 | + return [torch.zeros_like(i) for i in input] |
| 34 | + """ |
| 35 | + run = run_pytorch_script(py_eval, ref.read_text(), sub, arch=None) |
| 36 | + assert run.success is False |
| 37 | + assert run.command == "python eval.py" |
| 38 | + # we never reach the benchmark part, because the test fails |
| 39 | + assert "warming up..." not in run.stdout |
| 40 | + assert "mismatch found! custom implementation doesnt match reference." in run.stdout |
| 41 | + assert run.exit_code == 112 |
| 42 | + assert run.result["check"] == "fail" |
| 43 | + |
| 44 | + |
| 45 | +def test_correct(): |
| 46 | + sub = Path("examples/identity_py/submission.py").read_text() |
| 47 | + |
| 48 | + run = run_pytorch_script(py_eval, ref.read_text(), sub, arch=None) |
| 49 | + assert run.success is True |
| 50 | + assert "warming up..." in run.stdout |
| 51 | + assert run.exit_code == 0 |
| 52 | + assert run.result["check"] == "pass" |
0 commit comments