p6_harness_probe v2: measure what a resolving lm-eval install moves, instead of assuming --no-deps is safe (it is not: sacrebleu import failure)
Browse files- kernels/p6_harness_probe.py +111 -67
kernels/p6_harness_probe.py
CHANGED
|
@@ -1,15 +1,22 @@
|
|
| 1 |
-
"""Phase 6 pre-flight on free CPU
|
| 2 |
-
|
| 3 |
-
The
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
import json
|
| 15 |
import os
|
|
@@ -25,77 +32,114 @@ PRIMARY_METRIC = {"arc_challenge": "acc,none", "arc_easy": "acc,none", "hellaswa
|
|
| 25 |
"mmlu": "acc,none", "piqa": "acc,none", "truthfulqa_mc1": "acc,none",
|
| 26 |
"truthfulqa_mc2": "acc,none", "winogrande": "acc,none",
|
| 27 |
"gsm8k": "exact_match,flexible-extract"}
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
| 31 |
print("=== " + label, flush=True)
|
| 32 |
p = subprocess.run(argv, capture_output=True, text=True, timeout=timeout)
|
| 33 |
out = (p.stdout or "") + (p.stderr or "")
|
| 34 |
-
print(label, "rc", p.returncode, "
|
| 35 |
return p.returncode, out
|
| 36 |
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
from lm_eval.tasks import TaskManager
|
| 62 |
tm = TaskManager()
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
try:
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
except Exception as e:
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
print("TASKCONFIG"
|
| 82 |
-
""" % (TASKS,)
|
| 83 |
-
|
| 84 |
-
rc, tc = sh([sys.executable, "taskconfig.py"], "task_configs", 900)
|
| 85 |
line = next((l for l in tc.splitlines() if l.startswith("TASKCONFIG ")), "")
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
for t in TASKS:
|
| 88 |
c = cfgs.get(t, {})
|
| 89 |
m = PRIMARY_METRIC[t]
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
print("HARNESS_PROBE_JSON", json.dumps({
|
| 95 |
-
"
|
| 96 |
-
"
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
print("VERDICT P6_HARNESS_PROBE", "OK" if ok else "PROBLEM", "tasks_parsed", len(ids), flush=True)
|
| 101 |
raise SystemExit(0 if ok else 6)
|
|
|
|
| 1 |
+
"""Phase 6 pre-flight on free CPU, second pass: how do we get a working lm-eval without moving the image?
|
| 2 |
+
|
| 3 |
+
The first pass (12:13Z) answered a question nobody had asked and killed two assumptions at once:
|
| 4 |
+
|
| 5 |
+
* `pip install --user --no-deps lm-eval==0.4.13` **cannot be imported at all** -- `lm_eval/api/metrics.py:11`
|
| 6 |
+
does `import sacrebleu` at module scope, so `--tasks list` exits 1 with `ModuleNotFoundError`. The
|
| 7 |
+
`--no-deps` flag was E-045/12's answer to "a resolving install might drop a different transformers into
|
| 8 |
+
~/.local"; it bought that safety at the price of a harness that does not start. Review-found, CPU-proved.
|
| 9 |
+
* The rest of this file's own first draft then died on `%`-formatting a template that contains `%s` specs.
|
| 10 |
+
|
| 11 |
+
So the real question is which install keeps the image's `transformers 5.0.0` and `torch` *and* gets the
|
| 12 |
+
metric libraries. lm-eval declares `transformers>=4.1`, which 5.0.0 already satisfies -- pip leaves a
|
| 13 |
+
satisfied requirement alone -- so a resolving install may be safe here. This measures it rather than
|
| 14 |
+
arguing: it snapshots the versions and file locations of the packages Phase 6 depends on, installs with
|
| 15 |
+
deps, snapshots again, and only then parses `--tasks list` and dumps the nine task configs.
|
| 16 |
+
|
| 17 |
+
**No eval data is touched and none can be:** installing, listing task ids and reading YAML configs never
|
| 18 |
+
calls `datasets.load_dataset`; that happens only when a task is requested against a model, which is
|
| 19 |
+
Phase 6's own step (§3.3).
|
| 20 |
"""
|
| 21 |
import json
|
| 22 |
import os
|
|
|
|
| 32 |
"mmlu": "acc,none", "piqa": "acc,none", "truthfulqa_mc1": "acc,none",
|
| 33 |
"truthfulqa_mc2": "acc,none", "winogrande": "acc,none",
|
| 34 |
"gsm8k": "exact_match,flexible-extract"}
|
| 35 |
+
WATCH = ["transformers", "torch", "numpy", "pandas", "datasets", "evaluate", "accelerate", "scipy",
|
| 36 |
+
"sympy", "sacrebleu", "lm_eval"]
|
| 37 |
|
| 38 |
+
SNAPSHOT = """
|
| 39 |
+
import importlib.metadata as md, json, os, sys
|
| 40 |
+
out = {}
|
| 41 |
+
for name in %s:
|
| 42 |
+
try:
|
| 43 |
+
mod = __import__(name)
|
| 44 |
+
where = getattr(mod, "__file__", None) or "?"
|
| 45 |
+
except Exception:
|
| 46 |
+
where = None
|
| 47 |
+
try:
|
| 48 |
+
ver = md.version(name.replace("_", "-"))
|
| 49 |
+
except Exception:
|
| 50 |
+
ver = getattr(__import__(name), "__version__", None) if where else None
|
| 51 |
+
out[name] = {"version": str(ver) if ver else None,
|
| 52 |
+
"file": where, "user_dir": bool(where and "/.local/" in where)}
|
| 53 |
+
print("SNAPSHOT " + json.dumps(out, default=str))
|
| 54 |
+
""" % (WATCH,)
|
| 55 |
|
| 56 |
+
|
| 57 |
+
def sh(argv, label, timeout=2400):
|
| 58 |
print("=== " + label, flush=True)
|
| 59 |
p = subprocess.run(argv, capture_output=True, text=True, timeout=timeout)
|
| 60 |
out = (p.stdout or "") + (p.stderr or "")
|
| 61 |
+
print(label, "rc", p.returncode, "chars", len(out), flush=True)
|
| 62 |
return p.returncode, out
|
| 63 |
|
| 64 |
|
| 65 |
+
def snapshot(label):
|
| 66 |
+
open("snap.py", "w").write(SNAPSHOT)
|
| 67 |
+
rc, out = sh([sys.executable, "snap.py"], "snapshot_" + label, 600)
|
| 68 |
+
line = next((l for l in out.splitlines() if l.startswith("SNAPSHOT ")), "")
|
| 69 |
+
d = json.loads(line[len("SNAPSHOT "):]) if line else {}
|
| 70 |
+
for k, v in sorted(d.items()):
|
| 71 |
+
print(" %-12s %-10s %s" % (k, v["version"], ("<USER>" if v["user_dir"] else v["file"])),
|
| 72 |
+
flush=True)
|
| 73 |
+
return d
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def parse_ids(text):
|
| 77 |
+
return set(re.findall(r"^\s*(?:-\s*)?([a-z][a-z0-9_]{2,})\s*$", text, re.M))
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
before = snapshot("before")
|
| 81 |
+
|
| 82 |
+
rc, out = sh([sys.executable, "-m", "pip", "install", "--user", "--quiet",
|
| 83 |
+
"lm-eval==" + PIN], "pip_install_with_deps", 2400)
|
| 84 |
+
print(" ", out.strip()[-400:], flush=True)
|
| 85 |
+
after = snapshot("after")
|
| 86 |
+
moved = {k: (before.get(k, {}).get("version"), v["version"])
|
| 87 |
+
for k, v in after.items() if before.get(k, {}).get("version") != v["version"]
|
| 88 |
+
and k != "lm_eval"}
|
| 89 |
+
print("PIP_MOVED", json.dumps(moved, default=str), flush=True)
|
| 90 |
+
assert after["transformers"]["version"] == "5.0.0", "transformers moved off 5.0.0"
|
| 91 |
+
assert after["transformers"]["file"] == before["transformers"]["file"], "transformers moved location"
|
| 92 |
+
|
| 93 |
+
rc, listed = sh([sys.executable, "-m", "lm_eval", "--tasks", "list"], "tasks_list", 1200)
|
| 94 |
+
ids = parse_ids(listed)
|
| 95 |
+
print("PARSED_IDS", len(ids), "all nine present:", all(t in ids for t in TASKS), flush=True)
|
| 96 |
+
if not ids:
|
| 97 |
+
print("RAW_TAIL", repr(listed[-1500:]), flush=True)
|
| 98 |
+
|
| 99 |
+
open("taskconfig.py", "w").write("""
|
| 100 |
+
import json
|
| 101 |
from lm_eval.tasks import TaskManager
|
| 102 |
tm = TaskManager()
|
| 103 |
+
try:
|
| 104 |
+
out = {"index_type": str(type(next(iter(tm.task_index.values()))))}
|
| 105 |
+
except Exception as e:
|
| 106 |
+
out = {"index_type": "empty or unreachable: " + type(e).__name__}
|
| 107 |
+
recs = {}
|
| 108 |
+
for t in %s:
|
| 109 |
+
r = {"registered": t in tm.task_index}
|
| 110 |
try:
|
| 111 |
+
item = tm.task_index[t]
|
| 112 |
+
cfg = item if isinstance(item, dict) else getattr(item, "config", {})
|
| 113 |
+
r["keys"] = sorted(cfg)[:14]
|
| 114 |
+
r["num_fewshot"] = cfg.get("num_fewshot")
|
| 115 |
+
r["metric_list"] = [(m.get("metric_uri") if isinstance(m, dict) else m)
|
| 116 |
+
for m in (cfg.get("metric_list") or [])]
|
| 117 |
+
r["dataset_path"] = cfg.get("dataset_path")
|
| 118 |
+
r["dataset_name"] = cfg.get("dataset_name")
|
| 119 |
+
r["test_split"] = cfg.get("test_split")
|
| 120 |
+
r["validation_split"] = cfg.get("validation_split")
|
| 121 |
+
r["fewshot_split"] = cfg.get("fewshot_split")
|
| 122 |
except Exception as e:
|
| 123 |
+
r["error"] = "%%s: %%s" %% (type(e).__name__, str(e)[:220])
|
| 124 |
+
recs[t] = r
|
| 125 |
+
print("TASKCONFIG " + json.dumps({"meta": out, "tasks": recs}, default=str))
|
| 126 |
+
""" % (TASKS,))
|
| 127 |
+
rc, tc = sh([sys.executable, "taskconfig.py"], "task_configs", 1200)
|
|
|
|
| 128 |
line = next((l for l in tc.splitlines() if l.startswith("TASKCONFIG ")), "")
|
| 129 |
+
info = json.loads(line[len("TASKCONFIG "):]) if line else {"meta": {}, "tasks": {}}
|
| 130 |
+
cfgs = info.get("tasks", {})
|
| 131 |
+
print("TASKCONFIG_META", json.dumps(info.get("meta"), default=str), flush=True)
|
| 132 |
for t in TASKS:
|
| 133 |
c = cfgs.get(t, {})
|
| 134 |
m = PRIMARY_METRIC[t]
|
| 135 |
+
print("TASK %-16s fewshot=%-6s test=%-10s val=%-8s metric %-34s declared=%s" % (
|
| 136 |
+
t, c.get("num_fewshot"), c.get("test_split"), c.get("validation_split"), m,
|
| 137 |
+
m in (c.get("metric_list") or [])), flush=True)
|
| 138 |
|
| 139 |
print("HARNESS_PROBE_JSON", json.dumps({
|
| 140 |
+
"pip_moved": moved, "tasks_listed": len(ids), "all_present": all(t in ids for t in TASKS),
|
| 141 |
+
"primary_declared": {t: PRIMARY_METRIC[t] in (cfgs.get(t) or {}).get("metric_list", [])
|
| 142 |
+
for t in TASKS}, "configs": cfgs}, default=str)[:6000], flush=True)
|
| 143 |
+
ok = bool(ids) and all(t in ids for t in TASKS) and bool(cfgs)
|
| 144 |
+
print("VERDICT P6_HARNESS_PROBE", "OK" if ok else "PROBLEM", flush=True)
|
|
|
|
| 145 |
raise SystemExit(0 if ok else 6)
|