okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-clean-3 (321794636): docs and history (cleanup step 3, items 3.0-3.10); release manifest and capability table with checks, history/ with pointers, link check, tools/ split, bench index; owner OK'd the wording 11-082b36e8a02

main
740 B25 linesraw
1#!/usr/bin/env python3
2"""kl.py A.bin B.bin ... : KL(A||B), top-1 agreement and max |dlogit| between first-token logit dumps (STRATA_DUMP_FIRST_LOGITS)."""
3import sys
4import numpy as np
5
6
7def load(p):
8    return np.fromfile(p, dtype=np.float32).astype(np.float64)
9
10
11def lsm(x):
12    m = x.max()
13    return x - m - np.log(np.exp(x - m).sum())
14
15
16a = load(sys.argv[1])
17la = lsm(a)
18pa = np.exp(la)
19for p in sys.argv[2:]:
20    b = load(p)
21    lb = lsm(b)
22    kl = float((pa * (la - lb)).sum())
23    top = np.argsort(-a)[:5]
24    print(f"{p}: KL(A||B)={kl:.3e}  top1 {'same' if a.argmax() == b.argmax() else 'DIFF'}  max|dlogit|={np.abs(a - b).max():.4f}  "
25          f"max|dlogit| top5={np.abs(a[top] - b[top]).max():.4f}  A top1 p={pa.max():.3f}")