#!/usr/bin/env python3 """Build the fixed token sets every arm is scored on (PROTOCOL.md "Fixed inputs"). uv run --with transformers,pandas python build_eval_set.py --tok \ --wikitext-test wikitext2-test.txt --c4-eval c4-validation.00001-of-00008.json.gz \ --codeparrot file-000000000054.json.gz --out eval-set.json Output: {"ppl-wiki": [[ids]*40], "ppl-code": [[ids]*40], "kld": [[ids]*512], "meta": {...}}, all 2048 tokens per window. The same ids go to every arm, so tokenizer drift can't enter the comparison. Code windows come from the LAST 10 % of codeparrot docs (file order); quant_body.py calibrates on the first 90 %. C4 eval uses validation shard 1; calibration used shard 0. """ import argparse, gzip, hashlib, json, random from transformers import AutoTokenizer ap = argparse.ArgumentParser() ap.add_argument("--tok", required=True); ap.add_argument("--wikitext-test", required=True) ap.add_argument("--c4-eval", required=True); ap.add_argument("--codeparrot", required=True) ap.add_argument("--out", required=True) ap.add_argument("--seqlen", type=int, default=2048) a = ap.parse_args() random.seed(608) tok = AutoTokenizer.from_pretrained(a.tok) L = a.seqlen def windows(texts, n): out, buf = [], [] for t in texts: buf += tok(t, add_special_tokens=False)["input_ids"] + [tok.eos_token_id] while len(buf) >= L and len(out) < n: out.append(buf[:L]); buf = buf[L:] if len(out) >= n: return out raise SystemExit(f"only {len(out)} windows, wanted {n}") wiki_ids = tok(open(a.wikitext_test, encoding="utf-8").read(), add_special_tokens=False)["input_ids"] ppl_wiki = [wiki_ids[i * L:(i + 1) * L] for i in range(40)] # same chunks as ppl_wikitext2.py code_docs = [json.loads(l)["content"] for l in gzip.open(a.codeparrot, "rt")] code_tail = code_docs[int(len(code_docs) * 0.9):] random.shuffle(code_tail) code_win = windows(code_tail, 256 + 40) ppl_code, kld_code = code_win[:40], code_win[40:] c4 = [json.loads(l)["text"] for l in gzip.open(a.c4_eval, "rt")] random.shuffle(c4) kld = windows(c4, 256) + kld_code out = {"ppl-wiki": ppl_wiki, "ppl-code": ppl_code, "kld": kld} blob = json.dumps(out, separators=(",", ":")).encode() out["meta"] = {"seqlen": L, "seed": 608, "tokenizer": a.tok, "counts": {k: len(v) for k, v in out.items()}, "sha256_ids": hashlib.sha256(blob).hexdigest(), "code_docs_total": len(code_docs), "code_tail_from_index": int(len(code_docs) * 0.9)} json.dump(out, open(a.out, "w"), separators=(",", ":")) print(json.dumps(out["meta"], indent=1))