Skip to content
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
5 changes: 5 additions & 0 deletions autotune/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def run(self, config_path: Path | str, run_id: str) -> RunResult:
failure_reason: Optional[str] = None
with open(stdout_path, "w") as stdout_file:
stdout_file.write(f"autotune: command: {' '.join(shlex.quote(part) for part in cmd)}\n")
stdout_file.flush()
try:
proc = subprocess.run(
cmd,
Expand Down Expand Up @@ -143,4 +144,8 @@ def _find_report(expected_path: Path) -> Optional[Path]:
candidate = expected_path.parent / name
if candidate.exists():
return candidate
for name in REPORT_CANDIDATES:
candidates = sorted(expected_path.parent.glob(f"*/{name}"))
if candidates:
return candidates[-1]
return None
31 changes: 31 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_run_returns_failed_result_when_command_exits_nonzero(tmp_path):
assert result.returncode == 7
assert result.stdout_path.exists()
log = result.stdout_path.read_text()
assert log.splitlines()[0].startswith("autotune: command:")
assert "backend exploded" in log
assert "autotune: CloudAI exited with code 7" in log
assert result.failure_reason == "CloudAI exited with code 7"
Expand Down Expand Up @@ -115,6 +116,36 @@ def test_run_prefers_cloudai_summary_report(tmp_path):
assert result.report_path == tmp_path / "0006_test" / "cloudai-summary.json"


def test_run_detects_cloudai_summary_in_scenario_output_directory(tmp_path):
script = tmp_path / "fake_cloudai.sh"
script.write_text(
"#!/bin/sh\n"
"out=''\n"
"while [ \"$#\" -gt 0 ]; do\n"
" if [ \"$1\" = '--output-dir' ]; then\n"
" shift\n"
" out=\"$1\"\n"
" fi\n"
" shift\n"
"done\n"
"mkdir -p \"$out/scenario_timestamp\"\n"
"printf '{\"metrics\":{\"throughput_tokens_per_sec\": 123}}' "
"> \"$out/scenario_timestamp/cloudai-summary.json\"\n"
)
script.chmod(0o755)
runner = CloudAIRunner(
cloudai_bin=str(script),
runs_dir=tmp_path,
dry_run=True,
system_config=tmp_path / "system.toml",
)

result = runner.run(tmp_path / "config.toml", "0007_test")

assert result.succeeded
assert result.report_path == tmp_path / "0007_test" / "scenario_timestamp" / "cloudai-summary.json"


def test_command_string_uses_current_cloudai_cli_when_system_config_is_set(tmp_path):
runner = CloudAIRunner(
cloudai_bin="cloudai",
Expand Down