Spaces:
Running
Running
fix: make real AI smoke wait for model output
Browse files- scripts/smoke_local_ai.py +20 -7
- tests/test_ai_smoke.py +6 -4
scripts/smoke_local_ai.py
CHANGED
|
@@ -67,12 +67,20 @@ def stop_canary(canary: subprocess.Popen[bytes]) -> None:
|
|
| 67 |
canary.wait(timeout=3)
|
| 68 |
|
| 69 |
|
| 70 |
-
def generated(path: Path) -> bool:
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
def one_smoke(*, runner: Path, model: Path, provenance: dict[str, Any], index: int) -> dict[str, Any]:
|
| 75 |
-
prompt = "Explain one safe property of a Linux cgroup in
|
| 76 |
with tempfile.TemporaryDirectory(prefix="lumi-eggcracker-ai-smoke-", dir="/tmp") as raw:
|
| 77 |
root = Path(raw)
|
| 78 |
output, diagnostics, receipt_path = root / "generated.txt", root / "runner.stderr", root / "receipt.json"
|
|
@@ -88,12 +96,17 @@ def one_smoke(*, runner: Path, model: Path, provenance: dict[str, Any], index: i
|
|
| 88 |
started: dict[str, Any] | None = None
|
| 89 |
contained = False
|
| 90 |
try:
|
| 91 |
-
runner_argv = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
started = call(["start", "--name", name, "--max-pids", "64", "--", "/usr/bin/python3", str(WORKER), "--stdout", str(output), "--stderr", str(diagnostics), "--", *runner_argv])
|
| 93 |
-
deadline = time.monotonic() +
|
| 94 |
-
while time.monotonic() < deadline and not generated(output):
|
| 95 |
time.sleep(0.05)
|
| 96 |
-
if not generated(output):
|
| 97 |
raise RuntimeError("real AI workload did not produce 32 bytes of generated output")
|
| 98 |
status = call(["status", "--name", name])
|
| 99 |
if status.get("state") != "RUNNING":
|
|
|
|
| 67 |
canary.wait(timeout=3)
|
| 68 |
|
| 69 |
|
| 70 |
+
def generated(path: Path, prompt: str) -> bool:
|
| 71 |
+
if not path.is_file() or path.is_symlink():
|
| 72 |
+
return False
|
| 73 |
+
marker = f"\n> {prompt}\n".encode("utf-8")
|
| 74 |
+
output = path.read_bytes()
|
| 75 |
+
position = output.find(marker)
|
| 76 |
+
# llama-cli writes its startup banner before the prompt. Requiring text
|
| 77 |
+
# after the echoed prompt proves model output, rather than merely output
|
| 78 |
+
# from loading the binary or model metadata.
|
| 79 |
+
return position >= 0 and len(output) - (position + len(marker)) >= 32
|
| 80 |
|
| 81 |
|
| 82 |
def one_smoke(*, runner: Path, model: Path, provenance: dict[str, Any], index: int) -> dict[str, Any]:
|
| 83 |
+
prompt = "Explain one safe property of a Linux cgroup in one sentence."
|
| 84 |
with tempfile.TemporaryDirectory(prefix="lumi-eggcracker-ai-smoke-", dir="/tmp") as raw:
|
| 85 |
root = Path(raw)
|
| 86 |
output, diagnostics, receipt_path = root / "generated.txt", root / "runner.stderr", root / "receipt.json"
|
|
|
|
| 96 |
started: dict[str, Any] | None = None
|
| 97 |
contained = False
|
| 98 |
try:
|
| 99 |
+
runner_argv = [
|
| 100 |
+
"/usr/bin/stdbuf", "-o0", "-e0", str(runner), "-m", str(model),
|
| 101 |
+
"-p", prompt, "-n", "512", "-t", "12", "-tb", "12", "-c", "512",
|
| 102 |
+
"--simple-io", "--single-turn", "--no-warmup", "--no-display-prompt",
|
| 103 |
+
"--seed", "1234",
|
| 104 |
+
]
|
| 105 |
started = call(["start", "--name", name, "--max-pids", "64", "--", "/usr/bin/python3", str(WORKER), "--stdout", str(output), "--stderr", str(diagnostics), "--", *runner_argv])
|
| 106 |
+
deadline = time.monotonic() + 120
|
| 107 |
+
while time.monotonic() < deadline and not generated(output, prompt):
|
| 108 |
time.sleep(0.05)
|
| 109 |
+
if not generated(output, prompt):
|
| 110 |
raise RuntimeError("real AI workload did not produce 32 bytes of generated output")
|
| 111 |
status = call(["status", "--name", name])
|
| 112 |
if status.get("state") != "RUNNING":
|
tests/test_ai_smoke.py
CHANGED
|
@@ -48,10 +48,12 @@ class AiSmokeTests(unittest.TestCase):
|
|
| 48 |
def test_generated_output_requires_visible_content(self) -> None:
|
| 49 |
with tempfile.TemporaryDirectory() as raw:
|
| 50 |
output = Path(raw) / "generated.txt"
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
def test_prepare_script_keeps_external_asset_inputs_pinned(self) -> None:
|
| 57 |
self.assertEqual("b10240", prepare.LLAMA_TAG)
|
|
|
|
| 48 |
def test_generated_output_requires_visible_content(self) -> None:
|
| 49 |
with tempfile.TemporaryDirectory() as raw:
|
| 50 |
output = Path(raw) / "generated.txt"
|
| 51 |
+
prompt = "test prompt"
|
| 52 |
+
output.write_bytes(b"startup output\n> test prompt\n" + b"x" * 31)
|
| 53 |
+
self.assertFalse(smoke.generated(output, prompt))
|
| 54 |
+
output.write_bytes(b"startup output\n> test prompt\n" + b"x" * 32)
|
| 55 |
+
self.assertTrue(smoke.generated(output, prompt))
|
| 56 |
+
self.assertFalse(smoke.generated(output, "other prompt"))
|
| 57 |
|
| 58 |
def test_prepare_script_keeps_external_asset_inputs_pinned(self) -> None:
|
| 59 |
self.assertEqual("b10240", prepare.LLAMA_TAG)
|