File size: 1,113 Bytes
c8420ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Kernel cell (piped to `colab exec`): installs pip deps, starts pilot.py detached if it is not running, then prints the
# latest log line once a minute until it ends, so Colab sees a busy kernel for the whole job (one GPU job at a time).
import os
import subprocess
import time

LOG = "/content/set5/logs/pilot.log"
os.makedirs("/content/set5/logs", exist_ok=True)


def running():
    return subprocess.run(["pgrep", "-f", "python pilot.py"], capture_output=True).returncode == 0


if not running():
    subprocess.run("pip install -q diffusers timm torchdiffeq h5py >> /content/set5/logs/pip.log 2>&1", shell=True)
    subprocess.Popen(f"cd /content/set5/code && nohup python pilot.py >> {LOG} 2>&1 &", shell=True)
    time.sleep(15)
while running():
    last = subprocess.run(f"tail -n 1 {LOG}", shell=True, capture_output=True, text=True).stdout.strip()
    print(time.strftime("%H:%M:%S"), last[:160], flush=True)
    time.sleep(60)
print(time.strftime("%H:%M:%S"), "PILOT PROCESS ENDED", flush=True)
print(subprocess.run(f"tail -n 15 {LOG}", shell=True, capture_output=True, text=True).stdout, flush=True)