Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/evidence/OLLM-AB4-ROUNDS-4-11-20261122/harness/build_mix.py # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / evidence / OLLM-AB4-ROUNDS-4-11-20261122 / harness / build_mix.py` 155 lines ยท 5830 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Measuring/prep harness (not structural): build a zero-leakage, NUL-EOS, shuffled training mix. 3 4 usage: build_mix.py ROUND OUT_DIR REPO_FRAC_PCT EPOCHS name=path:weight ... 5 6 Same method as the Round 3 prep (session `ed855b80` step 944): split sources into `note .. fn .. end` 7 records, prune any record whose AST collides with a frozen benchmark task (`bench seen`), weight, 8 shuffle, blend repo-train.om rehearsal, NUL-join. Writes: 9 OUT_DIR/rN_mix.om the training mix 10 OUT_DIR/rN_audit.om every distinct RLVR record once, newline-joined (for `bench seen` / score) 11 OUT_DIR/rN_manifest.txt counts and sha256 of every input and output 12 Exits 1 if the final audit is not `seen 0`. 13 """ 14 import hashlib, os, random, subprocess, sys, tempfile 15 16 CAMP = "/home/drakestapleton/work/ollm-helix-rlvr-`20261121`" 17 VLOOP = "/home/drakestapleton/work/ollm-loop-`20261121`" 18 BENCH = f"{CAMP}/bin/bench" 19 TASKS = f"{CAMP}/data/tasks.om" 20 21 22 def sha(path): 23 h = hashlib.sha256() 24 with open(path, "rb") as f: 25 for b in iter(lambda: f.read(1 << 20), b""): 26 h.update(b) 27 return h.hexdigest() 28 29 30 def split_by_note(path): 31 raw = open(path, "rb").read().replace(b"\x00", b"\n").decode("utf-8", errors="ignore") 32 recs, cur = [], [] 33 34 def flush(): 35 if cur and any(l.startswith("fn ") for l in cur): 36 s = "\n".join(cur).strip() 37 if s.endswith("end"): 38 recs.append(s + "\n") 39 40 for line in raw.splitlines(): 41 if line.startswith("note ") and cur and any(l.startswith("fn ") for l in cur): 42 flush() 43 cur = [line] 44 elif line.strip() != "": 45 cur.append(line) 46 flush() 47 return recs 48 49 50 def seen_out(recs): 51 if not recs: 52 return "SEENSUM seen 0" 53 with tempfile.NamedTemporaryFile("w", delete=False, suffix=".om") as tf: 54 tf.write("\n".join(recs)) 55 p = tf.name 56 try: 57 r = subprocess.run([BENCH, "seen", TASKS, p], capture_output=True, text=True, check=True) 58 return r.stdout.strip() 59 finally: 60 os.unlink(p) 61 62 63 def leaked(recs): 64 return "seen 0" not in seen_out(recs) 65 66 67 def prune_seen(recs): 68 if not leaked(recs): 69 return recs, 0 70 if len(recs) <= 1: 71 return [], len(recs) 72 mid = len(recs) // 2 73 a, pa = prune_seen(recs[:mid]) 74 b, pb = prune_seen(recs[mid:]) 75 return a + b, pa + pb 76 77 78 def main(): 79 rnd, out_dir, repo_pct, epochs = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]) 80 specs = sys.argv[5:] 81 os.makedirs(out_dir, exist_ok=True) 82 rng = random.Random(`20261122` + int(rnd)) 83 man = [f"round {rnd} repo_pct {repo_pct} epochs {epochs}"] 84 pool, audit, seen_set = [], [], set() 85 for spec in specs: 86 name, rest = spec.split("=", 1) 87 path, weight = rest.rsplit(":", 1) 88 weight = int(weight) 89 recs = split_by_note(path) 90 uniq = list(dict.fromkeys(recs)) 91 clean, pruned = prune_seen(uniq) 92 man.append(f"source {name} path {path} sha256 {sha(path)} parsed {len(recs)} unique {len(uniq)} pruned {pruned} kept {len(clean)} weight {weight}") 93 print(man[-1], flush=True) 94 pool.extend(clean * weight) 95 for r in clean: 96 if r not in seen_set: 97 seen_set.add(r) 98 audit.append(r) 99 final = seen_out(audit) 100 man.append(f"audit_records {len(audit)} bench_seen: {final.splitlines()[-1]}") 101 print(man[-1], flush=True) 102 if "seen 0" not in final: 103 print("FATAL LEAK", final, file=sys.stderr) 104 sys.exit(1) 105 chunks = [] 106 for _ in range(epochs): 107 rng.shuffle(pool) 108 chunks.extend(pool) 109 rlvr_bytes = sum(len(c.encode()) + 1 for c in chunks) 110 target_repo = rlvr_bytes * repo_pct // (100 - repo_pct) 111 repo_path = f"{VLOOP}/data/repo-train.om" 112 slice_mix = os.environ.get("REPO_FROM_MIX", "") 113 if slice_mix: 114 # ablation: replay the small repo slice of an earlier mix (its non-record documents) until 115 # the target share is reached, instead of drawing widely from repo-train.om 116 docs = open(slice_mix, "rb").read().split(b"\x00") 117 repo_set = set(open(repo_path, "rb").read().split(b"\x00")) 118 sl = [d for d in docs if len(d) >= 20 and d in repo_set] 119 sl = list(dict.fromkeys(sl)) 120 man.append(f"repo slice replayed from {slice_mix} sha256 {sha(slice_mix)} distinct_docs {len(sl)} distinct_bytes {sum(len(d) + 1 for d in sl)}") 121 pick, got = [], 0 122 while got < target_repo: 123 rng.shuffle(sl) 124 for ch in sl: 125 pick.append(ch) 126 got += len(ch) + 1 127 if got >= target_repo: 128 break 129 else: 130 repo_raw = open(repo_path, "rb").read().split(b"\x00") 131 rng.shuffle(repo_raw) 132 pick, got = [], 0 133 for ch in repo_raw: 134 if len(ch) < 20: 135 continue 136 pick.append(ch) 137 got += len(ch) + 1 138 if got >= target_repo: 139 break 140 combined = [c.encode() for c in chunks] + pick 141 rng.shuffle(combined) 142 blob = b"\x00".join(combined) + b"\x00" 143 mix = f"{out_dir}/r{rnd}_mix.om" 144 aud = f"{out_dir}/r{rnd}_audit.om" 145 open(mix, "wb").write(blob) 146 open(aud, "w").write("\n".join(audit)) 147 man.append(f"repo source {repo_path} sha256 {sha(repo_path)} docs {len(pick)} distinct_docs {len(set(pick))} bytes {got}") 148 man.append(f"mix {mix} bytes {len(blob)} docs {len(combined)} rlvr_docs {len(chunks)} rlvr_bytes {rlvr_bytes} repo_share_pct {100.0 * got / (got + rlvr_bytes):.1f} sha256 {sha(mix)}") 149 man.append(f"audit {aud} sha256 {sha(aud)}") 150 open(f"{out_dir}/r{rnd}_manifest.txt", "w").write("\n".join(man) + "\n") 151 print("\n".join(man[-3:]), flush=True) 152 153 154 if __name__ == "__main__": 155 main()