j-chim commited on
Commit
62c5d14
·
verified ·
1 Parent(s): 11c3a47

Deploy eval-card-registry service

Browse files
Files changed (1) hide show
  1. src/eval_card_registry/cli.py +60 -1
src/eval_card_registry/cli.py CHANGED
@@ -459,9 +459,68 @@ def seed(
459
  # `non_lineage_bases`: underspecified umbrella ids that stay resolvable
460
  # but may never be a lineage PARENT (see collision_overrides.yaml).
461
  non_lineage_bases = set(ov.get("non_lineage_bases") or [])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  merged, _remap = collision_fold.fold_collisions(
463
  merged, never_fold, prefer,
464
- force_merge={**_org_merges, **curated_merge},
465
  non_lineage_bases=non_lineage_bases,
466
  )
467
 
 
459
  # `non_lineage_bases`: underspecified umbrella ids that stay resolvable
460
  # but may never be a lineage PARENT (see collision_overrides.yaml).
461
  non_lineage_bases = set(ov.get("non_lineage_bases") or [])
462
+ # An HF-true canonical (oracle-sourced, or HF-promoted by the models.dev
463
+ # refresh with `hf_deferred`) carries the invented ids it replaced as
464
+ # aliases. A side source the refresh never rewrites (enrichments,
465
+ # tier3, hub_stats) may still key a record by such an id; left alone it
466
+ # materialises a second canonical that collides on the alias. Fold
467
+ # those records onto the HF entry, like a curated `merge` (core ids are
468
+ # never folded this way).
469
+ core_ids = {e["id"] for e in core_entries}
470
+ # A multi-child family root (`alibaba/qwen3-vl-235b-a22b` over Instruct
471
+ # and Thinking) is not one repo and stays a root, like an umbrella.
472
+ kids: dict[str, set[str]] = {}
473
+ for e in merged:
474
+ for p in collision_fold._edges(e.get("parents")):
475
+ if not isinstance(p, dict) or p.get("relationship") != "variant":
476
+ continue
477
+ pid = p.get("id")
478
+ if isinstance(pid, str) and pid != e["id"]:
479
+ kids.setdefault(pid, set()).add(e["id"])
480
+ multi_child = {pid for pid, k in kids.items() if len(k) >= 2}
481
+
482
+ def _own_name(old: str, hf_id: str) -> bool:
483
+ return seed_collision_key(old.rsplit("/", 1)[-1]) == seed_collision_key(hf_id.rsplit("/", 1)[-1])
484
+
485
+ def _hf_true(e: dict) -> bool:
486
+ meta = e.get("metadata")
487
+ if isinstance(meta, str):
488
+ try:
489
+ meta = json.loads(meta)
490
+ except ValueError:
491
+ meta = None
492
+ return e.get("resolution_source") == "hf" or (
493
+ isinstance(meta, dict) and meta.get("hf_deferred") is True
494
+ )
495
+
496
+ hf_true_ids = {e["id"] for e in merged if _hf_true(e)}
497
+ core_keys = {collision_fold.collision_key(i) for i in core_ids}
498
+ promoted_merge: dict[str, str] = {}
499
+ for e in merged:
500
+ if e["id"] not in hf_true_ids:
501
+ continue
502
+ for a in e.get("aliases") or []:
503
+ # Never a core id, a curated umbrella, another HF-true
504
+ # canonical, or a multi-child root under a different name.
505
+ if a in core_ids or a in non_lineage_bases or a in hf_true_ids:
506
+ continue
507
+ if a in multi_child and not _own_name(a, e["id"]):
508
+ continue
509
+ if a != e["id"] and a in by_id:
510
+ promoted_merge.setdefault(a, e["id"])
511
+ # A loser that is itself a declared winner would make a cycle.
512
+ promoted_merge = {l: w for l, w in promoted_merge.items() if w not in promoted_merge}
513
+ for l, w in promoted_merge.items():
514
+ # A casing twin shares the collision key; pin the HF id as that
515
+ # group's winner so the group fold cannot pick the alias and leave
516
+ # the two remaps pointing at each other. A key a core entry owns
517
+ # keeps its core winner.
518
+ key = collision_fold.collision_key(w)
519
+ if collision_fold.collision_key(l) == key and key not in core_keys:
520
+ prefer.setdefault(key, w)
521
  merged, _remap = collision_fold.fold_collisions(
522
  merged, never_fold, prefer,
523
+ force_merge={**_org_merges, **promoted_merge, **curated_merge},
524
  non_lineage_bases=non_lineage_bases,
525
  )
526