Download scripts/audit_primary.py from BurnyCoder/novel-tokens-reasoning-diffusion-llm: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/BurnyCoder/novel-tokens-reasoning-diffusion-llm/resolve/main/scripts/audit_primary.py
- Command line
-
hf download hf://BurnyCoder/novel-tokens-reasoning-diffusion-llm/scripts/audit_primary.py
-
curl -L -o audit_primary.py https://huggingface.co/BurnyCoder/novel-tokens-reasoning-diffusion-llm/resolve/main/scripts/audit_primary.py
2.66 kB
| """Recompute the original cup endpoint from individual recorded predictions.""" | |
| import gzip | |
| import json | |
| import math | |
| from collections import Counter | |
| from itertools import combinations | |
| from novel_tokens.runtime import RESULTS, save_json | |
| def main(): | |
| folder=RESULTS/"cups-symbols-17" | |
| metrics=json.loads((folder/"test-cups.json").read_bytes()) | |
| with gzip.open(folder/metrics["raw"],"rt",encoding="utf-8") as file: | |
| rows=[json.loads(line) for line in file] | |
| index={r["key"]:r for r in rows} | |
| pairs=list(combinations(range(4),2)) | |
| alphabet={v["id"] for v in json.loads((RESULTS/"vocabulary.json").read_bytes())["symbols"]} | |
| counts=Counter() | |
| gold_counts=Counter() | |
| own_counts=Counter() | |
| for r in rows: | |
| # Follow a single ball's position; the training verifier permutes the complete layout. | |
| location=r["start"].index(r["color"]) | |
| for move in r["program"]: | |
| a,b=pairs[move] | |
| location=b if location==a else a if location==b else location | |
| gold="ABCD"[location] | |
| donor=index[r["donor_key"]] | |
| assert gold==r["gold"] and r["key"]!=donor["key"] and donor["donor_key"]==r["key"] | |
| assert r["intervention_ids"]["donor"]==donor["trace_ids"] | |
| assert r["intervention_ids"]["intact"]==r["trace_ids"] and r["intervention_ids"]["direct"]==[] | |
| assert len(r["trace_ids"])==8 and set(r["trace_ids"])<=alphabet | |
| assert sorted(r["reveal_order"])==list(range(8)) and len(r["answer_uniforms"])==1 | |
| gold_counts[gold]+=1 | |
| own_counts[r["answer"]]+=1 | |
| for condition,answer in r["outputs"].items(): | |
| counts[condition]+=answer==gold | |
| programs=len({tuple(r["program"]) for r in rows}) | |
| assert programs==len(index)==len(rows)==metrics["n"] | |
| assert all(metrics["conditions"][key]==hits/len(rows) for key,hits in counts.items()) | |
| assert metrics["delta"]==(counts["intact"]-counts["donor"])/len(rows) | |
| train=[x for x in json.loads((folder/"curves.json").read_bytes()) if "grad_norm" in x] | |
| assert all(math.isfinite(x["grad_norm"]) and math.isfinite(x["replay_error"]) for x in train) | |
| result={"programs":programs,"donor_pairs":len(rows)//2,"gold_counts":dict(gold_counts), | |
| "own_answer_counts":dict(own_counts),"correct_counts":dict(counts), | |
| "changed_answers":sum(r["answer"]!=r["donor_answer"] for r in rows), | |
| "nonzero_gradient_updates":sum(x["grad_norm"]>0 for x in train), | |
| "max_replay_error":max(x["replay_error"] for x in train)} | |
| save_json(RESULTS/"primary-audit.json",result) | |
| print(json.dumps(result,indent=2)) | |
| if __name__=="__main__": | |
| main() | |