File size: 2,339 Bytes
9d945e1 | 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 | """Step-0 GPU chain, run INSIDE the Colab kernel (colab exec -f) so the kernel stays busy and Colab does not reclaim
the runtime as idle (a detached background job let the first VM be reclaimed after ~30 min of kernel idleness).
Order (one GPU job at a time): setup -> ADM reference batch -> SiT S/B/L/XL at N=4000 with ADM eval -> JiT GPU check.
Every step is resumable through the .done markers (local or Drive).
"""
import os
import subprocess
import sys
import time
CODE, LOGS = "/content/set5/code", "/content/set5/logs"
os.makedirs(LOGS, exist_ok=True)
sys.path.insert(0, CODE)
env = dict(os.environ, PYTHONUNBUFFERED="1", PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True")
def step(name, cmd, log):
t0 = time.time()
print(time.strftime("%H:%M:%S"), "start", name, flush=True)
with open(f"{LOGS}/{log}", "a") as f:
p = subprocess.Popen(cmd, shell=True, cwd=CODE, env=env, stdout=f, stderr=subprocess.STDOUT)
while p.poll() is None:
time.sleep(60)
last = subprocess.run(f"grep -a '^[0-9][0-9]:' {LOGS}/{log} | tail -1", shell=True, capture_output=True,
text=True).stdout.strip()
print(time.strftime("%H:%M:%S"), name, "|", last[:150], flush=True)
print(time.strftime("%H:%M:%S"), "end", name, "rc", p.returncode, f"{(time.time()-t0)/60:.1f} min", flush=True)
return p.returncode
print(subprocess.run("nvidia-smi --query-gpu=name,memory.total --format=csv,noheader; df -h /content | tail -1",
shell=True, capture_output=True, text=True).stdout, flush=True)
step("pip", f"{sys.executable} -m pip install -q torchdiffeq diffusers timm", "setup.log")
step("adm-ref", "mkdir -p /content/set5/fid && cd /content/set5/fid && "
"([ -f ref.sha256 ] || (curl -sSfL --retry 5 -o VIRTUAL_imagenet256_labeled.npz "
"https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/256/"
"VIRTUAL_imagenet256_labeled.npz && sha256sum VIRTUAL_imagenet256_labeled.npz > ref.sha256))", "setup.log")
rc = step("sit", "FID_N=4000 python s0a_sit.py S,B,L,XL", "s0a_sit.log")
step("jit-gpu", "python s0b_jit.py gpu", "s0b_gpu.log")
import common5 # noqa: E402
print("synced to Drive:", common5.sync_out(), flush=True)
print(time.strftime("%H:%M:%S"), "STEP0 CHAIN FINISHED", flush=True)
|