"""Assign each usable run to an outcome category and to a random sub-mean group (local). Usable = finished 100-step run whose training log is its own (48 repos in 22 sets share a byte-identical log while their weights differ, so their labels are unknown: excluded) and whose weights are not a byte-identical re-upload. Categories from the last 10 logged steps (training accuracy, mean completion length, policy entropy): loop acc < 0.05, length >= 768, entropy < 1.0 (long and low-entropy: repetition loops) gibberish acc < 0.05, length >= 768, entropy >= 1.0 (long and high-entropy: token salad) short acc < 0.05, length < 768 (other collapse) degraded 0.05 <= acc < 0.5 healthy acc >= 0.5 Groups: within each category, shuffle (seed 0) and cut into near-equal groups of about 40 (at least 4 groups when the category has >= 16 runs, so split halves exist). Writes meta/groups.json and meta/usable.csv. """ import csv, json, os, random, collections, requests from concurrent.futures import ThreadPoolExecutor TOK = open(os.path.expanduser("~/.cache/huggingface/token")).read().strip() H = {"Authorization": f"Bearer {TOK}"} R = list(csv.DictReader(open("meta/runs.csv"))) ent = json.load(open("meta/entropy.json")) U = [r for r in R if r["max_steps"] == "100" and r["global_step"] == "100"] cnt = collections.Counter(r["log_hash"] for r in U) dup_log = [r["repo"] for r in U if cnt[r["log_hash"]] > 1] U = [r for r in U if cnt[r["log_hash"]] == 1] def oid(r): t = requests.get(f"https://huggingface.co/api/models/{r['repo']}/tree/{r['sha']}", headers=H).json() return r["repo"], tuple(sorted(x["lfs"]["oid"] for x in t if x["path"].endswith(".safetensors"))) with ThreadPoolExecutor(8) as ex: oids = dict(ex.map(oid, U)) assert all(len(v) == 4 for v in oids.values()), "unexpected shard count" seen, dup_w = {}, [] for r in U: if oids[r["repo"]] in seen: dup_w.append(r["repo"]) else: seen[oids[r["repo"]]] = r["repo"] U = [r for r in U if r["repo"] not in dup_w] def cat(r): a, l = float(r["acc_last10"]), float(r["len_last10"]) e = ent[r["repo"]][1] if a >= 0.5: return "healthy" if a >= 0.05: return "degraded" if l < 768: return "short" if e is None: return "long_unknown" return "loop" if e < 1.0 else "gibberish" for r in U: r["category"] = cat(r) r["ent_last10"] = ent[r["repo"]][1] by = collections.defaultdict(list) for r in U: by[r["category"]].append(r["repo"]) rng = random.Random(0) groups = [] for c in sorted(by): xs = sorted(by[c]); rng.shuffle(xs) k = max(4 if len(xs) >= 16 else 1, round(len(xs) / 40)) for i in range(k): groups.append(dict(name=f"{c}_g{i:02d}", category=c, members=xs[i::k])) for g in groups: g["n"] = len(g["members"]) json.dump(dict(groups=groups, excluded_dup_log=dup_log, excluded_dup_weights=dup_w, rules=__doc__), open("meta/groups.json", "w"), indent=1) with open("meta/usable.csv", "w", newline="") as f: keys = list(U[0].keys()); w = csv.DictWriter(f, keys); w.writeheader(); w.writerows(U) print("usable", len(U), "dup-log excluded", len(dup_log), "dup-weights excluded", len(dup_w)) print({c: len(v) for c, v in sorted(by.items())}) print([(g["name"], g["n"]) for g in groups])