Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
120
scripts/srv04-kern-test/block_ab.py
Normal file
120
scripts/srv04-kern-test/block_ab.py
Normal file
@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Kernprüfung Block A und B (#1263): läuft auf dem Entwicklungsrechner gegen die Testinstanz auf srv04.
|
||||
|
||||
Voraussetzung: remote.sh prepare und start, Tunnel `ssh -f -N -L 18100:127.0.0.1:18100 srv04`.
|
||||
Aufruf: block_ab.py ERGEBNIS.jsonl [Modell ...] Schreibt je Modell eine Zeile; keine Antworttexte, kein Key.
|
||||
"""
|
||||
import json, subprocess, sys, time, urllib.request
|
||||
import openai
|
||||
|
||||
BASE = "http://127.0.0.1:18100"
|
||||
|
||||
def ssh(cmd):
|
||||
return subprocess.run(["ssh", "-o", "BatchMode=yes", "srv04", cmd], capture_output=True, text=True, timeout=60).stdout.strip()
|
||||
|
||||
KEY = ssh("cat /tmp/nexus-kern/key")
|
||||
client = openai.OpenAI(base_url=BASE + "/v1", api_key=KEY, max_retries=0, timeout=600)
|
||||
|
||||
def gpu():
|
||||
out = ssh("nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits; free -m | awk '/^Mem/{print $7}'")
|
||||
*g, ram = [int(x) for x in out.split()]
|
||||
return {"gpu_mib": g, "ram_frei_mb": ram}
|
||||
|
||||
def instances():
|
||||
req = urllib.request.Request(BASE + "/gateway/v1/status", headers={"Authorization": "Bearer " + KEY})
|
||||
return json.load(urllib.request.urlopen(req, timeout=30))["scheduler"]["instances"]
|
||||
|
||||
def probe(fn):
|
||||
t = time.time()
|
||||
try:
|
||||
r = fn()
|
||||
return {"ok": True, "s": round(time.time() - t, 1), **(r or {})}
|
||||
except openai.APIStatusError as e:
|
||||
return {"ok": False, "s": round(time.time() - t, 1), "status": e.status_code, "code": e.code, "meldung": str(e.message)[:300]}
|
||||
except Exception as e:
|
||||
return {"ok": False, "s": round(time.time() - t, 1), "fehler": f"{type(e).__name__}: {e}"[:300]}
|
||||
|
||||
TOOLS = [{"type": "function", "function": {"name": "wetter", "description": "Liefert das Wetter einer Stadt.",
|
||||
"parameters": {"type": "object", "properties": {"stadt": {"type": "string"}}, "required": ["stadt"]}}}]
|
||||
FRAGE = [{"role": "user", "content": "Wie ist das Wetter in Bremen? Benutze das Werkzeug."}]
|
||||
|
||||
def chat(m, **kw):
|
||||
def run():
|
||||
r = client.chat.completions.create(model=m, messages=[{"role": "user", "content": "Nenne eine Farbe."}], max_tokens=200, **kw)
|
||||
c = r.choices[0]
|
||||
return {"ende": c.finish_reason, "zeichen": len(c.message.content or ""), "usage": bool(r.usage and r.usage.total_tokens), "modell_ok": r.model == m}
|
||||
return run
|
||||
|
||||
def stream(m):
|
||||
def run():
|
||||
n, ende = 0, None
|
||||
for p in client.chat.completions.create(model=m, messages=[{"role": "user", "content": "Zähle bis fünf."}], max_tokens=200, stream=True):
|
||||
n += 1
|
||||
if p.choices and p.choices[0].finish_reason: ende = p.choices[0].finish_reason
|
||||
return {"stuecke": n, "ende": ende}
|
||||
return run
|
||||
|
||||
def tools(m):
|
||||
def run():
|
||||
r = client.chat.completions.create(model=m, messages=FRAGE, tools=TOOLS, max_tokens=600)
|
||||
msg = r.choices[0].message
|
||||
if not msg.tool_calls:
|
||||
return {"werkzeug": False, "ende": r.choices[0].finish_reason}
|
||||
tc = msg.tool_calls[0]
|
||||
args = json.loads(tc.function.arguments)
|
||||
folge = client.chat.completions.create(model=m, tools=TOOLS, max_tokens=600, messages=FRAGE + [
|
||||
{"role": "assistant", "content": msg.content, "tool_calls": [t.model_dump() for t in msg.tool_calls]},
|
||||
*[{"role": "tool", "tool_call_id": t.id, "content": "17 Grad, Regen"} for t in msg.tool_calls]])
|
||||
return {"werkzeug": True, "name": tc.function.name, "args_ok": "stadt" in args, "folge_nutzt_ergebnis": "17" in (folge.choices[0].message.content or "")}
|
||||
return run
|
||||
|
||||
def tools_stream(m):
|
||||
def run():
|
||||
name, args, ende = "", "", None
|
||||
for p in client.chat.completions.create(model=m, messages=FRAGE, tools=TOOLS, max_tokens=600, stream=True):
|
||||
if not p.choices: continue
|
||||
for t in p.choices[0].delta.tool_calls or []:
|
||||
name += (t.function.name or "") if t.function else ""
|
||||
args += (t.function.arguments or "") if t.function else ""
|
||||
ende = p.choices[0].finish_reason or ende
|
||||
if args: json.loads(args)
|
||||
return {"werkzeug": bool(name), "name": name, "ende": ende}
|
||||
return run
|
||||
|
||||
def embed(m):
|
||||
def run():
|
||||
r = client.embeddings.create(model=m, input=["Hallo", "Welt"])
|
||||
return {"vektoren": len(r.data), "dim": len(r.data[0].embedding)}
|
||||
return run
|
||||
|
||||
def main():
|
||||
out, wanted = sys.argv[1], sys.argv[2:]
|
||||
models = sorted(x.id for x in client.models.list())
|
||||
with open(out, "a") as f:
|
||||
def emit(d):
|
||||
f.write(json.dumps(d, ensure_ascii=False) + "\n"); f.flush(); print(json.dumps(d, ensure_ascii=False), flush=True)
|
||||
emit({"fall": "allgemein", "modelle": len(models), "instanzen": len(instances()), **gpu(),
|
||||
"unbekannt": probe(chat("gibt-es-nicht")),
|
||||
"falscher_key": probe(lambda: openai.OpenAI(base_url=BASE + "/v1", api_key="falsch", max_retries=0).models.list() and None),
|
||||
"instanzen_danach": len(instances())})
|
||||
for m in wanted or models:
|
||||
d = {"modell": m, "vorher": gpu()}
|
||||
if m == "bge-m3":
|
||||
d["kalt"] = probe(embed(m)); d["geladen"] = gpu()
|
||||
else:
|
||||
d["kalt"] = probe(chat(m)); d["geladen"] = gpu()
|
||||
if d["kalt"]["ok"]:
|
||||
d["stream"] = probe(stream(m))
|
||||
d["werkzeug"] = probe(tools(m))
|
||||
d["werkzeug_stream"] = probe(tools_stream(m))
|
||||
d["falscher_parameter"] = probe(chat(m, temperature=-5))
|
||||
d["warm"] = probe(chat(m))
|
||||
d["instanzen_geladen"] = [{k: i.get(k) for k in ("model", "state", "vram_mb", "gpus")} for i in instances()]
|
||||
t = time.time()
|
||||
while instances() and time.time() - t < 150:
|
||||
time.sleep(5)
|
||||
time.sleep(3)
|
||||
d["entladen"] = {"s": round(time.time() - t), "instanzen": len(instances()), **gpu()}
|
||||
emit(d)
|
||||
|
||||
main()
|
||||
43
scripts/srv04-kern-test/config.toml.in
Normal file
43
scripts/srv04-kern-test/config.toml.in
Normal file
@ -0,0 +1,43 @@
|
||||
# Testinstanz für die Kernprüfung (#1263), nur 127.0.0.1, Daten unter @DIR@/data. Produktion bleibt unberührt.
|
||||
listen = "127.0.0.1:18100"
|
||||
data_dir = "@DIR@/data"
|
||||
log_level = "info"
|
||||
|
||||
[scheduler]
|
||||
idle_secs = 45
|
||||
maya_idle_secs = 45
|
||||
|
||||
[llama_cpp]
|
||||
binary = "/srv/apps/llama.cpp/build/bin/llama-server"
|
||||
model_roots = ["/srv/models/gguf"]
|
||||
port_from = 19080
|
||||
port_to = 19180
|
||||
ready_timeout_secs = 300
|
||||
|
||||
[ollama]
|
||||
mode = "managed"
|
||||
binary = "/usr/local/bin/ollama"
|
||||
models_dir = "/srv/models/ollama"
|
||||
gpus = [0]
|
||||
port_from = 12500
|
||||
port_to = 12599
|
||||
ready_timeout_secs = 300
|
||||
[ollama.env]
|
||||
OLLAMA_NOPRUNE = "1"
|
||||
OLLAMA_VULKAN = "0"
|
||||
|
||||
[maya]
|
||||
python = "/srv/apps/maya/.venv/bin/python"
|
||||
script = "/srv/apps/maya/maya.py"
|
||||
config_roots = ["/srv/apps/maya"]
|
||||
port_from = 19200
|
||||
port_to = 19299
|
||||
ready_timeout_secs = 300
|
||||
|
||||
[strata]
|
||||
config_roots = ["/home/svc-scotty/.local/share/strata/install"]
|
||||
port_from = 19500
|
||||
port_to = 19599
|
||||
ready_timeout_secs = 400
|
||||
[strata.env]
|
||||
XDG_DATA_HOME = "/home/svc-scotty/.local/share"
|
||||
46
scripts/srv04-kern-test/remote.sh
Normal file
46
scripts/srv04-kern-test/remote.sh
Normal file
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
# Läuft AUF srv04 als Benutzer stephan (ohne sudo). Testinstanz für die Kernprüfung (#1263).
|
||||
# Aufruf: bash remote.sh prepare|start|stop|clean
|
||||
# Alles liegt unter /tmp/nexus-kern (tmpfs). Die Produktion (nexus.service, Port 8080) wird nicht angefasst.
|
||||
set -u
|
||||
DIR=/tmp/nexus-kern
|
||||
N="$DIR/bin/nexus"
|
||||
CFG="$DIR/config.toml"
|
||||
G=/srv/models/gguf
|
||||
S=/home/svc-scotty/.local/share/strata/install
|
||||
case "${1:-}" in
|
||||
prepare)
|
||||
mkdir -p "$DIR/data"; chmod 700 "$DIR"
|
||||
sed "s|@DIR@|$DIR|g" "$DIR/config.toml.in" > "$CFG"
|
||||
add() { n=$1; shift; "$N" model add --name "$n" "$@" --config "$CFG" 2>&1 | tail -1; }
|
||||
add bonsai --path "$G/Bonsai-1.7B-Q1_0.gguf" --gpus 0 --context 4096
|
||||
add darkidol --path "$G/DarkIdol-Llama-3.1-8B-Instruct-1.2-Uncensored-Q6_K.gguf" --gpus 0 --context 4096
|
||||
add erebus --path "$G/Erebus-RP-Engine-26B-A4B.Q4_K_M.gguf" --gpus 0,1 --context 4096
|
||||
add gemory --path "$G/Gemory-26B-A4B-Q4_K_M.gguf" --gpus 0,1 --context 4096
|
||||
add multiverse --path "$G/M-MOE-4X7B-Dark-MultiVerse-UC-E32-24B-D_AU-Q4_k_m.gguf" --gpus 0,1 --context 4096
|
||||
add cydonia --path "$G/TheDrummer_Cydonia-24B-v4.3-Q4_K_M.gguf" --gpus 0,1 --context 4096
|
||||
add painted --path "$G/zerofata_MS3.2-PaintedFantasy-v3-24B-Q4_K_M.gguf" --gpus 0,1 --context 4096
|
||||
add qwen36 --path "$G/models/qwen36-UD-Q4_K_XL/Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" --gpus 0,1 --context 4096
|
||||
add bge-m3 --path "$G/bge-m3-q8_0.gguf" --gpus 0 --embeddings --pooling cls
|
||||
for t in qwen3:0.6b qwen3:1.7b llama3.2:3b gemma3:4b; do add "ollama-${t//:/-}" --engine ollama --tag "$t" --gpus 0; done
|
||||
add maya --engine maya --maya-config /srv/apps/maya/maya-maya-xs-iq1_s.json --gpus 0,1
|
||||
for s in iq3_s q2_0 qwen36-ud-q4_k_xl; do add "strata-$s" --engine strata --strata-config "$S/strata-$s.json" --gpus 0,1; done
|
||||
umask 077
|
||||
"$N" key create --name kern --metrics --max-priority high --config "$CFG" | grep -E '^nx[A-Za-z0-9_-]{8,}|^[A-Za-z0-9_-]{24,}$' | head -1 > "$DIR/key"
|
||||
echo "Key-Datei: $(wc -c < "$DIR/key") Byte"
|
||||
"$N" model list --config "$CFG"
|
||||
;;
|
||||
start)
|
||||
setsid nohup "$N" serve --config "$CFG" > "$DIR/serve.log" 2>&1 < /dev/null &
|
||||
echo $! > "$DIR/nexus.pid"
|
||||
curl -s --retry 10 --retry-delay 1 --retry-connrefused http://127.0.0.1:18100/gateway/v1/health; echo
|
||||
;;
|
||||
stop)
|
||||
[ -f "$DIR/nexus.pid" ] && kill "$(cat "$DIR/nexus.pid")" 2>/dev/null; rm -f "$DIR/nexus.pid"
|
||||
;;
|
||||
clean)
|
||||
[ -f "$DIR/nexus.pid" ] && { echo "erst stop"; exit 1; }
|
||||
rm -rf "$DIR"
|
||||
;;
|
||||
*) echo "Aufruf: remote.sh prepare|start|stop|clean"; exit 2 ;;
|
||||
esac
|
||||
Reference in New Issue
Block a user