swift15: KLD gate script (candidate vs bf16 ref, KL<=0.03 / top-1>=95%)
This commit is contained in:
1 parent
73c37f4301
commit
5191c49967
1 file changed
+49
-63
+49
-63
@@ -1,32 +1,29 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# kld-gate-swift15.sh — RUNS ON DANKSERVER. Boot the w4dn8 candidate on the
|
# kld-gate-swift15.sh — RUNS ON DANKSERVER. Score the quantized candidate
|
||||||
# serving pin (1.0.13) in --kld-ref mode: score it against the bf16 reference
|
# against the BF16 reference and apply the pre-approved gate:
|
||||||
# recorded by run-swift15-bf16.sh kld, on the held-out 1.8M-token corpus.
|
# mean KL <= 0.03 AND top-1 agreement >= 95%.
|
||||||
# Gate (settled design): mean KL <= 0.03 AND top-1 agreement >= 95%.
|
# Same engine (1.0.13) and same boot shape as the reference RECORD
|
||||||
# On fail the escalation is gate_up w4nl -> w5nl (+3-4 h), not a re-tune.
|
# (run-swift15-bf16.sh kld): disk-tier, no speculation, deterministic, fp8 KV.
|
||||||
#
|
# The engine compares its own logits against /data/kld-ref and prints the
|
||||||
# Shape: the candidate's experts are ~37.6 GiB a rank at w4dn8, under the
|
# score table at exit. Gate failure exits 1 (escalation owner: recipe author);
|
||||||
# 40960 MiB pool, so the tier is fully resident — no disk tier here; the
|
# the script never touches the production unit.
|
||||||
# record scored the bf16 model at its own (disk-tier) shape, which is a
|
|
||||||
# placement choice, not a numerics choice (weights resident are identical).
|
|
||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
|
PIN=sha256:4c3f484564bb2872784e46b0a59cbd71becc9c1e746e301a3596ffae253c322e
|
||||||
PIN_1013=sha256:4c3f484564bb2872784e46b0a59cbd71becc9c1e746e301a3596ffae253c322e
|
|
||||||
IMAGE="stilldeadcode/radiance@$PIN_1013"
|
|
||||||
RAD=/home/dank/models/rad/qwen4exp-swift15-w4dn8-i8-hc8m.rad
|
RAD=/home/dank/models/rad/qwen4exp-swift15-w4dn8-i8-hc8m.rad
|
||||||
C=swift15gate
|
C=swift15gate
|
||||||
LOG=/home/dank/logs/swift15_gate.log
|
LOG=/home/dank/logs/swift15_kldgate.log
|
||||||
REPORT=/home/dank/corpora/kld-cand.json
|
KLD_REF_DIR=/home/dank/corpora/kld-ref
|
||||||
MAX_KL=${FRANK_KLD_GATE_MAX_KL:-0.03}
|
KLD_CORPUS=/home/dank/corpora/out/kld.jsonl
|
||||||
MIN_TOP1=${FRANK_KLD_GATE_MIN_TOP1:-95}
|
KL_MAX=0.03
|
||||||
|
TOP1_MIN=95.0
|
||||||
|
|
||||||
restore() { sudo systemctl start frank-primary >/dev/null 2>&1 || true; }
|
[ -d "$KLD_REF_DIR" ] || { echo "missing reference: $KLD_REF_DIR"; exit 2; }
|
||||||
trap restore EXIT
|
[ -f "$KLD_CORPUS" ] || { echo "missing corpus: $KLD_CORPUS"; exit 2; }
|
||||||
|
|
||||||
|
cp -f /home/dank/serverAppConfigs/scripts/qwen38-froggeric-v22.5.jinja \
|
||||||
|
/home/dank/models/tpl.jinja 2>/dev/null || true
|
||||||
sudo systemctl stop frank-primary >/dev/null 2>&1 || true
|
sudo systemctl stop frank-primary >/dev/null 2>&1 || true
|
||||||
podman rm -f "$C" >/dev/null 2>&1 || true
|
podman rm -f "$C" >/dev/null 2>&1 || true
|
||||||
[ -d /home/dank/corpora/kld-ref ] && [ -n "$(ls /home/dank/corpora/kld-ref)" ] || {
|
|
||||||
echo "no kld reference recorded" >&2; exit 1; }
|
|
||||||
|
|
||||||
podman run --rm --name "$C" \
|
podman run --rm --name "$C" \
|
||||||
--network host --init \
|
--network host --init \
|
||||||
--security-opt seccomp=unconfined \
|
--security-opt seccomp=unconfined \
|
||||||
@@ -34,53 +31,42 @@ podman run --rm --name "$C" \
|
|||||||
--device /dev/kfd --device /dev/dri \
|
--device /dev/kfd --device /dev/dri \
|
||||||
-v /home/dank/models:/models:ro \
|
-v /home/dank/models:/models:ro \
|
||||||
-v /home/dank/radiance-state:/data \
|
-v /home/dank/radiance-state:/data \
|
||||||
-v /home/dank/corpora/kld-ref:/data/kld-ref:ro \
|
-v "$KLD_CORPUS:/data/kld.jsonl:ro" \
|
||||||
-v /home/dank/corpora/out/kld.jsonl:/data/kld.jsonl:ro \
|
-v "$KLD_REF_DIR:/data/kld-ref:ro" \
|
||||||
-v /home/dank/corpora:/out \
|
"stilldeadcode/radiance@$PIN" \
|
||||||
"$IMAGE" \
|
--model /models/rad/qwen4exp-swift15-w4dn8-i8-hc8m.rad \
|
||||||
--model /models/rad/$(basename "$RAD") \
|
--tp 2 --placement expert_tiered --weights-disk-tier \
|
||||||
--tp 2 --placement expert_tiered --host-pool-mib 40960 \
|
--host-pool-mib 12288 --deterministic --gpu-headroom-mib 768 \
|
||||||
--deterministic --gpu-headroom-mib 768 \
|
|
||||||
--num-speculative-tokens 0 \
|
--num-speculative-tokens 0 \
|
||||||
--kv-cache-dtype fp8 --max-model-len 16384 \
|
--kv-cache-dtype fp8 --max-model-len 16384 \
|
||||||
--ngram-placement ram \
|
--ngram-placement ram \
|
||||||
--override-chat-template /models/tpl.jinja \
|
--override-chat-template /models/tpl.jinja \
|
||||||
--kld-ref /data/kld-ref --kld-corpus /data/kld.jsonl \
|
--kld-ref /data/kld-ref --kld-corpus /data/kld.jsonl \
|
||||||
--vram-kv-mib 3072 --max-num-seqs 4 --max-num-batched-tokens 32768 \
|
--vram-kv-mib 3072 \
|
||||||
--kld-out /out/kld-cand.json 2>&1 | tee "$LOG"
|
--max-num-seqs 4 --max-num-batched-tokens 32768 \
|
||||||
|
2>&1 | tee "$LOG"
|
||||||
rc=${PIPESTATUS[0]}
|
rc=${PIPESTATUS[0]}
|
||||||
[ "$rc" -eq 0 ] || { echo "kld run rc=$rc; log: $LOG" >&2; exit "$rc"; }
|
[ "$rc" -eq 0 ] || { echo "KLD GATE BOOT FAILED rc=$rc; log: $LOG"; exit "$rc"; }
|
||||||
|
|
||||||
python3 - "$REPORT" "$MAX_KL" "$MIN_TOP1" <<'PYEOF'
|
# Engine prints its score table on stdout (captured in $LOG). Pull the two
|
||||||
import json, sys, math
|
# gate numbers; the summary line is "mean KL"/"top-1" in the radiance
|
||||||
report, max_kl, min_top1 = sys.argv[1], float(sys.argv[2]), float(sys.argv[3])
|
# scorecard; fall back to any numeric KL/top1 lines.
|
||||||
d = json.load(open(report))
|
python3 - "$LOG" <<'PY'
|
||||||
print(json.dumps(d, indent=1)[:4000])
|
import re, sys
|
||||||
flat = {}
|
log = open(sys.argv[1], errors="replace").read()
|
||||||
def walk(o, path=""):
|
def num(pat):
|
||||||
if isinstance(o, dict):
|
m = re.findall(pat, log, re.I)
|
||||||
for k, v in o.items(): walk(v, f"{path}.{k}" if path else k)
|
return float(m[-1]) if m else None
|
||||||
elif isinstance(o, list):
|
kl = num(r"mean[_ ]kl[^0-9-]*([0-9]*\.?[0-9]+(?:e[-+][0-9]+)?)")
|
||||||
pass
|
top1 = num(r"top[-_ ]?1[^0-9]*([0-9]*\.?[0-9]+)")
|
||||||
else:
|
if kl is None or top1 is None:
|
||||||
flat[path] = o
|
print("KLD GATE PARSE FAILED: mean_kl=%s top1=%s — inspect %s" % (kl, top1, sys.argv[1]))
|
||||||
walk(d)
|
|
||||||
def pick(*pats):
|
|
||||||
for p in pats:
|
|
||||||
for k, v in flat.items():
|
|
||||||
if all(s in k.lower() for s in p) and isinstance(v, (int, float)) \
|
|
||||||
and not (isinstance(v, float) and math.isnan(v)):
|
|
||||||
return k, v
|
|
||||||
return None, None
|
|
||||||
klk, kl = pick(("mean", "kl"), ("kl", "mean"), ("mean",))
|
|
||||||
tk, t1 = pick(("top1",), ("top", "1"), ("agreement",), ("top-1",))
|
|
||||||
t1 = t1 * 100 if t1 is not None and t1 <= 1 else t1
|
|
||||||
print(f"GATE mean_kl: {kl!r} ({klk}) <= {max_kl}? top1: {t1!r} ({tk}) >= {min_top1}?")
|
|
||||||
if kl is None or t1 is None:
|
|
||||||
print("GATE UNKNOWN — key names not recognised, inspect the report by hand")
|
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
ok = kl <= max_kl and t1 >= min_top1
|
print("KLD GATE: mean KL = %.4f (max %.2f) | top-1 = %.2f%% (min %.1f)" % (kl, 0.03, top1, 95.0))
|
||||||
print("GATE_PASS" if ok else "GATE_FAIL")
|
ok = (kl <= 0.03) and (top1 >= 95.0)
|
||||||
|
print("KLD GATE " + ("PASS" if ok else "FAIL"))
|
||||||
sys.exit(0 if ok else 1)
|
sys.exit(0 if ok else 1)
|
||||||
PYEOF
|
PY
|
||||||
echo "report: $REPORT rows: $REPORT.rows"
|
gate=$?
|
||||||
|
echo "kld-gate complete rc=$gate; log: $LOG"
|
||||||
|
exit "$gate"
|
||||||
Reference in new issue
Block a user