#!/usr/bin/env python3 """Merge the strict-limit sweep rows with the pager stats into one table.""" import json from pathlib import Path HERE = Path(__file__).parent RESULTS = HERE / "results" EXPERT_TOTAL_BYTES = 91653931008 # from the GGUF: routed expert weights def load_rows(): rows = [] for name in ("strict_low.json", "strict_high.json", "strict_64g.json"): p = RESULTS / name if p.exists(): rows += json.loads(p.read_text()) rows.sort(key=lambda r: r["level_mb"]) return rows def stats_for(level_mb): p = RESULTS / "strict_levels" / f"level_{level_mb}_r0.jsonl" if not p.exists(): return None last = None for line in p.read_text().splitlines(): if line.strip(): last = json.loads(line) return last def main(): rows = load_rows() out = [] for r in rows: s = stats_for(r["level_mb"]) row = dict(r) if s: row["arena_gib"] = round(s["arena_bytes"] / 2**30, 2) row["slots"] = s["n_slots"] row["small_slots"] = s["n_small_slots"] row["big_slots"] = s["n_big_slots"] row["coverage_pct"] = round(100 * s["arena_bytes"] / EXPERT_TOTAL_BYTES, 1) row["expert_requests"] = s["expert_requests"] row["expert_hits"] = s["expert_hits"] row["expert_misses"] = s["expert_misses"] row["hit_rate"] = s["hit_rate"] row["evictions"] = s["evictions"] row["demand_wait_s"] = round(s["demand_wait_us"] / 1e6, 1) out.append(row) (RESULTS / "strict_memory_levels_final.json").write_text( json.dumps(out, indent=2, ensure_ascii=False)) lines = [] lines.append("| RAM cap | result | arena | slots (small/big) | expert coverage | anon peak | RSS peak | decode tok/s | SSD MB/tok | hit rate | evictions |") lines.append("|---|---|---|---|---|---|---|---|---|---|---|") for r in out: if r["result"] == "FAIL": lines.append(f"| {r['level_gib']:.0f} GiB | **FAIL** ({r.get('detail','')[:40]}) | - | - | - | " f"{r['peak_anon_mb']:.0f} MB | {r['peak_rss_mb']:.0f} MB | - | - | - | - |") continue lines.append( f"| {r['level_gib']:.0f} GiB | PASS | {r.get('arena_gib','?')} GiB | " f"{r.get('slots','?')} ({r.get('small_slots','?')}/{r.get('big_slots','?')}) | " f"{r.get('coverage_pct','?')}% | {r['peak_anon_mb']:.0f} MB | {r['peak_rss_mb']:.0f} MB | " f"{r['decode_tok_s']:.2f} | {r['ssd_mb_tok']:.0f} | {r.get('hit_rate','?')} | {r.get('evictions','?')} |") table = "\n".join(lines) (RESULTS / "strict_memory_levels.md").write_text(table + "\n") print(table) if __name__ == "__main__": main()