LELEKA_TRACE_RESIDUAL=<dir> dumps the final R of each verifier window, LELEKA_TRACE_LADDER adds a per-hc_read R ladder (2 frames per layer), LELEKA_TRACE_PLE prints the PLE row ids per window row. scripts/numerics holds the patch scripts for a private copy of the Original (not applied to engine/strata) and the comparison tools. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
import os, re, struct, sys, math, array
|
|
D = os.path.expanduser("~/work/gpu-runs/baseline/corpus")
|
|
N = os.path.expanduser("~/work/gpu-runs/numerics")
|
|
W = 4 * 2560
|
|
ids = [int(x) for x in open(D + "/p4.ids").read().strip().split(",")]
|
|
port = [int(x) for x in open(D + "/p4.port").read().split()]
|
|
truth = ids + port
|
|
|
|
|
|
def rd(path):
|
|
a = array.array("f")
|
|
with open(path, "rb") as f:
|
|
a.frombytes(f.read())
|
|
return a
|
|
|
|
|
|
# port windows from the job log (corpus part only)
|
|
log = open(os.path.expanduser("~/work/gpu-runs/holder/jobs/100-numerics-resid.log"), errors="replace").read().split("\n")
|
|
start = [i for i, l in enumerate(log) if l.startswith("DBG corpus 0 prompt_ids")][0]
|
|
end = [i for i, l in enumerate(log) if l.startswith("DBG corpus 0 output")][0]
|
|
pw = []
|
|
for l in log[start:end]:
|
|
m = re.match(r"DBG residual window seq=(\d+) first=(\d+) rows=(\d+) inputs=\[([0-9, ]+)\] floats=\d+ -> (\S+)", l)
|
|
if m:
|
|
pw.append((int(m[2]), [int(x) for x in m[4].split(",")], m[5]))
|
|
# original windows from stderr
|
|
ow = []
|
|
for l in open(N + "/orig_serve.err", errors="replace"):
|
|
m = re.match(r"NUMRESID seq=(\d+) pos0=(\d+) T=(\d+) tokens=([0-9,]+)", l)
|
|
if m:
|
|
s = int(m[1])
|
|
ow.append((int(m[2]), [int(x) for x in m[4].split(",")], N + "/orig_resid/r_win%05d_pos%s.f32" % (s, m[2])))
|
|
|
|
|
|
def valid_rows(wins):
|
|
"""position -> (window index, row) for rows whose full prefix equals the truth sequence"""
|
|
out = {}
|
|
for wi, (p0, toks, _) in enumerate(wins):
|
|
for k in range(len(toks)):
|
|
if p0 + k < len(truth) and toks[: k + 1] == truth[p0 : p0 + k + 1]:
|
|
out.setdefault(p0 + k, (wi, k))
|
|
else:
|
|
break
|
|
return out
|
|
|
|
|
|
pv, ov = valid_rows(pw), valid_rows(ow)
|
|
cache = {}
|
|
|
|
|
|
def row(wins, wi, k):
|
|
path = wins[wi][2]
|
|
if path not in cache:
|
|
cache[path] = rd(path)
|
|
return cache[path][k * W : (k + 1) * W]
|
|
|
|
|
|
stats = []
|
|
for pos in sorted(pv):
|
|
if pos not in ov:
|
|
continue
|
|
a = row(pw, *pv[pos])
|
|
b = row(ow, *ov[pos])
|
|
num = sum((x - y) ** 2 for x, y in zip(a, b))
|
|
den = sum(y * y for y in b)
|
|
mx = max(abs(x - y) for x, y in zip(a, b))
|
|
bm = max(abs(y) for y in b)
|
|
stats.append((pos, math.sqrt(num / den), mx, bm, pv[pos][1], ov[pos][1]))
|
|
print("compared positions", len(stats), "of port valid", len(pv), "orig valid", len(ov))
|
|
for s in stats[:12] + stats[-4:]:
|
|
print("pos %d relL2=%.3e maxabs=%.3e max|R_orig|=%.2f port_row=%d orig_row=%d" % s)
|
|
rel = sorted(s[1] for s in stats)
|
|
print("relL2 median=%.3e max=%.3e" % (rel[len(rel) // 2], rel[-1]))
|