gnn_wm2 / Ctrl-World-Graph /scripts /run_eval_after_train.py
EndeavourDD's picture
Upload folder using huggingface_hub (part 17)
f15a766 verified
Raw
History Blame Contribute Delete
1.75 kB
from __future__ import annotations
import os
import subprocess
import time
from datetime import datetime, timezone
from pathlib import Path
ROOT = Path("/workspace/Ctrl-World-Graph")
LOG_PATH = ROOT / "logs" / "eval_graph_video_after_train.log"
TRAIN_PID = 2619263
def timestamp() -> str:
return datetime.now(timezone.utc).isoformat()
def log(message: str) -> None:
with LOG_PATH.open("a", encoding="utf-8") as f:
f.write(f"[{timestamp()}] {message}\n")
f.flush()
def pid_alive(pid: int) -> bool:
try:
os.kill(pid, 0)
return True
except ProcessLookupError:
return False
def latest_checkpoint() -> Path:
checkpoints = sorted(
(ROOT / "model_ckpt" / "ctrl_world_graph").glob("checkpoint-*.pt"),
key=lambda p: int(p.stem.split("-")[-1]),
)
if not checkpoints:
raise FileNotFoundError("No checkpoints found")
return checkpoints[-1]
def main() -> None:
while pid_alive(TRAIN_PID):
log(f"waiting for train pid {TRAIN_PID}")
time.sleep(60)
ckpt = latest_checkpoint()
log(f"running eval with {ckpt}")
env = os.environ.copy()
env["CUDA_VISIBLE_DEVICES"] = "0"
env["PYTHONUNBUFFERED"] = "1"
with LOG_PATH.open("a", encoding="utf-8") as f:
subprocess.run(
[
"python",
"-u",
"scripts/eval_graph_video.py",
"--ckpt-path",
str(ckpt),
"--sample-index",
"0",
],
cwd=str(ROOT),
env=env,
stdout=f,
stderr=subprocess.STDOUT,
check=False,
)
log("eval done")
if __name__ == "__main__":
main()