fix: fremde GPU-Belegung vor dem Start messen (#1275)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 15:24:38 +01:00
parent 8a34ab835b
commit 2b434b914b
4 changed files with 109 additions and 33 deletions

View File

@ -4,15 +4,17 @@
Voraussetzung: remote.sh prepare, Tunnel `ssh -f -N -L 18100:127.0.0.1:18100 srv04`. Startet die Testinstanz selbst neu.
Aufruf: block_cdg.py ERGEBNIS.jsonl [c g d7 d6] Keine Antworttexte, kein Key in der Ausgabe.
"""
import collections, json, random, statistics, subprocess, sys, threading, time, urllib.request
import collections, json, os, random, shlex, statistics, subprocess, sys, threading, time, urllib.request
import openai
BASE = "http://127.0.0.1:18100"
REMOTE = "bash /tmp/nexus-kern/remote.sh"
GRENZE = 12288 - 512
# Falls der Name nicht auflöst: NEXUS_SSH_OPTS="-o HostName=ADRESSE -o HostKeyAlias=srv04"
SSH = ["ssh", "-o", "BatchMode=yes", *shlex.split(os.environ.get("NEXUS_SSH_OPTS", "")), "srv04"]
def ssh(cmd, timeout=120):
return subprocess.run(["ssh", "-o", "BatchMode=yes", "srv04", cmd], capture_output=True, text=True, timeout=timeout).stdout.strip()
return subprocess.run([*SSH, cmd], capture_output=True, text=True, timeout=timeout).stdout.strip()
KEY = ssh("cat /tmp/nexus-kern/key")
client = openai.OpenAI(base_url=BASE + "/v1", api_key=KEY, max_retries=0, timeout=400)
@ -34,7 +36,7 @@ class Monitor:
"""Beobachtet Buchungen (alle 2 s) und die echte GPU-Belegung."""
def __init__(self):
self.stop = threading.Event(); self.max_booked = [0, 0]; self.max_gpu = [0, 0]; self.verstoss = []; self.max_wartend = 0; self.n = 0
self.smi = subprocess.Popen(["ssh", "-o", "BatchMode=yes", "srv04", "timeout 1200 nvidia-smi --query-gpu=index,memory.used --format=csv,noheader,nounits -l 2"], stdout=subprocess.PIPE, text=True)
self.smi = subprocess.Popen([*SSH, "timeout 1200 nvidia-smi --query-gpu=index,memory.used --format=csv,noheader,nounits -l 2"], stdout=subprocess.PIPE, text=True)
self.t = [threading.Thread(target=self.st, daemon=True), threading.Thread(target=self.gp, daemon=True)]
for t in self.t: t.start()
def st(self):
@ -99,7 +101,7 @@ for l in open("/tmp/nexus-kern/serve.log"):
if e and e!="zugeteilt": c[e+" "+str(d.get("model") or d.get("modell") or "")]+=1
if d.get("level")=="ERROR" or (d.get("level")=="WARN" and d.get("message")!="Anfrage beantwortet"): w[d.get("message","")[:120]]+=1
print(json.dumps({"ereignisse":dict(c),"warnungen":dict(w)}))'''
p = subprocess.run(["ssh", "-o", "BatchMode=yes", "srv04", "python3 -I -"], input=prog, capture_output=True, text=True, timeout=60)
p = subprocess.run([*SSH, "python3 -I -"], input=prog, capture_output=True, text=True, timeout=60)
return json.loads(p.stdout or "{}")
def ruhe():
@ -132,7 +134,7 @@ def block_vergleich(emit, fristen=(60, 0)):
modelle = ["bonsai", "darkidol", "ollama-gemma3-4b", "erebus", "cydonia"]
for frist in fristen:
restart("idle_secs = 600", f"evict_min_idle_secs = {frist}")
smi = subprocess.Popen(["ssh", "-o", "BatchMode=yes", "srv04", "timeout 600 nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -l 2"], stdout=subprocess.PIPE, text=True)
smi = subprocess.Popen([*SSH, "timeout 600 nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -l 2"], stdout=subprocess.PIPE, text=True)
werte = []
leser = threading.Thread(target=lambda: werte.extend(int(x) for x in smi.stdout if x.strip().isdigit())); leser.start()
random.seed(1263); start = time.time(); mon = Monitor()