vaultpls's picture
LFM3-1.7B-Looped: layers 8-11 run twice at half step (training-free depth loop), Q8_0 GGUF + bf16
830e33a verified
Raw History Blame Contribute Delete
2.05 kB
#!/usr/bin/env python3
"""Logit-ensemble of two ARC runs (same items, same options): accuracy as a function of
the mixing weight on model A, plus paired stats against each endpoint."""
import json, math, sys
def load(p):
d = json.load(open(p))
if isinstance(d, list): # legacy format: per-item correctness only
raise SystemExit(f"{p} has no per-option logprobs; rerun with --dump-lp")
return d
def acc(lp, gold):
return sum(int(max(range(len(s)), key=lambda j: s[j]) == g) for s, g in zip(lp, gold)) / len(gold)
def mcnemar(a, b):
n01 = sum(1 for x, y in zip(a, b) if x and not y)
n10 = sum(1 for x, y in zip(a, b) if not x and y)
m = n01 + n10
p = min(1.0, 2 * sum(math.comb(m, i) for i in range(0, min(n01, n10) + 1)) / 2 ** m) if m else 1.0
return n01, n10, p
A = load(sys.argv[1]); B = load(sys.argv[2])
lab_a = sys.argv[3] if len(sys.argv) > 3 else "A"
lab_b = sys.argv[4] if len(sys.argv) > 4 else "B"
assert A["gold"] == B["gold"] and len(A["lp"]) == len(B["lp"]), "different item sets"
gold = A["gold"]
print(f"{'w(' + lab_a + ')':>16} acc vs {lab_a:<14} vs {lab_b}")
best = None
for w in [0, 0.1, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6, 0.7, 0.75, 0.8, 0.9, 1.0]:
mix = [[w * x + (1 - w) * y for x, y in zip(sa, sb)] for sa, sb in zip(A["lp"], B["lp"])]
per = [int(max(range(len(s)), key=lambda j: s[j]) == g) for s, g in zip(mix, gold)]
a_per = [int(max(range(len(s)), key=lambda j: s[j]) == g) for s, g in zip(A["lp"], gold)]
b_per = [int(max(range(len(s)), key=lambda j: s[j]) == g) for s, g in zip(B["lp"], gold)]
n01, n10, p = mcnemar(b_per, per)
n01b, n10b, pb = mcnemar(a_per, per)
print(f"{w:16.2f} {sum(per)/len(per)*100:5.1f}% {sum(per)/len(per)*100 - sum(a_per)/len(a_per)*100:+5.1f}pp (p={pb:.3f}) "
f"{sum(per)/len(per)*100 - sum(b_per)/len(b_per)*100:+5.1f}pp (p={p:.3f})")
if best is None or sum(per) > best[1]:
best = (w, sum(per), p)
print(f"best w({lab_a})={best[0]} acc={best[1]/len(gold)*100:.1f}% p_vs_B={best[2]:.3f}")