Cion-lab commited on
Commit
5f5b188
·
verified ·
1 Parent(s): 8ec129e

p6_cli_probe v3: build metric keys from the YAML's own metric/aggregation fields and rank candidate config files -- the first pass guessed metric_uri and picked a mmlu subject file

Browse files
Files changed (1) hide show
  1. kernels/p6_cli_probe.py +55 -24
kernels/p6_cli_probe.py CHANGED
@@ -106,40 +106,71 @@ def resolve(path, depth=0, seen=None):
106
  return d
107
 
108
 
109
- def find_yaml(name):
110
- exact = os.path.join(tasks_dir, name + ".yaml")
111
- if os.path.exists(exact):
112
- return exact
113
- hits = []
114
- for pat in ("**/" + name + ".yaml", "**/" + name + "/*.yaml", "**/*.yaml"):
115
- hits = [p for p in glob.glob(os.path.join(tasks_dir, pat), recursive=True)
116
- if load_yaml(p).get("task") == name or os.path.basename(p) == name + ".yaml"]
117
- if hits:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  break
119
- if not hits: # grouped configs declare their fields in a template the group members include
120
- hits = [p for p in glob.glob(os.path.join(tasks_dir, "**", "*.yaml"), recursive=True)
121
- if name in os.path.relpath(p, tasks_dir).replace("\\", "/").split("/")]
122
- return hits[0] if hits else None
123
 
124
 
125
  print("TASKS_DIR", tasks_dir, os.path.isdir(tasks_dir), flush=True)
126
  report = {}
127
  for t in TASKS:
128
- y = find_yaml(t)
129
- if not y:
130
  report[t] = {"file": None}
 
131
  continue
 
132
  c = resolve(y)
133
- metrics = [(m.get("metric_uri") if isinstance(m, dict) else m)
134
- for m in (c.get("metric_list") or [])]
135
- report[t] = {"file": os.path.relpath(y, tasks_dir), "num_fewshot": c.get("num_fewshot"),
136
- "test_split": c.get("test_split"), "validation_split": c.get("validation_split"),
137
- "fewshot_split": c.get("fewshot_split"), "metric_list": metrics,
138
- "dataset_path": c.get("dataset_path"), "dataset_name": c.get("dataset_name"),
139
- "metric_declared": PRIMARY_METRIC[t] in metrics}
140
- print("YAML %-16s %-34s fewshot=%-6s test=%-10s val=%-9s fs=%-6s metric_declared=%s" % (
 
 
 
 
141
  t, report[t]["file"], c.get("num_fewshot"), c.get("test_split"), c.get("validation_split"),
142
- c.get("fewshot_split"), report[t]["metric_declared"]), flush=True)
 
143
 
144
  ok = not missing and all(report[t].get("metric_declared") for t in TASKS) and \
145
  all(report[t].get("file") for t in TASKS)
 
106
  return d
107
 
108
 
109
+ def candidates(name):
110
+ """Every YAML that could be the config `--tasks <name>` means, best-guess first.
111
+
112
+ The first pass picked `mmlu/flan_cot_fewshot/mmlu_formal_logic.yaml` for `mmlu` -- a subject file of a
113
+ different variant -- so ranking is explicit now, and the winner is printed alongside the raw metric
114
+ block so a wrong pick is visible rather than silent.
115
+ """
116
+ hits = glob.glob(os.path.join(tasks_dir, "**", name + ".yaml"), recursive=True)
117
+ exact = [h for h in hits if os.path.basename(h) == name + ".yaml"]
118
+ tmpl = [h for h in hits if "_default_template" in h or h.endswith("default.yaml")]
119
+ named = []
120
+ for p in glob.glob(os.path.join(tasks_dir, "**", "*.yaml"), recursive=True):
121
+ if os.path.basename(p).startswith("_"):
122
+ continue
123
+ d = load_yaml(p)
124
+ if d.get("task") == name or d.get("group") == name:
125
+ named.append(p)
126
+ ordered = []
127
+ for h in exact + named + tmpl + hits:
128
+ if h not in ordered:
129
+ ordered.append(h)
130
+ return ordered
131
+
132
+
133
+ def raw_metrics(path):
134
+ """The metric block exactly as the YAML spells it, with the key names lm-eval actually uses."""
135
+ try:
136
+ with open(path, encoding="utf-8") as fh:
137
+ txt = fh.read()
138
+ except Exception:
139
+ return "UNREADABLE"
140
+ lines, out = txt.splitlines(), []
141
+ for i, l in enumerate(lines):
142
+ if "metric" in l.lower() or "include" in l.lower() or "num_fewshot" in l:
143
+ out.append(l.strip()[:90])
144
+ if len(out) > 7:
145
  break
146
+ return " | ".join(out) or "no metric/include lines"
 
 
 
147
 
148
 
149
  print("TASKS_DIR", tasks_dir, os.path.isdir(tasks_dir), flush=True)
150
  report = {}
151
  for t in TASKS:
152
+ cands = candidates(t)
153
+ if not cands:
154
  report[t] = {"file": None}
155
+ print("YAML %-16s NO CANDIDATE FILES" % t, flush=True)
156
  continue
157
+ y = cands[0]
158
  c = resolve(y)
159
+ ml = c.get("metric_list") or []
160
+ names = [(m.get("metric") if isinstance(m, dict) else m) for m in ml]
161
+ aggs = [(m.get("aggregation") if isinstance(m, dict) else None) for m in ml]
162
+ keys = ["%s,%s" % (n, a) for n, a in zip(names, aggs)]
163
+ report[t] = {"file": os.path.relpath(y, tasks_dir), "n_candidates": len(cands),
164
+ "others": [os.path.relpath(x, tasks_dir) for x in cands[1:4]],
165
+ "num_fewshot": c.get("num_fewshot"), "test_split": c.get("test_split"),
166
+ "validation_split": c.get("validation_split"), "fewshot_split": c.get("fewshot_split"),
167
+ "metric_names": names, "metric_keys": keys, "dataset_path": c.get("dataset_path"),
168
+ "dataset_name": c.get("dataset_name"),
169
+ "metric_declared": PRIMARY_METRIC[t] in keys}
170
+ print("YAML %-16s %-38s fewshot=%-6s test=%-9s val=%-10s fs=%-7s keys=%s declared=%s" % (
171
  t, report[t]["file"], c.get("num_fewshot"), c.get("test_split"), c.get("validation_split"),
172
+ c.get("fewshot_split"), keys, report[t]["metric_declared"]), flush=True)
173
+ print(" RAW %s" % raw_metrics(y)[:220], flush=True)
174
 
175
  ok = not missing and all(report[t].get("metric_declared") for t in TASKS) and \
176
  all(report[t].get("file") for t in TASKS)