j-chim commited on
Commit
1167da1
·
verified ·
1 Parent(s): b869b42

Deploy eval-card-registry service

Browse files
src/eval_card_registry/cli.py CHANGED
@@ -7,6 +7,8 @@ Commands:
7
  sync Batch sync one or all EEE configs → eval_results table
8
  """
9
  import json
 
 
10
  from pathlib import Path
11
  from typing import Optional
12
 
@@ -532,8 +534,97 @@ def seed(
532
  by_id[entry["id"]] = _merge_benchmark(by_id[entry["id"]], entry)
533
  else:
534
  by_id[entry["id"]] = entry
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
  return list(by_id.values())
536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
  # ------------------------------------------------------------------
538
  # Families — translate seed/families.yaml's nested {slug: {fields}}
539
  # shape into flat dicts ready for upsert. The YAML uses the slug as
@@ -1144,6 +1235,61 @@ def seed(
1144
  store.set_table("canonical_inference_platforms", inf_plat_df)
1145
  typer.echo(f" inference_platforms: {len(inf_plat_rows)}")
1146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1147
  # Derive denormalized parent-walk caches now that all canonical_models
1148
  # rows are present. `model_group_id` and `lineage_origin_model_org_id`
1149
  # are computed from `parents` and need the full graph to be in place.
 
7
  sync Batch sync one or all EEE configs → eval_results table
8
  """
9
  import json
10
+ import re
11
+ import unicodedata
12
  from pathlib import Path
13
  from typing import Optional
14
 
 
534
  by_id[entry["id"]] = _merge_benchmark(by_id[entry["id"]], entry)
535
  else:
536
  by_id[entry["id"]] = entry
537
+ # `preferred_metric` (seed key) -> `preferred_metric_id` (column),
538
+ # validated against metrics.yaml so a typo can't silently null the
539
+ # merged-view default.
540
+ metrics_path = seed_path / "metrics.yaml"
541
+ metric_ids: set[str] = set()
542
+ if metrics_path.exists():
543
+ with open(metrics_path) as f:
544
+ metric_ids = {m["id"] for m in (yaml.safe_load(f) or [])}
545
+ for entry in by_id.values():
546
+ pm = entry.pop("preferred_metric", None)
547
+ if pm is not None:
548
+ if pm not in metric_ids:
549
+ raise typer.BadParameter(
550
+ f"benchmark {entry['id']!r}: preferred_metric {pm!r} "
551
+ f"is not a canonical metric id"
552
+ )
553
+ entry["preferred_metric_id"] = pm
554
+
555
+ _check_benchmark_collisions(list(by_id.values()))
556
  return list(by_id.values())
557
 
558
+ def _check_benchmark_collisions(entries: list[dict]) -> None:
559
+ """Seed-time guard: two benchmarks whose ids, display names, or
560
+ global aliases collapse to the same normalized key (casefold +
561
+ strip non-alphanumerics — stricter than collision_fold's
562
+ separator-only key, so spaced llm-stats-mint aliases like
563
+ "Vita Bench" are covered) are one entity split in two — fold them
564
+ per specs/benchmark-relationships-audit.md §4. Flag-only, never
565
+ auto-folds. Groups verified genuinely distinct go in
566
+ seed/benchmarks_distinct_allowlist.yaml (a list of id groups).
567
+ Residual: semantic dupes with different normalized keys
568
+ (mmmu-val vs mmmu-validation) are invisible to this check.
569
+ Also rejects '/' in benchmark ids — reserved by the merged-view
570
+ URL scheme (single-segment merged eval ids stay collision-free
571
+ with two-segment per-source ids only while benchmark ids are
572
+ slash-free)."""
573
+ allow_path = seed_path / "benchmarks_distinct_allowlist.yaml"
574
+ allowed: list[frozenset[str]] = []
575
+ if allow_path.exists():
576
+ with open(allow_path) as f:
577
+ for group in yaml.safe_load(f) or []:
578
+ allowed.append(frozenset(group))
579
+
580
+ def _norm(s: str) -> str:
581
+ # NFKD + combining-mark strip folds accent variants ("racé" vs
582
+ # "race") into one key before the alphanumeric strip would
583
+ # silently delete the accented char and miss the collision.
584
+ # Residual: cross-script confusables (Cyrillic 'а') still evade.
585
+ decomposed = unicodedata.normalize("NFKD", str(s))
586
+ base = "".join(ch for ch in decomposed if not unicodedata.combining(ch))
587
+ return re.sub(r"[^a-z0-9]", "", base.casefold())
588
+
589
+ # Typo guard: every allowlisted id must name a real benchmark,
590
+ # else a stale/misspelled allowlist entry silently stops guarding.
591
+ all_ids = {str(e["id"]) for e in entries}
592
+ stale = sorted({bid for grp in allowed for bid in grp} - all_ids)
593
+ if stale:
594
+ raise typer.BadParameter(
595
+ f"benchmarks_distinct_allowlist.yaml names unknown benchmark id(s): {stale}"
596
+ )
597
+
598
+ key_owners: dict[str, set[str]] = {}
599
+ for e in entries:
600
+ bid = str(e["id"])
601
+ if "/" in bid:
602
+ raise typer.BadParameter(
603
+ f"benchmark id {bid!r} contains '/' (reserved for merged-view routing)"
604
+ )
605
+ # id + display_name + aliases: all three become resolver
606
+ # aliases at seed time (display_name is auto-promoted), so all
607
+ # three can carry a dupe in.
608
+ keys = {_norm(bid)}
609
+ if e.get("display_name"):
610
+ keys.add(_norm(e["display_name"]))
611
+ keys |= {_norm(a) for a in (e.get("aliases") or []) if a}
612
+ keys.discard("")
613
+ for k in keys:
614
+ key_owners.setdefault(k, set()).add(bid)
615
+ conflicts = [
616
+ sorted(ids)
617
+ for ids in key_owners.values()
618
+ if len(ids) > 1 and not any(ids <= grp for grp in allowed)
619
+ ]
620
+ if conflicts:
621
+ listing = "; ".join(str(g) for g in sorted(conflicts))
622
+ raise typer.BadParameter(
623
+ f"{len(conflicts)} separator/case-collision group(s) among benchmark "
624
+ f"ids+aliases — fold them (audit spec §4) or allowlist in "
625
+ f"benchmarks_distinct_allowlist.yaml: {listing}"
626
+ )
627
+
628
  # ------------------------------------------------------------------
629
  # Families — translate seed/families.yaml's nested {slug: {fields}}
630
  # shape into flat dicts ready for upsert. The YAML uses the slug as
 
1235
  store.set_table("canonical_inference_platforms", inf_plat_df)
1236
  typer.echo(f" inference_platforms: {len(inf_plat_rows)}")
1237
 
1238
+ # ------------------------------------------------------------------
1239
+ # Benchmark metric folds — flat dim table (no entity ids, so it skips
1240
+ # the seed_specs/upsert path). Entries state that `from_metric` on
1241
+ # `benchmark` is the preferred measurement under a generic name.
1242
+ # ------------------------------------------------------------------
1243
+ folds_path = seed_path / "metric_folds.yaml"
1244
+ if folds_path.exists():
1245
+ import pandas as pd
1246
+
1247
+ with open(folds_path) as f:
1248
+ fold_entries = yaml.safe_load(f) or []
1249
+ if not isinstance(fold_entries, list):
1250
+ raise typer.BadParameter(f"{folds_path} must be a flat list")
1251
+ bench_ids = {e["id"] for e in _load_benchmarks_merged()}
1252
+ fold_metrics_path = seed_path / "metrics.yaml"
1253
+ metric_ids = set()
1254
+ if fold_metrics_path.exists():
1255
+ with open(fold_metrics_path) as f:
1256
+ metric_ids = {m["id"] for m in (yaml.safe_load(f) or [])}
1257
+ seen_pairs: set[tuple[str, str]] = set()
1258
+ fold_rows = []
1259
+ for e in fold_entries:
1260
+ b, fm, tm = e.get("benchmark"), e.get("from_metric"), e.get("to_metric")
1261
+ if not (b and fm and tm):
1262
+ raise typer.BadParameter(f"metric_folds entry needs benchmark/from_metric/to_metric: {e!r}")
1263
+ if b not in bench_ids:
1264
+ raise typer.BadParameter(f"metric_folds: unknown benchmark {b!r}")
1265
+ missing = [m for m in (fm, tm) if m not in metric_ids]
1266
+ if missing:
1267
+ raise typer.BadParameter(f"metric_folds ({b}): unknown metric id(s) {missing}")
1268
+ if fm == tm:
1269
+ raise typer.BadParameter(f"metric_folds ({b}): self-fold {fm!r}")
1270
+ if (b, fm) in seen_pairs:
1271
+ raise typer.BadParameter(f"metric_folds: duplicate fold for ({b}, {fm})")
1272
+ seen_pairs.add((b, fm))
1273
+ factor = e.get("scale_factor")
1274
+ if factor is not None and (not isinstance(factor, (int, float)) or factor <= 0):
1275
+ raise typer.BadParameter(
1276
+ f"metric_folds ({b}): scale_factor must be a positive number, got {factor!r}"
1277
+ )
1278
+ fold_rows.append({
1279
+ "benchmark_id": b, "from_metric_id": fm,
1280
+ "to_metric_id": tm, "scale_factor": factor, "note": e.get("note"),
1281
+ })
1282
+ # No chains: a fold target must not itself be folded on the same benchmark.
1283
+ targets = {(r["benchmark_id"], r["to_metric_id"]) for r in fold_rows}
1284
+ chained = sorted(targets & seen_pairs)
1285
+ if chained:
1286
+ raise typer.BadParameter(f"metric_folds: chained folds {chained}")
1287
+ folds_df = pd.DataFrame(
1288
+ fold_rows, columns=list(schemas._SCHEMAS["benchmark_metric_folds"].keys())
1289
+ )
1290
+ store.set_table("benchmark_metric_folds", folds_df)
1291
+ typer.echo(f" metric_folds: {len(fold_rows)}")
1292
+
1293
  # Derive denormalized parent-walk caches now that all canonical_models
1294
  # rows are present. `model_group_id` and `lineage_origin_model_org_id`
1295
  # are computed from `parents` and need the full graph to be in place.
src/eval_card_registry/store/hf_store.py CHANGED
@@ -34,6 +34,7 @@ TABLE_NAMES = [
34
  "canonical_families",
35
  "canonical_composites",
36
  "canonical_metrics",
 
37
  "eval_harnesses",
38
  "canonical_inference_platforms",
39
  "aliases",
 
34
  "canonical_families",
35
  "canonical_composites",
36
  "canonical_metrics",
37
+ "benchmark_metric_folds",
38
  "eval_harnesses",
39
  "canonical_inference_platforms",
40
  "aliases",
src/eval_card_registry/store/schemas.py CHANGED
@@ -103,6 +103,9 @@ _SCHEMAS: dict[str, dict] = {
103
  "description": pd.StringDtype(),
104
  "dataset_repo": pd.StringDtype(),
105
  "parent_benchmark_id": pd.StringDtype(),
 
 
 
106
  "tags": pd.StringDtype(),
107
  "metadata": pd.StringDtype(),
108
  "review_status": pd.StringDtype(),
@@ -180,6 +183,21 @@ _SCHEMAS: dict[str, dict] = {
180
  "created_at": pd.StringDtype(),
181
  "updated_at": pd.StringDtype(),
182
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  "eval_harnesses": {
184
  "id": pd.StringDtype(),
185
  "display_name": pd.StringDtype(),
 
103
  "description": pd.StringDtype(),
104
  "dataset_repo": pd.StringDtype(),
105
  "parent_benchmark_id": pd.StringDtype(),
106
+ # Registry-declared default metric for the merged benchmark view
107
+ # (seed key `preferred_metric`). Null → consumer fallback rules.
108
+ "preferred_metric_id": pd.StringDtype(),
109
  "tags": pd.StringDtype(),
110
  "metadata": pd.StringDtype(),
111
  "review_status": pd.StringDtype(),
 
183
  "created_at": pd.StringDtype(),
184
  "updated_at": pd.StringDtype(),
185
  },
186
+ # Curated per-benchmark metric naming folds (seed/metric_folds.yaml):
187
+ # `from_metric_id` on `benchmark_id` is the same measurement as
188
+ # `to_metric_id` under a generic name. Naming folds ONLY — protocol
189
+ # variants (cot-correct vs accuracy) never fold. Consumed by the
190
+ # producer to compute `metric_id_effective` for the merged view.
191
+ "benchmark_metric_folds": {
192
+ "benchmark_id": pd.StringDtype(),
193
+ "from_metric_id": pd.StringDtype(),
194
+ "to_metric_id": pd.StringDtype(),
195
+ # Optional curated published-scale -> registry-scale multiplier
196
+ # (e.g. 0.1 for a raw 1-10 score folding onto a [0,1] metric).
197
+ # Null = scales already agree; detection-based conversion applies.
198
+ "scale_factor": "float64",
199
+ "note": pd.StringDtype(),
200
+ },
201
  "eval_harnesses": {
202
  "id": pd.StringDtype(),
203
  "display_name": pd.StringDtype(),