Skip to content

Commit 598ea6d

Browse files
ngc92alexzhang13
andauthored
Allow arbitrary sets of files to be used in python and cuda runner code (#132)
* allow arbitrary sources and headers * fixed runners and merge multi-file with new runners * fix runner to squash, fix arguments for testing runner to squash, fix arguments for testing runner to squash, fix arguments for testing runner for now, fix to train until we fix naming train -> submission --------- Co-authored-by: alexzhang13 <[email protected]>
1 parent 7c233d3 commit 598ea6d

File tree

12 files changed

+97
-68
lines changed

12 files changed

+97
-68
lines changed

.github/workflows/runner.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313

1414
if config["lang"] == "cu":
1515
comp, run = run_cuda_script(
16-
config.get("eval.cu", cu_eval),
17-
config.get("reference.cuh", None),
18-
config.get("submission.cuh", None),
16+
{"eval.cu": cu_eval},
17+
{key: config[key] for key in ["reference.cuh", "submission.cuh"] if key in config},
1918
arch=None,
2019
)
2120
result = {"compile": asdict(comp), "run": asdict(run)}
2221
else:
2322
run = run_pytorch_script(
24-
config.get("eval.py", py_eval),
25-
config.get("reference.py", None),
26-
config.get("submission.py", None),
23+
{
24+
"eval.py": py_eval,
25+
**{key: config[key] for key in ["reference.py", "submission.py"] if key in config},
26+
},
27+
main="eval.py",
2728
arch=None,
2829
)
2930
result = {"run": asdict(run)}

docs/docs/creating-a-leaderboard/cuda-creations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Let's break down what's going on in this relatively short file:
5656
#include <iostream>
5757

5858
#include "reference.cuh"
59-
#include "train.cuh"
59+
#include "submission.cuh"
6060

6161
#define WARMUP_RUNS 10
6262
#define TIMED_RUNS 100
@@ -118,7 +118,7 @@ int main() {
118118
return 0;
119119
}
120120
```
121-
You'll notice that we include from headers named `reference.cuh` and `train.cuh`. These are the reference
121+
You'll notice that we include from headers named `reference.cuh` and `submission.cuh`. These are the reference
122122
code and submission code respectively, just renamed to a fix module so we can include them. The
123123
general idea is that the evaluation code can treat the leaderboard as a basic abstraction, and only
124124
concern itself with three things:

docs/docs/creating-a-leaderboard/python-creations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Let's break down what's going on in this relatively short file:
5353
import torch
5454
import time
5555
from reference import ref_kernel, generate_input, check_implementation
56-
from train import custom_kernel
56+
from submission import custom_kernel
5757

5858

5959
def correctness() -> bool:

scripts/ci_test_cuda.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ def test_does_not_compile():
2020
output_t custom_kernel(input_tt data) { }
2121
"""
2222

23-
comp, run = run_cuda_script(cu_eval, ref.read_text(), sub, arch=None)
23+
comp, run = run_cuda_script(
24+
{"eval.cu": cu_eval}, {"reference.cuh": ref.read_text(), "submission.cuh": sub}, arch=None
25+
)
2426
assert comp.success is False
2527
assert run.success is False
2628
assert comp.nvcc_found is True
2729
assert comp.exit_code != ExitCode.SUCCESS
2830
assert comp.stdout == ""
29-
assert 'train.cuh(2): error: identifier "input_tt" is undefined' in comp.stderr
31+
assert 'submission.cuh(2): error: identifier "input_tt" is undefined' in comp.stderr
3032
assert '1 error detected in the compilation of "eval.cu".' in comp.stderr
3133
assert comp.command.startswith("/usr/local/cuda/bin/nvcc")
3234
assert "nvcc: NVIDIA (R) Cuda compiler driver" in comp.nvcc_version
@@ -52,7 +54,9 @@ def test_cuda_runtime_error():
5254
}
5355
5456
"""
55-
comp, run = run_cuda_script(cu_eval, ref.read_text(), sub, arch=None)
57+
comp, run = run_cuda_script(
58+
{"eval.cu": cu_eval}, {"reference.cuh": ref.read_text(), "submission.cuh": sub}, arch=None
59+
)
5660
assert comp.success is True
5761
assert run.success is False
5862
assert run.command == "./eval.out"
@@ -80,7 +84,9 @@ def test_cuda_validation_fail():
8084
}
8185
8286
"""
83-
comp, run = run_cuda_script(cu_eval, ref.read_text(), sub, arch=None)
87+
comp, run = run_cuda_script(
88+
{"eval.cu": cu_eval}, {"reference.cuh": ref.read_text(), "submission.cuh": sub}, arch=None
89+
)
8490
assert comp.success is True
8591
assert run.success is True
8692
assert run.passed is False
@@ -95,7 +101,9 @@ def test_cuda_validation_fail():
95101
def test_cuda_correct():
96102
sub = Path("examples/identity_cuda/submission.cuh").read_text()
97103

98-
comp, run = run_cuda_script(cu_eval, ref.read_text(), sub, arch=None)
104+
comp, run = run_cuda_script(
105+
{"eval.cu": cu_eval}, {"reference.cuh": ref.read_text(), "submission.cuh": sub}, arch=None
106+
)
99107
assert comp.success is True
100108
assert run.success is True
101109
assert "warming up..." in run.stdout

scripts/ci_test_python.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def test_does_not_import():
2020
this is a syntax error
2121
"""
2222

23-
run = run_pytorch_script(py_eval, ref.read_text(), sub, arch=None)
23+
run = run_pytorch_script(
24+
{"eval.py": py_eval, "reference.py": ref.read_text(), "submission.py": sub}, "eval.py"
25+
)
2426
assert run.success is False
2527
assert run.exit_code != ExitCode.SUCCESS
2628
assert "IndentationError: unexpected indent\n" in run.stderr
@@ -33,7 +35,12 @@ def test_error():
3335
def custom_kernel(input):
3436
return [torch.zeros_like(i) for i in input]
3537
"""
36-
run = run_pytorch_script(py_eval, ref.read_text(), sub, arch=None)
38+
39+
run = run_pytorch_script(
40+
{"eval.py": py_eval, "reference.py": ref.read_text(), "submission.py": sub},
41+
"eval.py",
42+
arch=None,
43+
)
3744
assert run.success is True
3845
assert run.passed is False
3946
assert run.command == "python eval.py"
@@ -47,7 +54,9 @@ def custom_kernel(input):
4754
def test_correct():
4855
sub = Path("examples/identity_py/submission.py").read_text()
4956

50-
run = run_pytorch_script(py_eval, ref.read_text(), sub, arch=None)
57+
run = run_pytorch_script(
58+
{"eval.py": py_eval, "reference.py": ref.read_text(), "submission.py": sub}, "eval.py"
59+
)
5160
assert run.success is True
5261
assert "warming up..." in run.stdout
5362
assert run.exit_code == ExitCode.SUCCESS

scripts/local-test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
ref = Path("examples/identity_cuda/reference.cuh")
1010
sub = Path("examples/identity_cuda/submission.cuh")
1111

12-
cout, score = run_cuda_script(cu_eval, ref.read_text(), sub.read_text(), arch=None)
12+
cout, score = run_cuda_script(
13+
{"eval.cu": cu_eval},
14+
{"reference.cuh": ref.read_text(), "submission.cuh": sub.read_text()},
15+
arch=None,
16+
)
1317
print(cout)
1418
print(score)
1519
exit(0 if score > 0 else 1)

src/discord-cluster-manager/cogs/modal_cog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def run_modal(
5959
"**Running on Modal...**\n> ⏳ Waiting for available GPU..."
6060
)
6161

62-
filename = "train.py" if script.filename.endswith(".py") else "train.cu"
62+
filename = "submission.py" if script.filename.endswith(".py") else "train.cu"
6363
reference_content = None
6464
if reference_script is not None or reference_code is not None:
6565
reference_content = (

src/discord-cluster-manager/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def combine_enums(enums: list[Type[Enum]], combined_name: str) -> Enum:
6767
MODAL_PATH = "/tmp/dcs/"
6868
MODAL_EVAL_CODE_PATH = "/tmp/dcs/eval.py"
6969
MODAL_REFERENCE_CODE_PATH = "/tmp/dcs/reference.py"
70-
MODAL_SUBMISSION_CODE_PATH = "/tmp/dcs/train.py"
70+
MODAL_SUBMISSION_CODE_PATH = "/tmp/dcs/submission.py"
7171

7272

7373
# Compilation flags for Modal

src/discord-cluster-manager/eval.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <memory>
88

99
#include "reference.cuh"
10-
#include "train.cuh"
10+
#include "submission.cuh"
1111

1212
#define WARMUP_RUNS 10
1313
#define TIMED_RUNS 100

src/discord-cluster-manager/eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import torch
77
from reference import check_implementation, generate_input, ref_kernel
8-
from train import custom_kernel
8+
from submission import custom_kernel
99

1010

1111
class PopcornLogger:

0 commit comments

Comments
 (0)