Spaces:
Running
Running
Upload folder using huggingface_hub
Browse filesFiles changed (13)
- packages/eval-entity-resolver/src/eval_entity_resolver/__init__.py+2
- packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/__init__.cpython-311.pyc
- packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/__init__.cpython-314.pyc
- packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/display.cpython-311.pycAdded
- packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/display.cpython-314.pycAdded
- packages/eval-entity-resolver/src/eval_entity_resolver/display.pyAdded+183
- src/eval_card_registry/__pycache__/cli.cpython-314.pyc
- src/eval_card_registry/services/__pycache__/hub_stats.cpython-314.pyc
- src/eval_card_registry/services/__pycache__/resolution_service.cpython-314.pyc
- src/eval_card_registry/services/hub_stats.py+13
- src/eval_card_registry/services/resolution_service.py+10-1
- src/eval_card_registry/store/__pycache__/queries.cpython-314.pyc
- src/eval_card_registry/store/queries.py+24-9
123456 unmodified lines12131415from eval_entity_resolver.alias_store import AliasStorefrom eval_entity_resolver.canonical_store import CanonicalStorefrom eval_entity_resolver.eee import clean_eval_name, extract_metricfrom eval_entity_resolver.models import ResolutionResult, ResolverConfigfrom eval_entity_resolver.resolver import Resolver6 unmodified lines"ResolutionResult","clean_eval_name","extract_metric",]1234566 unmodified lines1314151617from eval_entity_resolver.alias_store import AliasStorefrom eval_entity_resolver.canonical_store import CanonicalStorefrom eval_entity_resolver.display import humanize_model_slugfrom eval_entity_resolver.eee import clean_eval_name, extract_metricfrom eval_entity_resolver.models import ResolutionResult, ResolverConfigfrom eval_entity_resolver.resolver import Resolver6 unmodified lines"ResolutionResult","clean_eval_name","extract_metric","humanize_model_slug",]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183"""Display-name humanization for canonical model slugs.
Single source of truth for converting machine slugs (`gpt-4o-2024-05-13`) intohuman-friendly display names (`GPT-4o (2024-05-13)`). Used by refresh scriptsand the seed migration; consumers (frontend, API) should NOT re-humanize butread `canonical_models.display_name` directly.
Rules in priority order:1. Strip org prefix (`openai/gpt-5` -> `gpt-5`).2. Strip and parenthesize a trailing date suffix: - `-YYYY-MM-DD` -> ` (YYYY-MM-DD)` - `-YYYYMMDD` -> ` (YYYY-MM-DD)` - `-MMDD` (4-digit) -> ` (MMDD)`3. Per-token formatting: - Known acronyms render uppercase (`gpt` -> `GPT`). - Mixed-case overrides apply (`moe` -> `MoE`). - Param sizes uppercase the unit (`7b` -> `7B`, `a22b` -> `A22B`, `8x7b` -> `8x7B`, `30m` -> `30M`). - Number+letter version tags preserve case (`4o` -> `4o`). - O-series stays lowercase (`o1`, `o3`). - Vendor-name overrides (`deepseek` -> `DeepSeek`). - Default: capitalize first letter.4. Glue an acronym token to the next token with a hyphen when the next token is a bare version number (digits + optional `.NN` + optional single non-size letter): `GPT 5 Mini` -> `GPT-5 Mini`, `GPT 4o ...` -> `GPT-4o ...`. Skipped when the next token is a param size like `7B`."""
from __future__ import annotations
import re
ACRONYMS: frozenset[str] = frozenset( { "gpt", "glm", "llm", "vl", "vlm", "qvq", "qwq", "mt", "vit", "clip", "dit", "hf", "ocr", "tts", "asr", "moe", "mlp", "rlhf", })
# Tokens whose canonical rendering is mixed case rather than ALL CAPS.CASE_OVERRIDES: dict[str, str] = { "moe": "MoE", "vit": "ViT", "dit": "DiT",}
# Vendor / family tokens whose canonical rendering doesn't match a simple# capitalize() — e.g., `deepseek` should display as `DeepSeek`. Keep the# list short; this is for tokens the auto-rule mangles, not a general# branding registry.TOKEN_OVERRIDES: dict[str, str] = { "deepseek": "DeepSeek", "openai": "OpenAI", "stepfun": "StepFun", "moonshotai": "MoonshotAI", "mistralai": "MistralAI",}
# Suffixes treated as parameter-count units, NOT version letters. When a# token like `7b` appears after an acronym, we do NOT hyphen-glue it._SIZE_SUFFIXES: frozenset[str] = frozenset({"b", "m", "k"})
def humanize_model_slug(slug: str) -> str: """Render a model slug as a human display name.
Accepts a bare slug (`gpt-4o-2024-05-13`) or a full canonical id (`openai/gpt-4o-2024-05-13`); the org prefix is dropped. """ if not slug: return "" if "/" in slug: slug = slug.split("/", 1)[1]
slug, suffix = _strip_date_suffix(slug)
tokens = slug.split("-") formatted = [_format_token(t) for t in tokens]
out: list[str] = [] i = 0 while i < len(formatted): cur_lower = tokens[i].lower() if ( i + 1 < len(formatted) and cur_lower in ACRONYMS and _is_version_token(tokens[i + 1]) ): out.append(f"{formatted[i]}-{formatted[i + 1]}") i += 2 else: out.append(formatted[i]) i += 1
return " ".join(out) + suffix
def _strip_date_suffix(slug: str) -> tuple[str, str]: """Pop a trailing date or 4-digit code; return (slug_without, ' (suffix)').
Order matters: more specific patterns first, since a partial match against a less-specific pattern would mis-render (e.g. `2025` as a bare 4-digit code when it's actually the year half of `2025-08`). """ # Full ISO date: `-YYYY-MM-DD` m = re.search(r"-(20\d{2}-\d{2}-\d{2})$", slug) if m: return slug[: m.start()], f" ({m.group(1)})" # Compact date: `-YYYYMMDD` m = re.search(r"-(20\d{6})$", slug) if m: d = m.group(1) return slug[: m.start()], f" ({d[:4]}-{d[4:6]}-{d[6:8]})" # Year-month: `-YYYY-MM` (e.g. `gpt-5-2025-08`) m = re.search(r"-(20\d{2})-(\d{2})$", slug) if m: return slug[: m.start()], f" ({m.group(1)}-{m.group(2)})" # Cohere convention: `-MM-YYYY` (e.g. `command-r-08-2024`). # Render as `(YYYY-MM)` for ISO-ordered display. m = re.search(r"-(\d{2})-(20\d{2})$", slug) if m: return slug[: m.start()], f" ({m.group(2)}-{m.group(1)})" # Bare 4-digit code: `-NNNN` (e.g. `grok-4-0709`, `kimi-k2-0711`). m = re.search(r"-(\d{4})$", slug) if m: return slug[: m.start()], f" ({m.group(1)})" return slug, ""
def _format_token(tok: str) -> str: if not tok: return tok low = tok.lower() if low in CASE_OVERRIDES: return CASE_OVERRIDES[low] if low in ACRONYMS: return low.upper() if low in TOKEN_OVERRIDES: return TOKEN_OVERRIDES[low] # Param size: 7b, 70b, 1.5b, 30m if re.fullmatch(r"\d+(?:\.\d+)?[bmk]", low): return low[:-1] + low[-1].upper() # MoE active-expert form: a22b, a3b if re.fullmatch(r"a\d+(?:\.\d+)?b", low): return "A" + low[1:-1] + "B" # MxNb: 8x7b -> 8x7B if re.fullmatch(r"\d+x\d+(?:\.\d+)?b", low): return low[:-1] + "B" # Number followed by a single lowercase letter that's NOT a size suffix: # version tags like `4o`, `5o` — keep as-is. if re.fullmatch(r"\d+(?:\.\d+)?[a-z]", low) and low[-1] not in _SIZE_SUFFIXES: return low # O-series: o1, o3, o4 if re.fullmatch(r"o\d+", low): return low # Default: capitalize first letter, preserve rest. return tok[0].upper() + tok[1:] if tok[0].isalpha() else tok
def _is_version_token(tok: str) -> bool: """True if `tok` looks like a version (e.g. `5`, `4.5`, `4o`) and not a parameter size (`7b`, `70m`).""" m = re.fullmatch(r"(\d+(?:\.\d+)?)([a-z]?)", tok.lower()) if not m: return False return m.group(2) not in _SIZE_SUFFIXES198 unmodified lines199200201202203204205206207198 unmodified linesreturn self._con# Import lazily so processes that never call lookup() don't pay# the duckdb import cost.import duckdbcon = duckdb.connect()con.execute("INSTALL httpfs; LOAD httpfs;")self._con = conreturn con198 unmodified lines199200201202203204205206207208209210211212213214215216217218219220198 unmodified linesreturn self._con# Import lazily so processes that never call lookup() don't pay# the duckdb import cost.import osimport duckdbcon = duckdb.connect()con.execute("INSTALL httpfs; LOAD httpfs;")# Authenticate parquet fetches when HF_TOKEN is in the environment# (typical on the deployed Space). Unauth limit is 500 req/5min;# one DuckDB read_parquet against the remote file streams via# several range requests and a sync that auto-creates many drafts# can brush that ceiling. With auth the ceiling is ~30k/5min.hf_token = os.environ.get("HF_TOKEN")if hf_token:escaped = hf_token.replace("'", "''")con.execute(f"CREATE SECRET hf_auth (TYPE HTTP, BEARER_TOKEN '{escaped}', "f"SCOPE 'https://huggingface.co');")self._con = conreturn con
14 unmodified lines151617181920273 unmodified lines29429529629729829930030130214 unmodified linesfrom typing import Optionalfrom eval_entity_resolver import AliasStore, CanonicalStore, Resolver, ResolverConfig, ResolutionResultfrom eval_card_registry.config import settingsfrom eval_card_registry.store.hf_store import RegistryStore273 unmodified linescandidate_id = f"{candidate_id}-{str(uuid.uuid4())[:8]}"now = _now()base = {"id": candidate_id,"display_name": raw_value,"metadata": "{}","review_status": "draft","created_at": now,14 unmodified lines15161718192021273 unmodified lines29529629729829930030130230330430530630730830931031114 unmodified linesfrom typing import Optionalfrom eval_entity_resolver import AliasStore, CanonicalStore, Resolver, ResolverConfig, ResolutionResultfrom eval_entity_resolver.display import humanize_model_slugfrom eval_card_registry.config import settingsfrom eval_card_registry.store.hf_store import RegistryStore273 unmodified linescandidate_id = f"{candidate_id}-{str(uuid.uuid4())[:8]}"now = _now()# Models get a humanized display name (`gpt-5-2025-08-07` -># `GPT-5 (2025-08-07)`); other entity types pass `raw_value`# through — benchmark/metric/harness/org names are usually# already in their preferred display form.if entity_type == "model":display = humanize_model_slug(raw_value) or raw_valueelse:display = raw_valuebase = {"id": candidate_id,"display_name": display,"metadata": "{}","review_status": "draft","created_at": now,
84 unmodified lines85868788899091929323 unmodified lines1171181191201211221231243 unmodified lines1281291301311321331341 unmodified line13613713813914014124 unmodified lines16616716816917017117217317417517684 unmodified lines`root_model_id`, `lineage_origin_org_id`, and inherited `open_weights`columns.- `root_model_id`: walk parents up through *only* `quantized` edges(identity-preserving chain). NULL when self has no quantizedancestor — i.e., self IS the identity root.- `lineage_origin_org_id`: walk through any non-`variant` edge(quantized / finetune / merge / adapter) to the deepest ancestor,then read its `org_id`. For Meta-originated models = self.org_id;23 unmodified linesow = row.get("open_weights")open_by_id[cid] = None if _is_na(ow) else bool(ow)def _walk(start: str, allowed: set[str]) -> str:"""Walk parents through edges whose relationship is in `allowed`.Returns the deepest reachable id; stops on no-match or cycle."""visited = {start}current = start3 unmodified linesfor p in edges:if not isinstance(p, dict):continueif p.get("relationship") in allowed and p.get("id"):next_id = p["id"]breakif not next_id or next_id in visited or next_id not in parents_by_id:1 unmodified linevisited.add(next_id)current = next_iddef _inherit_open_from_ancestors(start: str) -> Optional[bool]:"""Walk ONLY ancestors (skip self) through `variant` + `quantized`edges and return the first explicit `open_weights` value found.24 unmodified linesopen_updates: dict[str, Optional[bool]] = {}inherited_count = 0for cid in parents_by_id:# Identity root via quantized-only walkroot = _walk(cid, {"quantized"})root_updates[cid] = root if root != cid else None# Lineage origin via any non-variant edge; org of deepest ancestorancestor = _walk(cid, {"quantized", "finetune", "merge", "adapter"})lineage_updates[cid] = org_by_id.get(ancestor) or org_by_id.get(cid)# Open weights — explicit self value WINS; only fall back to# ancestor inheritance when self has no value set. Never overwrite84 unmodified lines85868788899091929394959623 unmodified lines1201211221231241251261273 unmodified lines1311321331341351361371 unmodified line13914014114214314414514614714814915015115215315415524 unmodified lines18018118218318418518618718818919019184 unmodified lines`root_model_id`, `lineage_origin_org_id`, and inherited `open_weights`columns.- `root_model_id`: walk parents up through edges that preserve APIidentity — `quantized` (different precision, same model) and`variant axis=version` (dated snapshot of the same release, e.g.`gpt-4o-2024-05-13` -> `gpt-4o`). NULL when self has no suchancestor — i.e., self IS the identity root. Other variant axes(size, mode, modality, domain) keep separate identity at the leaf.- `lineage_origin_org_id`: walk through any non-`variant` edge(quantized / finetune / merge / adapter) to the deepest ancestor,then read its `org_id`. For Meta-originated models = self.org_id;23 unmodified linesow = row.get("open_weights")open_by_id[cid] = None if _is_na(ow) else bool(ow)def _walk(start: str, edge_ok) -> str:"""Walk parents through edges where `edge_ok(edge)` is True.Returns the deepest reachable id; stops on no-match or cycle."""visited = {start}current = start3 unmodified linesfor p in edges:if not isinstance(p, dict):continueif edge_ok(p) and p.get("id"):next_id = p["id"]breakif not next_id or next_id in visited or next_id not in parents_by_id:1 unmodified linevisited.add(next_id)current = next_iddef _is_identity_edge(p: dict) -> bool:rel = p.get("relationship")if rel == "quantized":return Trueif rel == "variant" and p.get("axis") == "version":return Truereturn Falsedef _is_lineage_edge(p: dict) -> bool:return p.get("relationship") in {"quantized", "finetune", "merge", "adapter"}def _inherit_open_from_ancestors(start: str) -> Optional[bool]:"""Walk ONLY ancestors (skip self) through `variant` + `quantized`edges and return the first explicit `open_weights` value found.24 unmodified linesopen_updates: dict[str, Optional[bool]] = {}inherited_count = 0for cid in parents_by_id:# Identity root via quantized + variant-version walk (both treat# the parent as the same model at the API level — see docstring).root = _walk(cid, _is_identity_edge)root_updates[cid] = root if root != cid else None# Lineage origin via any non-variant edge; org of deepest ancestorancestor = _walk(cid, _is_lineage_edge)lineage_updates[cid] = org_by_id.get(ancestor) or org_by_id.get(cid)# Open weights — explicit self value WINS; only fall back to# ancestor inheritance when self has no value set. Never overwrite
packages/eval-entity-resolver/src/eval_entity_resolver/__init__.py+2
packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/__init__.cpython-311.pyc
packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/__init__.cpython-314.pyc
packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/display.cpython-311.pycAdded
packages/eval-entity-resolver/src/eval_entity_resolver/__pycache__/display.cpython-314.pycAdded
packages/eval-entity-resolver/src/eval_entity_resolver/display.pyAdded+183
src/eval_card_registry/__pycache__/cli.cpython-314.pyc
src/eval_card_registry/services/__pycache__/hub_stats.cpython-314.pyc
src/eval_card_registry/services/__pycache__/resolution_service.cpython-314.pyc
src/eval_card_registry/services/hub_stats.py+13
src/eval_card_registry/services/resolution_service.py+10-1
src/eval_card_registry/store/__pycache__/queries.cpython-314.pyc
src/eval_card_registry/store/queries.py+24-9