Record memory, disk and GPU use with every log upload; use the built-in sampler
Browse files- scripts/launch.py +8 -1
- scripts/pipeline.sh +6 -0
- scripts/sync.py +13 -0
- scripts/sysstats.py +104 -0
scripts/launch.py
CHANGED
|
@@ -66,7 +66,7 @@ def alive(pidfile):
|
|
| 66 |
|
| 67 |
|
| 68 |
def status(root):
|
| 69 |
-
print(f"working folder : {root} ({shutil.disk_usage(root).
|
| 70 |
print(f"supervisor : {'running' if alive(root / 'supervisor.pid') else 'not running'}")
|
| 71 |
try:
|
| 72 |
print("GPU :", subprocess.run(["nvidia-smi", "--query-gpu=name,memory.used,memory.total,utilization.gpu",
|
|
@@ -74,6 +74,13 @@ def status(root):
|
|
| 74 |
timeout=20).stdout.strip())
|
| 75 |
except Exception: # noqa: BLE001
|
| 76 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
done = sorted(p.stem for p in (root / "state").glob("*.done"))
|
| 78 |
failed = sorted(p.stem for p in (root / "state").glob("*.failed"))
|
| 79 |
print("stages done :", " ".join(done) or "-")
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def status(root):
|
| 69 |
+
print(f"working folder : {root} ({shutil.disk_usage(root).used / 1e9:.0f} GB used)")
|
| 70 |
print(f"supervisor : {'running' if alive(root / 'supervisor.pid') else 'not running'}")
|
| 71 |
try:
|
| 72 |
print("GPU :", subprocess.run(["nvidia-smi", "--query-gpu=name,memory.used,memory.total,utilization.gpu",
|
|
|
|
| 74 |
timeout=20).stdout.strip())
|
| 75 |
except Exception: # noqa: BLE001
|
| 76 |
pass
|
| 77 |
+
stats = root / "repo" / "scripts" / "sysstats.py"
|
| 78 |
+
if stats.exists():
|
| 79 |
+
try:
|
| 80 |
+
print("machine :", subprocess.run([sys.executable, str(stats), str(root)], capture_output=True,
|
| 81 |
+
text=True, timeout=60).stdout.strip())
|
| 82 |
+
except Exception: # noqa: BLE001
|
| 83 |
+
pass
|
| 84 |
done = sorted(p.stem for p in (root / "state").glob("*.done"))
|
| 85 |
failed = sorted(p.stem for p in (root / "state").glob("*.failed"))
|
| 86 |
print("stages done :", " ".join(done) or "-")
|
scripts/pipeline.sh
CHANGED
|
@@ -22,16 +22,20 @@ export UV_CACHE_DIR="$EMC_ROOT/uv-cache" UV_PYTHON_INSTALL_DIR="$EMC_ROOT/uv-pyt
|
|
| 22 |
export EMC2_HOME="$KIT" EMC_RESULTS="$RESULTS"
|
| 23 |
export XDG_CACHE_HOME="$WORK/cache" VLLM_CACHE_ROOT="$WORK/cache/vllm" VLLM_NO_USAGE_STATS=1 DO_NOT_TRACK=1
|
| 24 |
export TORCHINDUCTOR_CACHE_DIR="$WORK/cache/inductor" TRITON_CACHE_DIR="$WORK/cache/triton"
|
|
|
|
|
|
|
| 25 |
[ -f "$STATE/run_id" ] || echo "${RUN_ID:-$(date +%Y%m%d-%H%M)}" > "$STATE/run_id"
|
| 26 |
|
| 27 |
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOGS/pipeline.log"; }
|
| 28 |
sync_hf() { if [ -x "$PY" ]; then "$PY" "$REPO/scripts/sync.py" "$@" >> "$LOGS/sync.log" 2>&1 || true; fi; }
|
| 29 |
is_done() { [ -f "$STATE/$1.done" ]; }
|
|
|
|
| 30 |
|
| 31 |
stage() { # stage <name> <required: 0|1> <function>
|
| 32 |
local name=$1 required=$2 fn=$3 t0=$SECONDS rc
|
| 33 |
if is_done "$name"; then log "skip $name (done)"; return 0; fi
|
| 34 |
log "start $name"
|
|
|
|
| 35 |
( set -e; "$fn" ) > "$LOGS/$name.log" 2>&1
|
| 36 |
rc=$?
|
| 37 |
if [ "$rc" = 0 ]; then
|
|
@@ -132,6 +136,8 @@ s_eval_alt() {
|
|
| 132 |
s_report() { "$PY" "$REPO/scripts/collect.py"; }
|
| 133 |
|
| 134 |
log "pipeline start: run $(cat "$STATE/run_id"), code $(cat "$REPO/.commit" 2>/dev/null | cut -c1-12)"
|
|
|
|
|
|
|
| 135 |
stage env 1 s_env
|
| 136 |
stage download 1 s_download
|
| 137 |
stage baseline 1 s_baseline
|
|
|
|
| 22 |
export EMC2_HOME="$KIT" EMC_RESULTS="$RESULTS"
|
| 23 |
export XDG_CACHE_HOME="$WORK/cache" VLLM_CACHE_ROOT="$WORK/cache/vllm" VLLM_NO_USAGE_STATS=1 DO_NOT_TRACK=1
|
| 24 |
export TORCHINDUCTOR_CACHE_DIR="$WORK/cache/inductor" TRITON_CACHE_DIR="$WORK/cache/triton"
|
| 25 |
+
# greedy decoding only: use the built-in sampler instead of compiling FlashInfer kernels at start-up
|
| 26 |
+
export VLLM_USE_FLASHINFER_SAMPLER=0
|
| 27 |
[ -f "$STATE/run_id" ] || echo "${RUN_ID:-$(date +%Y%m%d-%H%M)}" > "$STATE/run_id"
|
| 28 |
|
| 29 |
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOGS/pipeline.log"; }
|
| 30 |
sync_hf() { if [ -x "$PY" ]; then "$PY" "$REPO/scripts/sync.py" "$@" >> "$LOGS/sync.log" 2>&1 || true; fi; }
|
| 31 |
is_done() { [ -f "$STATE/$1.done" ]; }
|
| 32 |
+
stats() { if [ -x "$PY" ]; then "$PY" "$REPO/scripts/sysstats.py" "$EMC_ROOT" >> "$LOGS/stats.log" 2>/dev/null || true; fi; }
|
| 33 |
|
| 34 |
stage() { # stage <name> <required: 0|1> <function>
|
| 35 |
local name=$1 required=$2 fn=$3 t0=$SECONDS rc
|
| 36 |
if is_done "$name"; then log "skip $name (done)"; return 0; fi
|
| 37 |
log "start $name"
|
| 38 |
+
stats
|
| 39 |
( set -e; "$fn" ) > "$LOGS/$name.log" 2>&1
|
| 40 |
rc=$?
|
| 41 |
if [ "$rc" = 0 ]; then
|
|
|
|
| 136 |
s_report() { "$PY" "$REPO/scripts/collect.py"; }
|
| 137 |
|
| 138 |
log "pipeline start: run $(cat "$STATE/run_id"), code $(cat "$REPO/.commit" 2>/dev/null | cut -c1-12)"
|
| 139 |
+
# a vLLM server left behind by an interrupted run would still hold the GPU
|
| 140 |
+
if pkill -f -- "--served-model-name target" 2>/dev/null; then log "stopped a leftover vLLM server"; sleep 20; fi
|
| 141 |
stage env 1 s_env
|
| 142 |
stage download 1 s_download
|
| 143 |
stage baseline 1 s_baseline
|
scripts/sync.py
CHANGED
|
@@ -55,7 +55,20 @@ def scrub_copy(src: Path, dst: Path):
|
|
| 55 |
shutil.copy(src, dst)
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def main():
|
|
|
|
| 59 |
tok = token()
|
| 60 |
if not tok:
|
| 61 |
print("no Hugging Face token: skipping upload")
|
|
|
|
| 55 |
shutil.copy(src, dst)
|
| 56 |
|
| 57 |
|
| 58 |
+
def record_stats():
|
| 59 |
+
"""Append a machine snapshot (memory, disk, GPU) to logs/stats.log; never blocks an upload."""
|
| 60 |
+
try:
|
| 61 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 62 |
+
from sysstats import snapshot
|
| 63 |
+
(ROOT / "logs").mkdir(parents=True, exist_ok=True)
|
| 64 |
+
with open(ROOT / "logs" / "stats.log", "a") as f:
|
| 65 |
+
f.write(snapshot(ROOT) + "\n")
|
| 66 |
+
except Exception as e: # noqa: BLE001
|
| 67 |
+
print(f"machine stats unavailable: {e}")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
def main():
|
| 71 |
+
record_stats()
|
| 72 |
tok = token()
|
| 73 |
if not tok:
|
| 74 |
print("no Hugging Face token: skipping upload")
|
scripts/sysstats.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""One-line snapshot of the machine: memory, disk, GPU, load and the largest processes.
|
| 3 |
+
|
| 4 |
+
Standard library only. Shown by the status view of the launch cell and appended to
|
| 5 |
+
logs/stats.log by every log upload, so memory use can be followed over the whole run.
|
| 6 |
+
|
| 7 |
+
python sysstats.py [root]
|
| 8 |
+
"""
|
| 9 |
+
import os
|
| 10 |
+
import shutil
|
| 11 |
+
import subprocess
|
| 12 |
+
import sys
|
| 13 |
+
import time
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
GB = 1e9
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def meminfo():
|
| 20 |
+
info = {}
|
| 21 |
+
try:
|
| 22 |
+
for line in Path("/proc/meminfo").read_text().splitlines():
|
| 23 |
+
key, value = line.split(":", 1)
|
| 24 |
+
info[key] = int(value.split()[0]) * 1024
|
| 25 |
+
except (OSError, ValueError, IndexError):
|
| 26 |
+
pass
|
| 27 |
+
return info
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def cgroup_memory():
|
| 31 |
+
"""(used, limit or None) of the container's memory cgroup, when it is visible."""
|
| 32 |
+
for cur, lim in (("/sys/fs/cgroup/memory.current", "/sys/fs/cgroup/memory.max"),
|
| 33 |
+
("/sys/fs/cgroup/memory/memory.usage_in_bytes",
|
| 34 |
+
"/sys/fs/cgroup/memory/memory.limit_in_bytes")):
|
| 35 |
+
try:
|
| 36 |
+
used = int(Path(cur).read_text())
|
| 37 |
+
raw = Path(lim).read_text().strip()
|
| 38 |
+
return used, (None if raw == "max" or int(raw) >= 1 << 60 else int(raw))
|
| 39 |
+
except (OSError, ValueError):
|
| 40 |
+
continue
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def top_processes(n=3):
|
| 45 |
+
procs = []
|
| 46 |
+
try:
|
| 47 |
+
entries = list(Path("/proc").iterdir())
|
| 48 |
+
except OSError:
|
| 49 |
+
return procs
|
| 50 |
+
for d in entries:
|
| 51 |
+
if not d.name.isdigit():
|
| 52 |
+
continue
|
| 53 |
+
try:
|
| 54 |
+
name, rss = None, 0
|
| 55 |
+
for line in (d / "status").read_text().splitlines():
|
| 56 |
+
if line.startswith("Name:"):
|
| 57 |
+
name = line.split(None, 1)[1].strip()
|
| 58 |
+
elif line.startswith("VmRSS:"):
|
| 59 |
+
rss = int(line.split()[1]) * 1024
|
| 60 |
+
if name and rss:
|
| 61 |
+
procs.append((rss, name))
|
| 62 |
+
except (OSError, ValueError, IndexError):
|
| 63 |
+
continue
|
| 64 |
+
return sorted(procs, reverse=True)[:n]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def gpu():
|
| 68 |
+
try:
|
| 69 |
+
out = subprocess.run(["nvidia-smi", "--query-gpu=memory.used,memory.total,utilization.gpu,power.draw",
|
| 70 |
+
"--format=csv,noheader,nounits"], capture_output=True, text=True, timeout=15).stdout
|
| 71 |
+
used, total, util, power = (x.strip() for x in out.splitlines()[0].split(","))
|
| 72 |
+
return f"gpu {float(used) / 1024:.1f}/{float(total) / 1024:.1f} GiB, {util}%, {float(power):.0f} W"
|
| 73 |
+
except Exception: # noqa: BLE001 - no GPU tool, no line
|
| 74 |
+
return "gpu n/a"
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def snapshot(root):
|
| 78 |
+
parts = []
|
| 79 |
+
m = meminfo()
|
| 80 |
+
if m.get("MemTotal"):
|
| 81 |
+
used = m["MemTotal"] - m.get("MemAvailable", m.get("MemFree", 0))
|
| 82 |
+
parts.append(f"ram {used / GB:.1f}/{m['MemTotal'] / GB:.0f} GB used "
|
| 83 |
+
f"(cache {m.get('Cached', 0) / GB:.1f}, shmem {m.get('Shmem', 0) / GB:.1f})")
|
| 84 |
+
cg = cgroup_memory()
|
| 85 |
+
if cg:
|
| 86 |
+
parts.append(f"cgroup {cg[0] / GB:.1f}" + (f"/{cg[1] / GB:.0f} GB" if cg[1] else " GB (no limit)"))
|
| 87 |
+
try:
|
| 88 |
+
parts.append(f"disk {shutil.disk_usage(root).used / GB:.0f} GB used")
|
| 89 |
+
except OSError:
|
| 90 |
+
pass
|
| 91 |
+
parts.append(gpu())
|
| 92 |
+
try:
|
| 93 |
+
parts.append(f"load {os.getloadavg()[0]:.1f}")
|
| 94 |
+
except (OSError, AttributeError): # no load average on this system
|
| 95 |
+
pass
|
| 96 |
+
top = top_processes()
|
| 97 |
+
if top:
|
| 98 |
+
parts.append("largest " + ", ".join(f"{name} {rss / GB:.1f} GB" for rss, name in top))
|
| 99 |
+
return f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] " + " | ".join(parts)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
if __name__ == "__main__":
|
| 103 |
+
print(snapshot(Path(sys.argv[1]) if len(sys.argv) > 1
|
| 104 |
+
else Path(os.environ.get("EMC_ROOT", str(Path.home() / "emc")))))
|