fix(m0): retry failed LLM starts and never measure a foreign server
- A Strata install or start that never reached a server is saved as "failed" (not "partial"), so the next run retries the stage. - A launch that exits non-zero is not ready, even if something answers on the port afterwards. - Before the cold start, the stage stops if another program already listens on port 8080 and tells the user to close it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
@@ -121,7 +122,9 @@ class Strata:
|
||||
rc = run_logged(self.cmd("launch", *args), self.log, timeout=timeout, env=self.env, echo=True,
|
||||
echo_filter=progress)
|
||||
t_cmd = time.perf_counter() - t0
|
||||
ready = wait_ready(f"http://127.0.0.1:{PORT}", timeout=1800 if rc == 0 else 30)
|
||||
# Only a successful launch counts: after a failed one, whatever still
|
||||
# answers on the port is not the model that was asked for.
|
||||
ready = wait_ready(f"http://127.0.0.1:{PORT}", timeout=1800) if rc == 0 else None
|
||||
return {"args": scrub(" ".join(args)), "dropped_flags": dropped, "exit": rc,
|
||||
"command_seconds": round(t_cmd, 1), "ready": ready is not None,
|
||||
"ready_seconds": round(time.perf_counter() - t0, 1) if ready is not None else None}
|
||||
@@ -139,6 +142,12 @@ class Strata:
|
||||
return scrub(p.stdout[-2000:])
|
||||
|
||||
|
||||
def port_in_use(port: int) -> bool:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.settimeout(2)
|
||||
return sock.connect_ex(("127.0.0.1", port)) == 0
|
||||
|
||||
|
||||
def wait_ready(root: str, timeout: float) -> float | None:
|
||||
t0 = time.perf_counter()
|
||||
while time.perf_counter() - t0 < timeout:
|
||||
@@ -185,6 +194,10 @@ def measure_strata(r: StageResult, work: Path, which: str, context: int) -> None
|
||||
# 1) Start (the first start downloads the model and engine).
|
||||
say(f" {preset['label']} 시작 중. 처음에는 모델을 내려받으므로 오래 걸립니다.")
|
||||
s.stop()
|
||||
if port_in_use(PORT):
|
||||
# Another program owns the port; measuring it would report the wrong model.
|
||||
r.error("port", f"다른 프로그램이 {PORT} 포트를 쓰고 있습니다. 그 프로그램을 끄고 다시 실행해 주세요.")
|
||||
return
|
||||
with GpuSampler(interval=2) as g:
|
||||
r["launch_cold"] = s.launch(preset, context, parallel=1)
|
||||
r["launch_cold"].update(g.summary())
|
||||
@@ -237,7 +250,11 @@ def main() -> int:
|
||||
measure_strata(r, work, which, context)
|
||||
except Exception as e:
|
||||
r.error("llm", e)
|
||||
r.save("ok" if not r["errors"] else "partial")
|
||||
# No server reached means nothing was measured: "failed" so the next run retries it.
|
||||
if "server" not in r.data:
|
||||
r.save("failed")
|
||||
else:
|
||||
r.save("ok" if not r["errors"] else "partial")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user