#!/usr/bin/env python """MTEB-lite (eng): per-item scores for the merge-sweep models that have FULL MTEB(eng, v2) scores. Their merged weights were deleted after the sweep, so each one is rebuilt from its grid (scripts/merge_sweep.py build()), scored with mteb_lite_score.py (native:, the same loader as the sweep's run_mteb_english.py call) under its spec name - the name mteb_lite_select.py uses to find its outputs/merge_sweep/scores*//mteb_en/summary_en.json - and deleted again. python scripts/mteb_lite_score_merges.py --list (no GPU) what would be scored python scripts/mteb_lite_score_merges.py --shard i/n [--batch-size 64] one GPU per shard python scripts/mteb_lite_score_merges.py --suite ara --shard i/n Arabic: every merge of the *_complete grids (sweep_v3_complete, sweep_v3_full_complete, sweep_v3_final_complete, sweep_v4_complete, sweep_v34_complete, sweep_v5_complete) whose //mteb has all 42 Arabic test scores; names deduplicated (same spec = same model). Resumable: a merge whose score files already cover every pool task is not rebuilt; per task, existing score files are kept (mteb_lite_score.py skips them). """ from __future__ import annotations import argparse import glob import json import os import shutil import subprocess import sys from pathlib import Path REPO = Path(__file__).resolve().parents[1] sys.path.insert(0, str(REPO / "scripts")) AR_GRIDS = ("sweep_v3_complete", "sweep_v3_full_complete", "sweep_v3_final_complete", "sweep_v4_complete", "sweep_v34_complete", "sweep_v5_complete") def candidates_ara() -> list[tuple[str, dict, dict]]: import yaml sys.path.insert(0, str(REPO / "scripts")) import mteb_lite_lib as L from mteb_lite_public_full import summary_scores L.configure("ara") names = set(L.task_names()) out, seen = [], set() for gname in AR_GRIDS: g = REPO / "configs" / "merge" / f"{gname}.yaml" grid = yaml.safe_load(open(g)) scores = Path(grid.get("scores", REPO / "outputs" / "merge_sweep" / "scores")) if not scores.is_absolute(): scores = REPO / scores for spec in grid.get("specs", []): n = spec["name"] if n in seen or not names <= set(summary_scores(scores / n / "mteb")): continue seen.add(n) out.append((str(g), grid, spec)) return out def candidates() -> list[tuple[str, dict, dict]]: import yaml out, seen = [], set() for g in sorted(glob.glob(str(REPO / "configs" / "merge" / "*.yaml"))): grid = yaml.safe_load(open(g)) scores = Path(grid.get("scores", REPO / "outputs" / "merge_sweep" / "scores")) if not scores.is_absolute(): scores = REPO / scores for spec in grid.get("specs", []): n = spec["name"] if n in seen or not (scores / n / "mteb_en" / "summary_en.json").exists(): continue s = json.loads((scores / n / "mteb_en" / "summary_en.json").read_text()) if not s.get("n_tasks"): # partial runs still give per-task targets continue seen.add(n) out.append((g, grid, spec)) return out def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--suite", choices=["eng", "ara"], default="eng") ap.add_argument("--list", action="store_true") ap.add_argument("--shard", default="0/1") ap.add_argument("--batch-size", type=int, default=64) ap.add_argument("--tmp", default=None) ap.add_argument("--per-family", type=int, default=0, help="only the <= N models per merge family that mteb_lite_select_v2.py keeps (best / median / " "worst by full macro); 0 = all") args = ap.parse_args() sys.path.insert(0, str(REPO / "scripts")) import mteb_lite_lib as L L.configure(args.suite) if args.tmp is None: args.tmp = str(L.OUT / "tmp_merges") cands = candidates() if args.suite == "eng" else candidates_ara() tasks = [t for t in L.task_names() if L.pool_path(t).exists()] if args.per_family: from mteb_lite_select_v2 import diverse_set if args.suite == "ara": from mteb_lite_public_full import ours_ara fulls = ours_ara() else: import mteb_lite_select as S1 fulls = S1.full_scores([c[2]["name"] for c in cands], None) keep, _ = diverse_set([c[2]["name"] for c in cands if fulls.get(c[2]["name"])], fulls, L.task_names(), args.per_family) cands = [c for c in cands if c[2]["name"] in set(keep)] i, n = map(int, args.shard.split("/")) mine = cands[i::n] for g, grid, spec in (cands if args.list else mine): srcs = [grid["models"][a] for a in spec["models"]] ok = all((REPO / s / "model" / "model.safetensors").exists() or Path(s, "model", "model.safetensors").exists() for s in srcs) and glob.glob(str(REPO / grid["base"])) + glob.glob(grid["base"]) done = all((L.SCORES / spec["name"] / f"{t}.json").exists() for t in tasks) if args.list: print(f"{spec['name']:28s} {Path(g).name:28s} sources {'ok' if ok else 'MISSING'}" f"{' (all tasks scored)' if done else ''}") continue if done: print(f"[lite-merge] {spec['name']}: all {len(tasks)} tasks scored - skipped", flush=True) continue if not ok: print(f"[lite-merge] {spec['name']}: source weights missing - skipped", flush=True) continue os.chdir(REPO) # grid paths are repo-relative from merge_sweep import build tmp = Path(args.tmp) / spec["name"] build(spec, grid, tmp) try: r = subprocess.run([sys.executable, str(REPO / "scripts" / "mteb_lite_score.py"), "--model", f"native:{tmp}", "--name", spec["name"], "--batch-size", str(args.batch_size), "--suite", args.suite]) print(f"[lite-merge] {spec['name']}: exit {r.returncode}", flush=True) finally: shutil.rmtree(tmp, ignore_errors=True) if __name__ == "__main__": main()