Cion-lab commited on
Commit
1a8377a
·
verified ·
1 Parent(s): 1742ac7

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
Files changed (1) hide show
  1. 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: does the pinned harness work on this image, and what does it declare?
2
-
3
- The unknown this closes is not the model's score but the toolchain: `lm-eval` 0.4.13 was pinned in 2024 and
4
- the Kaggle image ships transformers 5.0.0, a combination nobody here has run (docs/05 §7 flagged it, §5 of
5
- the plan refuses to discover it after six billed GPU hours). It also checks the three things E-045/E-046
6
- rely on and that E-045 could only reason about: the real shape of `--tasks list` output that the new
7
- hard-failing guard parses, which `num_fewshot` each pinned task actually declares, and the exact
8
- `<metric>,<split>` key names that `PRIMARY_METRIC` promises to read out of results.json.
9
-
10
- **No eval data is touched here, and none can be.** Everything read comes from the tasks' YAML configs:
11
- `TaskManager.include_task` builds a task object from its config, and `datasets.load_dataset` is not called
12
- until a request is made — no model is loaded, no split is downloaded, no item is read (§3.3).
 
 
 
 
 
 
 
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
- def sh(argv, label, timeout=1800):
 
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, "lines", len(out.splitlines()), flush=True)
35
  return p.returncode, out
36
 
37
 
38
- rc, v = sh([sys.executable, "-c", "import transformers, os; print(transformers.__version__, "
39
- "os.path.dirname(transformers.__file__))"], "transformers")
40
- print(" |", v.strip()[:200], flush=True)
41
- tf_ver = v.split()[0] if v.split() else "?"
42
-
43
- rc, out = sh([sys.executable, "-m", "pip", "install", "--user", "--quiet", "--no-deps",
44
- "lm-eval==" + PIN], "pip_install")
45
- rc, v2 = sh([sys.executable, "-c", "import transformers, os; print(transformers.__version__, "
46
- "os.path.dirname(transformers.__file__))"], "transformers_after")
47
- print(" |", v2.strip()[:200], flush=True)
48
- assert tf_ver == v2.split()[0], "installing the harness moved transformers: %s -> %s" % (tf_ver, v2)
49
-
50
- rc, listed = sh([sys.executable, "-m", "lm_eval", "--tasks", "list"], "tasks_list", 900)
51
- # The same expression run_benchmarks.py uses, evaluated here against the real output so the guard is known
52
- # to parse something rather than assumed (E-045/6 became a hard failure on the strength of a guess).
53
- ids = set(re.findall(r"^\s*(?:-\s*)?([a-z][a-z0-9_]{2,})\s*$", listed, re.M))
54
- print("PARSED_IDS", len(ids), "| requested present:",
55
- {t: (t in ids) for t in TASKS}, flush=True)
56
- print("SAMPLE_RAW", repr(listed[-600:]), flush=True)
57
-
58
- probe = r"""
59
- import json, sys, warnings
60
- warnings.filterwarnings("ignore")
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  from lm_eval.tasks import TaskManager
62
  tm = TaskManager()
63
- out = {}
64
- for t in %r:
65
- rec = {"registered": t in tm.task_index}
 
 
 
 
66
  try:
67
- cfg = tm.task_index[t]
68
- rec["num_fewshot"] = cfg.get("num_fewshot")
69
- rec["metric_list"] = [m.get("metric_uri") if isinstance(m, dict) else m
70
- for m in (cfg.get("metric_list") or [])]
71
- rec["aggregation"] = [m.get("aggregation") for m in (cfg.get("metric_list") or [])
72
- if isinstance(m, dict)]
73
- rec["dataset_path"] = cfg.get("dataset_path")
74
- rec["dataset_name"] = cfg.get("dataset_name")
75
- rec["test_split"] = cfg.get("test_split")
76
- rec["validation_split"] = cfg.get("validation_split")
77
- rec["fewshot_split"] = cfg.get("fewshot_split")
78
  except Exception as e:
79
- rec["error"] = "%s: %s" % (type(e).__name__, str(e)[:200])
80
- out[t] = rec
81
- print("TASKCONFIG", json.dumps(out, default=str))
82
- """ % (TASKS,)
83
- open("taskconfig.py", "w").write(probe)
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
- cfgs = json.loads(line[len("TASKCONFIG "):]) if line else {}
 
 
87
  for t in TASKS:
88
  c = cfgs.get(t, {})
89
  m = PRIMARY_METRIC[t]
90
- metrics = c.get("metric_list") or []
91
- print("TASK %-16s fewshot=%-5s split=%-12s metric %s declared=%s" % (
92
- t, c.get("num_fewshot"), c.get("test_split"), m, m in metrics), flush=True)
93
 
94
  print("HARNESS_PROBE_JSON", json.dumps({
95
- "lm_eval_pin": PIN, "transformers": tf_ver, "tasks_listed": len(ids),
96
- "all_requested_present": all(t in ids for t in TASKS),
97
- "configs": cfgs, "primary_metric_declared": {t: PRIMARY_METRIC[t] in (cfgs.get(t) or {}).get(
98
- "metric_list", []) for t in TASKS}}, default=str), flush=True)
99
- ok = all(t in ids for t in TASKS) and bool(cfgs)
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)