File size: 1,748 Bytes
f15a766
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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()