Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit stdout and stderr capture to 16KiB #150

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions scripts/ci_test_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,33 @@ def test_cuda_correct():
assert "warming up..." in run.stdout
assert run.exit_code == ExitCode.SUCCESS
assert run.result["check"] == "pass"


def test_huge_output():
sub = """
#include "reference.cuh"
#include <iostream>
output_t custom_kernel(input_t data)
{
for(int i = 0; i < 10000; ++i) {
std::cout << "blah blah\\n";
}
return data;
}
"""

comp, run = run_cuda_script(
{"eval.cu": cu_eval}, {"reference.cuh": ref.read_text(), "submission.cuh": sub}, arch=None
)
assert run.success
assert len(run.stdout) < 16384
assert "[...]" in run.stdout

sub = sub.replace("std::cout", "std::cerr")

comp, run = run_cuda_script(
{"eval.cu": cu_eval}, {"reference.cuh": ref.read_text(), "submission.cuh": sub}, arch=None
)
assert run.success
assert len(run.stderr) < 16384
assert "[...]" in run.stderr
26 changes: 26 additions & 0 deletions scripts/ci_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,29 @@ def test_correct():
assert "warming up..." in run.stdout
assert run.exit_code == ExitCode.SUCCESS
assert run.result["check"] == "pass"


def test_huge_output():
sub = """
import sys
def custom_kernel(input):
print("blah blah\\n" * 10000, file=sys.stdout)
return input
"""
run = run_pytorch_script(
{"eval.py": py_eval, "reference.py": ref.read_text(), "submission.py": sub},
"eval.py",
)
assert run.success
assert len(run.stdout) < 16384
assert "[...]" in run.stdout

sub = sub.replace("sys.stdout", "sys.stderr")

run = run_pytorch_script(
{"eval.py": py_eval, "reference.py": ref.read_text(), "submission.py": sub},
"eval.py",
)
assert run.success
assert len(run.stderr) < 16384
assert "[...]" in run.stderr
27 changes: 19 additions & 8 deletions src/discord-cluster-manager/run_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ def _make_cmd(args: list[str]):
return " ".join(map(shlex.quote, args))


def _limit_length(text: str, max_len: int = 16384):
lines = text.split("\n")
size = 0
for i, line in enumerate(lines):
size += len(line) + 1
if size + 100 > max_len:
lines = lines[:i] + [f"[...] {len(lines)-i} lines omitted"]
return "\n".join(lines)
return text


def compile_cuda_script( # # noqa: C901
files: list[str],
arch: int = None,
Expand Down Expand Up @@ -88,8 +99,8 @@ def compile_cuda_script( # # noqa: C901
success=False,
nvcc_version="",
command=_make_cmd(e.cmd),
stdout=e.stdout,
stderr=e.stderr,
stdout=_limit_length(e.stdout),
stderr=_limit_length(e.stderr),
exit_code=e.returncode,
)

Expand All @@ -109,8 +120,8 @@ def compile_cuda_script( # # noqa: C901
success=False,
nvcc_version=nvcc_version,
command=_make_cmd(e.cmd),
stdout=e.stdout,
stderr=e.stderr,
stdout=_limit_length(e.stdout),
stderr=_limit_length(e.stderr),
exit_code=e.returncode,
)

Expand All @@ -119,8 +130,8 @@ def compile_cuda_script( # # noqa: C901
success=True,
nvcc_version=nvcc_version,
command=_make_cmd(compile_process.args),
stdout=compile_process.stdout,
stderr=compile_process.stderr,
stdout=_limit_length(compile_process.stdout),
stderr=_limit_length(compile_process.stderr),
exit_code=compile_process.returncode,
)

Expand Down Expand Up @@ -161,8 +172,8 @@ def run_program(args: list[str], seed: int) -> RunResult:
),
passed=result_dict.get("check", None) == "pass",
command=_make_cmd(run_process.args),
stdout=run_process.stdout,
stderr=run_process.stderr,
stdout=_limit_length(run_process.stdout),
stderr=_limit_length(run_process.stderr),
exit_code=run_process.returncode,
duration=execution_end_time - execution_start_time,
result=result_dict,
Expand Down
Loading