Nicholastempleman's picture
Publish cross-hardware reproducibility dataset with preprint PDF and source (CC-BY-4.0)
4e189ca verified
Raw History Blame Contribute Delete
3.15 kB
#!/usr/bin/env python3
"""Rebuild the paper's inputs from the PUBLISHED dataset alone, then regenerate every number.
python3 figures/from_dataset.py --dataset <root of the HF dataset> --work <scratch dir>
python3 figures/make_figures.py --decl <work>/decl-nemo --decl <work>/decl-batch2 --items <work>/items
The dataset stores the three runs of each item side by side (data/items.jsonl). This script splits
them back into one items.jsonl per run (<work>/items/runs/<run_id>/items.jsonl), and sorts the
runtime declarations into the two batch directories that make_figures.py expects (batch 1 is the
directory whose name contains "nemo"). make_figures.py then rebuilds every card, cross-checks it
against the declarations the signed capsules bind (a mismatch aborts), and writes build/numbers.json
and tables/*.tex; compare them with the released copies.
"""
from __future__ import annotations
import argparse
import json
import os
import shutil
RUNS = {"rtx3090": "rtx3090_", "t4_run1": "t4_run1_", "t4_run2": "t4_run2_"}
FIELDS = ("raw_output", "raw_output_sha256", "parsed_label", "grade", "done_reason")
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--dataset", required=True)
ap.add_argument("--work", required=True)
a = ap.parse_args()
ds, wk = a.dataset, a.work
if os.path.exists(wk):
raise SystemExit(f"{wk} exists; pass a fresh directory")
withheld = [l for l in open(os.path.join(ds, "data/withheld.jsonl"), encoding="utf-8") if l.strip()]
if withheld:
raise SystemExit(f"{len(withheld)} outputs are withheld from this copy; the prefix analysis needs them")
batch_of = {}
for line in open(os.path.join(ds, "data/cards.jsonl"), encoding="utf-8"):
c = json.loads(line)
batch_of[os.path.basename(c["declaration_file"])] = c["batch"]
for b, name in (("batch1", "decl-nemo"), ("batch2", "decl-batch2")):
os.makedirs(os.path.join(wk, name))
for f, cb in batch_of.items():
if cb == b:
shutil.copyfile(os.path.join(ds, "declarations", f), os.path.join(wk, name, f))
runs: dict[str, list[dict]] = {}
for line in open(os.path.join(ds, "data/items.jsonl"), encoding="utf-8"):
r = json.loads(line)
for pre in RUNS.values():
rid = r.get(pre + "run_id")
if rid is None:
continue
rec = {"item_id": r["item_id"], "sequence": r["sequence"], "prompt_sha256": r["prompt_sha256"],
"predicate": r["predicate"], "transport_ok": r[pre + "status"] != "transport_error"}
rec.update({k: r[pre + k] for k in FIELDS})
runs.setdefault(rid, []).append(rec)
for rid, recs in runs.items():
d = os.path.join(wk, "items", "runs", rid)
os.makedirs(d)
with open(os.path.join(d, "items.jsonl"), "w", encoding="utf-8") as fh:
for rec in sorted(recs, key=lambda x: x["sequence"]):
fh.write(json.dumps(rec, ensure_ascii=False) + "\n")
print(f"{len(batch_of)} declarations, {len(runs)} runs written under {wk}")
if __name__ == "__main__":
main()