Spaces:
Running
Running
Deploy eval-entity-registry service
Browse files- packages/eval-entity-resolver/src/eval_entity_resolver/canonical_store.py +110 -2
- packages/eval-entity-resolver/src/eval_entity_resolver/models.py +6 -0
- packages/eval-entity-resolver/src/eval_entity_resolver/resolver.py +103 -14
- packages/eval-entity-resolver/src/eval_entity_resolver/strategies/fuzzy.py +144 -63
- src/eval_entity_registry/services/resolution_service.py +2 -0
- src/eval_entity_registry/store/schemas.py +2 -1
packages/eval-entity-resolver/src/eval_entity_resolver/canonical_store.py
CHANGED
|
@@ -21,6 +21,7 @@ _TABLES = {
|
|
| 21 |
"org": "canonical_orgs",
|
| 22 |
"family": "canonical_families",
|
| 23 |
"composite": "canonical_composites",
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
# Scalar parent column for non-model types; models carry a typed `parents`
|
|
@@ -46,6 +47,11 @@ def _na_to_none(value: Any) -> Any:
|
|
| 46 |
return None if _is_na(value) else value
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def _safe_json_load(s: str, default: Any = None) -> Any:
|
| 50 |
"""`json.loads` that returns `default` on any decode/type error."""
|
| 51 |
try:
|
|
@@ -115,6 +121,51 @@ def variant_parent_id(parents: list[dict]) -> Optional[str]:
|
|
| 115 |
return None
|
| 116 |
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
def _kwarg_for(entity_type: str) -> str:
|
| 119 |
"""Constructor kwarg for an entity_type (English plurals, so no `<type>s_df`
|
| 120 |
rule: `harnesses_df`, `families_df`)."""
|
|
@@ -126,6 +177,7 @@ def _kwarg_for(entity_type: str) -> str:
|
|
| 126 |
"org": "orgs_df",
|
| 127 |
"family": "families_df",
|
| 128 |
"composite": "composites_df",
|
|
|
|
| 129 |
}[entity_type]
|
| 130 |
|
| 131 |
|
|
@@ -146,6 +198,7 @@ class CanonicalStore:
|
|
| 146 |
orgs_df: Optional[pd.DataFrame] = None,
|
| 147 |
families_df: Optional[pd.DataFrame] = None,
|
| 148 |
composites_df: Optional[pd.DataFrame] = None,
|
|
|
|
| 149 |
) -> None:
|
| 150 |
self._tables: dict[str, pd.DataFrame] = {
|
| 151 |
"model": models_df if models_df is not None else pd.DataFrame(),
|
|
@@ -155,7 +208,11 @@ class CanonicalStore:
|
|
| 155 |
"org": orgs_df if orgs_df is not None else pd.DataFrame(),
|
| 156 |
"family": families_df if families_df is not None else pd.DataFrame(),
|
| 157 |
"composite": composites_df if composites_df is not None else pd.DataFrame(),
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
|
|
|
| 159 |
self._index: dict[str, dict[str, dict]] = {}
|
| 160 |
# benchmark_id → family_id, built lazily from canonical_families.
|
| 161 |
self._benchmark_to_family: Optional[dict[str, str]] = None
|
|
@@ -250,6 +307,43 @@ class CanonicalStore:
|
|
| 250 |
return None
|
| 251 |
return self._ensure_index(entity_type).get(canonical_id)
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
def eval_name_layout(self, source_config: str) -> Optional[int]:
|
| 254 |
"""The declared dotted-`evaluation_name` layout of `source_config`,
|
| 255 |
read from `metadata.eval_name_layout` of the composite that lists it:
|
|
@@ -504,6 +598,22 @@ class CanonicalStore:
|
|
| 504 |
return None
|
| 505 |
return _na_to_none(entity.get(field))
|
| 506 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
def model_metadata_fields(
|
| 508 |
self, matched_canonical_id: str, matched_entity: Optional[dict]
|
| 509 |
) -> dict:
|
|
@@ -526,7 +636,6 @@ class CanonicalStore:
|
|
| 526 |
"model_family_id": None,
|
| 527 |
"lineage_origin_model_id": None,
|
| 528 |
"lineage_origin_model_org_id": None,
|
| 529 |
-
"inference_platform": None,
|
| 530 |
"resolution_source": None,
|
| 531 |
"resolution_granularity": None,
|
| 532 |
"parents": None,
|
|
@@ -552,7 +661,6 @@ class CanonicalStore:
|
|
| 552 |
"model_family_id": leaf_family,
|
| 553 |
"lineage_origin_model_id": leaf_lineage_model,
|
| 554 |
"lineage_origin_model_org_id": leaf_lineage_org,
|
| 555 |
-
"inference_platform": None,
|
| 556 |
"resolution_source": _na_to_none(matched_entity.get("resolution_source")),
|
| 557 |
"resolution_granularity": _na_to_none(matched_entity.get("resolution_granularity")),
|
| 558 |
"parents": parents_decoded,
|
|
|
|
| 21 |
"org": "canonical_orgs",
|
| 22 |
"family": "canonical_families",
|
| 23 |
"composite": "canonical_composites",
|
| 24 |
+
"inference_platform": "canonical_inference_platforms",
|
| 25 |
}
|
| 26 |
|
| 27 |
# Scalar parent column for non-model types; models carry a typed `parents`
|
|
|
|
| 47 |
return None if _is_na(value) else value
|
| 48 |
|
| 49 |
|
| 50 |
+
def _is_list_like(value: Any) -> bool:
|
| 51 |
+
"""A list or a pyarrow/numpy array of values, not a scalar or a string."""
|
| 52 |
+
return hasattr(value, "__iter__") and not isinstance(value, (str, bytes, dict))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
def _safe_json_load(s: str, default: Any = None) -> Any:
|
| 56 |
"""`json.loads` that returns `default` on any decode/type error."""
|
| 57 |
try:
|
|
|
|
| 121 |
return None
|
| 122 |
|
| 123 |
|
| 124 |
+
# Hub pipeline tags of a model whose output is generated text.
|
| 125 |
+
_TEXT_GENERATING_PIPELINES = frozenset({
|
| 126 |
+
"text-generation", "text2text-generation", "image-text-to-text",
|
| 127 |
+
"video-text-to-text", "audio-text-to-text", "image-to-text", "any-to-any",
|
| 128 |
+
})
|
| 129 |
+
# Hub pipeline tags of a model whose output is an image, a video, audio or a
|
| 130 |
+
# 3D asset. Every other tag says nothing either way: a chat model can carry
|
| 131 |
+
# `feature-extraction`, `translation` or `question-answering` on the Hub, and
|
| 132 |
+
# `audio-to-audio` covers speech-to-speech language models.
|
| 133 |
+
_NON_TEXT_PIPELINES = frozenset({
|
| 134 |
+
"text-to-image", "image-to-image", "image-text-to-image",
|
| 135 |
+
"unconditional-image-generation",
|
| 136 |
+
"text-to-video", "image-to-video", "image-text-to-video", "video-to-video",
|
| 137 |
+
"text-to-speech", "text-to-audio",
|
| 138 |
+
"text-to-3d", "image-to-3d",
|
| 139 |
+
})
|
| 140 |
+
# Curated tags of a model whose output is an image.
|
| 141 |
+
_NON_TEXT_TAGS = frozenset({"image-gen", "diffusion"})
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def _json_field(entity: dict, key: str) -> Any:
|
| 145 |
+
"""A JSON-encoded column decoded, or None; a pre-decoded value as is."""
|
| 146 |
+
value = entity.get(key)
|
| 147 |
+
return _safe_json_load(value) if isinstance(value, str) else value
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def _row_generates_text(entity: dict) -> Optional[bool]:
|
| 151 |
+
"""Whether one canonical model row says its model generates text, or
|
| 152 |
+
None when the row does not say. Most specific statement first: the
|
| 153 |
+
output modalities, then the Hub pipeline tag, then the curated tags."""
|
| 154 |
+
modalities = _json_field(entity, "output_modalities")
|
| 155 |
+
if _is_list_like(modalities) and len(modalities):
|
| 156 |
+
return "text" in list(modalities)
|
| 157 |
+
metadata = _json_field(entity, "metadata")
|
| 158 |
+
pipeline_tag = metadata.get("pipeline_tag") if isinstance(metadata, dict) else None
|
| 159 |
+
if pipeline_tag in _TEXT_GENERATING_PIPELINES:
|
| 160 |
+
return True
|
| 161 |
+
if pipeline_tag in _NON_TEXT_PIPELINES:
|
| 162 |
+
return False
|
| 163 |
+
tags = _json_field(entity, "tags")
|
| 164 |
+
if _is_list_like(tags) and _NON_TEXT_TAGS.intersection(tags):
|
| 165 |
+
return False
|
| 166 |
+
return None
|
| 167 |
+
|
| 168 |
+
|
| 169 |
def _kwarg_for(entity_type: str) -> str:
|
| 170 |
"""Constructor kwarg for an entity_type (English plurals, so no `<type>s_df`
|
| 171 |
rule: `harnesses_df`, `families_df`)."""
|
|
|
|
| 177 |
"org": "orgs_df",
|
| 178 |
"family": "families_df",
|
| 179 |
"composite": "composites_df",
|
| 180 |
+
"inference_platform": "inference_platforms_df",
|
| 181 |
}[entity_type]
|
| 182 |
|
| 183 |
|
|
|
|
| 198 |
orgs_df: Optional[pd.DataFrame] = None,
|
| 199 |
families_df: Optional[pd.DataFrame] = None,
|
| 200 |
composites_df: Optional[pd.DataFrame] = None,
|
| 201 |
+
inference_platforms_df: Optional[pd.DataFrame] = None,
|
| 202 |
) -> None:
|
| 203 |
self._tables: dict[str, pd.DataFrame] = {
|
| 204 |
"model": models_df if models_df is not None else pd.DataFrame(),
|
|
|
|
| 208 |
"org": orgs_df if orgs_df is not None else pd.DataFrame(),
|
| 209 |
"family": families_df if families_df is not None else pd.DataFrame(),
|
| 210 |
"composite": composites_df if composites_df is not None else pd.DataFrame(),
|
| 211 |
+
"inference_platform": (
|
| 212 |
+
inference_platforms_df if inference_platforms_df is not None else pd.DataFrame()
|
| 213 |
+
),
|
| 214 |
}
|
| 215 |
+
self._host_token_platforms: Optional[dict[str, str]] = None
|
| 216 |
self._index: dict[str, dict[str, dict]] = {}
|
| 217 |
# benchmark_id → family_id, built lazily from canonical_families.
|
| 218 |
self._benchmark_to_family: Optional[dict[str, str]] = None
|
|
|
|
| 307 |
return None
|
| 308 |
return self._ensure_index(entity_type).get(canonical_id)
|
| 309 |
|
| 310 |
+
def host_token_platforms(self) -> dict[str, str]:
|
| 311 |
+
"""Lowercased host-token spelling (`together/`, `-bedrock`) →
|
| 312 |
+
`canonical_inference_platforms.id`, inverted from the table's
|
| 313 |
+
`aliases`. Empty when the store carries no platform table."""
|
| 314 |
+
if self._host_token_platforms is None:
|
| 315 |
+
mapping: dict[str, str] = {}
|
| 316 |
+
for platform_id, row in self._ensure_index("inference_platform").items():
|
| 317 |
+
aliases = row.get("aliases")
|
| 318 |
+
if isinstance(aliases, str):
|
| 319 |
+
aliases = _safe_json_load(aliases, default=[])
|
| 320 |
+
if _is_list_like(aliases):
|
| 321 |
+
for alias in aliases:
|
| 322 |
+
if isinstance(alias, str) and alias:
|
| 323 |
+
mapping[alias.lower()] = platform_id
|
| 324 |
+
self._host_token_platforms = mapping
|
| 325 |
+
return self._host_token_platforms
|
| 326 |
+
|
| 327 |
+
def platform_developer_org(self, platform_id: str) -> Optional[str]:
|
| 328 |
+
"""The developer org that operates `platform_id`, from the platform
|
| 329 |
+
row's `canonical_org`, or None for a platform that only serves other
|
| 330 |
+
developers' models. A platform and a developer are separate entities;
|
| 331 |
+
this column is the one declared link between them."""
|
| 332 |
+
row = self._ensure_index("inference_platform").get(platform_id) or {}
|
| 333 |
+
org = _na_to_none(row.get("canonical_org"))
|
| 334 |
+
return org if isinstance(org, str) and org else None
|
| 335 |
+
|
| 336 |
+
def require_host_token_platforms(self, origin: str) -> None:
|
| 337 |
+
"""Refuse a registry snapshot that cannot attribute any host token.
|
| 338 |
+
Without this every `inference_platform` resolves to None and nothing
|
| 339 |
+
downstream can tell that from a model served by no platform."""
|
| 340 |
+
if not self.host_token_platforms():
|
| 341 |
+
raise ValueError(
|
| 342 |
+
f"registry snapshot at {origin} has no host tokens in "
|
| 343 |
+
"canonical_inference_platforms (table missing, empty, or "
|
| 344 |
+
"without aliases); inference_platform cannot be resolved"
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
def eval_name_layout(self, source_config: str) -> Optional[int]:
|
| 348 |
"""The declared dotted-`evaluation_name` layout of `source_config`,
|
| 349 |
read from `metadata.eval_name_layout` of the composite that lists it:
|
|
|
|
| 598 |
return None
|
| 599 |
return _na_to_none(entity.get(field))
|
| 600 |
|
| 601 |
+
def model_generates_text(self, entity: Optional[dict]) -> Optional[bool]:
|
| 602 |
+
"""Whether the registry says this model generates text: True, False,
|
| 603 |
+
or None when it does not say. Read off the model's own row, then off
|
| 604 |
+
its group root, which is the same model in another version,
|
| 605 |
+
precision or mode."""
|
| 606 |
+
if not entity:
|
| 607 |
+
return None
|
| 608 |
+
own = _row_generates_text(entity)
|
| 609 |
+
if own is not None:
|
| 610 |
+
return own
|
| 611 |
+
group_id = _na_to_none(entity.get("model_group_id"))
|
| 612 |
+
if not group_id or group_id == entity.get("id"):
|
| 613 |
+
return None
|
| 614 |
+
root = self.lookup("model", group_id)
|
| 615 |
+
return _row_generates_text(root) if root else None
|
| 616 |
+
|
| 617 |
def model_metadata_fields(
|
| 618 |
self, matched_canonical_id: str, matched_entity: Optional[dict]
|
| 619 |
) -> dict:
|
|
|
|
| 636 |
"model_family_id": None,
|
| 637 |
"lineage_origin_model_id": None,
|
| 638 |
"lineage_origin_model_org_id": None,
|
|
|
|
| 639 |
"resolution_source": None,
|
| 640 |
"resolution_granularity": None,
|
| 641 |
"parents": None,
|
|
|
|
| 661 |
"model_family_id": leaf_family,
|
| 662 |
"lineage_origin_model_id": leaf_lineage_model,
|
| 663 |
"lineage_origin_model_org_id": leaf_lineage_org,
|
|
|
|
| 664 |
"resolution_source": _na_to_none(matched_entity.get("resolution_source")),
|
| 665 |
"resolution_granularity": _na_to_none(matched_entity.get("resolution_granularity")),
|
| 666 |
"parents": parents_decoded,
|
packages/eval-entity-resolver/src/eval_entity_resolver/models.py
CHANGED
|
@@ -64,6 +64,10 @@ class ResolutionResult:
|
|
| 64 |
`lineage_origin_model_org_id`; remove once no consumer reads it.
|
| 65 |
- `lineage_origin_model_org_id`: that ancestor's org_id. Models only.
|
| 66 |
- `inference_platform`: FK to inference_platforms.id. Models only.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
- `resolution_source`: {hf|models_dev|curated|inferred|none}.
|
| 68 |
- `resolution_granularity`: {variant|group|family}.
|
| 69 |
- `parents`: typed-edge list of the matched leaf. Models only.
|
|
@@ -91,6 +95,8 @@ class ResolutionResult:
|
|
| 91 |
lineage_origin_model_id: Optional[str] = None
|
| 92 |
lineage_origin_model_org_id: Optional[str] = None
|
| 93 |
inference_platform: Optional[str] = None
|
|
|
|
|
|
|
| 94 |
resolution_source: Optional[str] = None
|
| 95 |
resolution_granularity: Optional[str] = None
|
| 96 |
parents: Optional[list[dict]] = None
|
|
|
|
| 64 |
`lineage_origin_model_org_id`; remove once no consumer reads it.
|
| 65 |
- `lineage_origin_model_org_id`: that ancestor's org_id. Models only.
|
| 66 |
- `inference_platform`: FK to inference_platforms.id. Models only.
|
| 67 |
+
- `reasoning_effort`, `reasoning_tokens`: the effort tier (`…-low`)
|
| 68 |
+
and thinking-token budget (`…-thinking-16k`) of the run. Read off
|
| 69 |
+
the matched mode leaf's id, else off the raw id when the id without
|
| 70 |
+
them names the same model. Models only.
|
| 71 |
- `resolution_source`: {hf|models_dev|curated|inferred|none}.
|
| 72 |
- `resolution_granularity`: {variant|group|family}.
|
| 73 |
- `parents`: typed-edge list of the matched leaf. Models only.
|
|
|
|
| 95 |
lineage_origin_model_id: Optional[str] = None
|
| 96 |
lineage_origin_model_org_id: Optional[str] = None
|
| 97 |
inference_platform: Optional[str] = None
|
| 98 |
+
reasoning_effort: Optional[str] = None
|
| 99 |
+
reasoning_tokens: Optional[int] = None
|
| 100 |
resolution_source: Optional[str] = None
|
| 101 |
resolution_granularity: Optional[str] = None
|
| 102 |
parents: Optional[list[dict]] = None
|
packages/eval-entity-resolver/src/eval_entity_resolver/resolver.py
CHANGED
|
@@ -11,7 +11,11 @@ from pathlib import Path
|
|
| 11 |
from typing import Callable, Optional
|
| 12 |
|
| 13 |
from eval_entity_resolver.alias_store import AliasStore
|
| 14 |
-
from eval_entity_resolver.canonical_store import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
from eval_entity_resolver.eee import (
|
| 16 |
clean_eval_name,
|
| 17 |
prepare_eval_name_segments,
|
|
@@ -26,7 +30,14 @@ from eval_entity_resolver.models import (
|
|
| 26 |
)
|
| 27 |
from eval_entity_resolver.strategies.exact import exact_match
|
| 28 |
from eval_entity_resolver.strategies.normalized import normalized_match
|
| 29 |
-
from eval_entity_resolver.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Strictly between exact (1.0) and fuzzy (`_STEM_CONFIDENCE`, 0.90) so the
|
| 32 |
# tier is recoverable from the confidence alone.
|
|
@@ -137,11 +148,14 @@ class Resolver:
|
|
| 137 |
config: Optional[ResolverConfig] = None,
|
| 138 |
) -> "Resolver":
|
| 139 |
"""Fully-enriching resolver over `<path>/*.parquet` (alias + canonical
|
| 140 |
-
tables).
|
|
|
|
|
|
|
|
|
|
| 141 |
return cls(
|
| 142 |
AliasStore.from_parquet(path),
|
| 143 |
config=config,
|
| 144 |
-
canonical_store=
|
| 145 |
)
|
| 146 |
|
| 147 |
@classmethod
|
|
@@ -150,11 +164,14 @@ class Resolver:
|
|
| 150 |
repo_id: str,
|
| 151 |
config: Optional[ResolverConfig] = None,
|
| 152 |
) -> "Resolver":
|
| 153 |
-
"""Fully-enriching resolver over a HF Dataset repo.
|
|
|
|
|
|
|
|
|
|
| 154 |
return cls(
|
| 155 |
AliasStore.from_hf(repo_id),
|
| 156 |
config=config,
|
| 157 |
-
canonical_store=
|
| 158 |
)
|
| 159 |
|
| 160 |
def resolve(
|
|
@@ -221,20 +238,15 @@ class Resolver:
|
|
| 221 |
confidence=0.0,
|
| 222 |
)
|
| 223 |
|
| 224 |
-
canonical_id, confidence
|
| 225 |
raw_value, entity_type, self.config.threshold, self.store, source_config,
|
| 226 |
org_dev_map=self._org_fold_map(), known_orgs=self._known_orgs(),
|
| 227 |
)
|
| 228 |
if canonical_id is not None:
|
| 229 |
-
|
| 230 |
raw_value, entity_type, source_config,
|
| 231 |
canonical_id, "fuzzy", confidence,
|
| 232 |
)
|
| 233 |
-
# An explicit host token in the raw id (`together/`, `-bedrock`) is
|
| 234 |
-
# the strongest per-run platform fact; absent one, leave the field.
|
| 235 |
-
if inferred_platform is not None:
|
| 236 |
-
result.inference_platform = inferred_platform
|
| 237 |
-
return result
|
| 238 |
|
| 239 |
return self._no_match_or_harness_retry(
|
| 240 |
raw_value, entity_type, source_config, mode
|
|
@@ -727,6 +739,78 @@ class Resolver:
|
|
| 727 |
knows (bypassing the strategy chain); same enrichment as `resolve()`."""
|
| 728 |
return self._enrich(raw_value, entity_type, source_config, canonical_id, strategy, confidence)
|
| 729 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 730 |
def _enrich(
|
| 731 |
self,
|
| 732 |
raw_value: str,
|
|
@@ -754,6 +838,9 @@ class Resolver:
|
|
| 754 |
|
| 755 |
if entity_type == "model":
|
| 756 |
fields = cs.model_metadata_fields(matched_canonical_id, matched_entity)
|
|
|
|
|
|
|
|
|
|
| 757 |
# review_status must describe the canonical the response names.
|
| 758 |
if fields["canonical_id"] != matched_canonical_id:
|
| 759 |
root_entity = cs.lookup("model", fields["canonical_id"])
|
|
@@ -776,7 +863,9 @@ class Resolver:
|
|
| 776 |
model_family_id=fields.get("model_family_id"),
|
| 777 |
lineage_origin_model_id=fields.get("lineage_origin_model_id"),
|
| 778 |
lineage_origin_model_org_id=fields.get("lineage_origin_model_org_id"),
|
| 779 |
-
inference_platform=
|
|
|
|
|
|
|
| 780 |
resolution_source=fields.get("resolution_source"),
|
| 781 |
resolution_granularity=fields.get("resolution_granularity"),
|
| 782 |
parents=fields["parents"],
|
|
|
|
| 11 |
from typing import Callable, Optional
|
| 12 |
|
| 13 |
from eval_entity_resolver.alias_store import AliasStore
|
| 14 |
+
from eval_entity_resolver.canonical_store import (
|
| 15 |
+
CanonicalStore,
|
| 16 |
+
_hf_repo_id_of,
|
| 17 |
+
decode_parents,
|
| 18 |
+
)
|
| 19 |
from eval_entity_resolver.eee import (
|
| 20 |
clean_eval_name,
|
| 21 |
prepare_eval_name_segments,
|
|
|
|
| 30 |
)
|
| 31 |
from eval_entity_resolver.strategies.exact import exact_match
|
| 32 |
from eval_entity_resolver.strategies.normalized import normalized_match
|
| 33 |
+
from eval_entity_resolver.fold import _norm_org_key
|
| 34 |
+
from eval_entity_resolver.strategies.fuzzy import (
|
| 35 |
+
_canon_org,
|
| 36 |
+
fuzzy_match,
|
| 37 |
+
host_platform_of,
|
| 38 |
+
mode_leaf_run_condition,
|
| 39 |
+
reasoning_run_condition_of,
|
| 40 |
+
)
|
| 41 |
|
| 42 |
# Strictly between exact (1.0) and fuzzy (`_STEM_CONFIDENCE`, 0.90) so the
|
| 43 |
# tier is recoverable from the confidence alone.
|
|
|
|
| 148 |
config: Optional[ResolverConfig] = None,
|
| 149 |
) -> "Resolver":
|
| 150 |
"""Fully-enriching resolver over `<path>/*.parquet` (alias + canonical
|
| 151 |
+
tables). Raises ValueError when the snapshot carries no host-token
|
| 152 |
+
platform map."""
|
| 153 |
+
canonical_store = CanonicalStore.from_parquet(path)
|
| 154 |
+
canonical_store.require_host_token_platforms(str(path))
|
| 155 |
return cls(
|
| 156 |
AliasStore.from_parquet(path),
|
| 157 |
config=config,
|
| 158 |
+
canonical_store=canonical_store,
|
| 159 |
)
|
| 160 |
|
| 161 |
@classmethod
|
|
|
|
| 164 |
repo_id: str,
|
| 165 |
config: Optional[ResolverConfig] = None,
|
| 166 |
) -> "Resolver":
|
| 167 |
+
"""Fully-enriching resolver over a HF Dataset repo. Raises ValueError
|
| 168 |
+
when the snapshot carries no host-token platform map."""
|
| 169 |
+
canonical_store = CanonicalStore.from_hf(repo_id)
|
| 170 |
+
canonical_store.require_host_token_platforms(repo_id)
|
| 171 |
return cls(
|
| 172 |
AliasStore.from_hf(repo_id),
|
| 173 |
config=config,
|
| 174 |
+
canonical_store=canonical_store,
|
| 175 |
)
|
| 176 |
|
| 177 |
def resolve(
|
|
|
|
| 238 |
confidence=0.0,
|
| 239 |
)
|
| 240 |
|
| 241 |
+
canonical_id, confidence = fuzzy_match(
|
| 242 |
raw_value, entity_type, self.config.threshold, self.store, source_config,
|
| 243 |
org_dev_map=self._org_fold_map(), known_orgs=self._known_orgs(),
|
| 244 |
)
|
| 245 |
if canonical_id is not None:
|
| 246 |
+
return self._enrich(
|
| 247 |
raw_value, entity_type, source_config,
|
| 248 |
canonical_id, "fuzzy", confidence,
|
| 249 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
return self._no_match_or_harness_retry(
|
| 252 |
raw_value, entity_type, source_config, mode
|
|
|
|
| 739 |
knows (bypassing the strategy chain); same enrichment as `resolve()`."""
|
| 740 |
return self._enrich(raw_value, entity_type, source_config, canonical_id, strategy, confidence)
|
| 741 |
|
| 742 |
+
def _host_platform(self, raw_value: str, canonical_id: str) -> Optional[str]:
|
| 743 |
+
"""The platform a host token in `raw_value` names, or None.
|
| 744 |
+
|
| 745 |
+
Who served a run and who developed the model are separate facts. The
|
| 746 |
+
developer comes from the matched model, never from the token. A prefix
|
| 747 |
+
token is ambiguous only when the platform it names is operated by that
|
| 748 |
+
same developer (the platform row's `canonical_org`): `together/` on a
|
| 749 |
+
Together-developed model, `Groq/Llama-3-Groq-8B-Tool-Use`,
|
| 750 |
+
`fireworks/ember-1`. That prefix may be a namespace, so no platform is
|
| 751 |
+
claimed."""
|
| 752 |
+
cs = self.canonical_store
|
| 753 |
+
host = host_platform_of(raw_value, cs.host_token_platforms())
|
| 754 |
+
if host is None:
|
| 755 |
+
return None
|
| 756 |
+
operator = cs.platform_developer_org(host.platform_id)
|
| 757 |
+
if host.prefix_token is not None and operator is not None:
|
| 758 |
+
# An alias can point at an id with no canonical row; its namespace
|
| 759 |
+
# is then the only developer on record.
|
| 760 |
+
developer = (cs.lookup("model", canonical_id) or {}).get("org_id") or (
|
| 761 |
+
canonical_id.split("/", 1)[0] if "/" in canonical_id else None
|
| 762 |
+
)
|
| 763 |
+
fold = self._org_fold_map()
|
| 764 |
+
if developer and _norm_org_key(
|
| 765 |
+
_canon_org(operator, fold)
|
| 766 |
+
) == _norm_org_key(_canon_org(developer, fold)):
|
| 767 |
+
return None
|
| 768 |
+
return host.platform_id
|
| 769 |
+
|
| 770 |
+
def _reasoning_run_condition(
|
| 771 |
+
self,
|
| 772 |
+
raw_value: str,
|
| 773 |
+
source_config: Optional[str],
|
| 774 |
+
canonical_id: str,
|
| 775 |
+
matched_entity: Optional[dict],
|
| 776 |
+
) -> tuple[Optional[str], Optional[int]]:
|
| 777 |
+
"""`(effort tier, thinking-token budget)` of the run `raw_value`
|
| 778 |
+
names, each None when absent.
|
| 779 |
+
|
| 780 |
+
How a run was configured and which model ran are separate facts, and
|
| 781 |
+
a trailing `-low` / `-max` can be either. Two rules, in this order:
|
| 782 |
+
|
| 783 |
+
1. The matched entity. A mode leaf (`o3-2025-04-16-high`, a `variant`
|
| 784 |
+
of `o3-2025-04-16` on `axis: mode`) states the condition in its
|
| 785 |
+
own id, so every spelling that reaches the leaf reports it.
|
| 786 |
+
2. The raw id, for what the entity leaves unstated. The suffix is a
|
| 787 |
+
condition when the id without it names the same model: the
|
| 788 |
+
matched one (`claude-sonnet-5-low` and `claude-sonnet-5`) or the
|
| 789 |
+
one it is a variant of. `mistral-medium` and `mistral` are two
|
| 790 |
+
models. It is not read at all on a model the registry knows
|
| 791 |
+
produces no text: nothing reasons there, so the tier word is part
|
| 792 |
+
of the product name (Stable Diffusion 3 Medium)."""
|
| 793 |
+
cs = self.canonical_store
|
| 794 |
+
parents = decode_parents((matched_entity or {}).get("parents"))
|
| 795 |
+
leaf = mode_leaf_run_condition(canonical_id, parents)
|
| 796 |
+
effort, tokens = (leaf.effort, leaf.reasoning_tokens) if leaf else (None, None)
|
| 797 |
+
|
| 798 |
+
stated = reasoning_run_condition_of(raw_value)
|
| 799 |
+
if stated is None or cs.model_generates_text(matched_entity) is False:
|
| 800 |
+
return effort, tokens
|
| 801 |
+
if (effort or not stated.effort) and (tokens or not stated.reasoning_tokens):
|
| 802 |
+
return effort, tokens
|
| 803 |
+
same_model = {canonical_id, cs.parent_canonical_id("model", matched_entity)}
|
| 804 |
+
same_model.discard(None)
|
| 805 |
+
for stem in stated.stems:
|
| 806 |
+
# The stem is synthesized here, not asked about by the caller, so
|
| 807 |
+
# it draws no live HF lookup, and an HF repo that happens to carry
|
| 808 |
+
# its name cannot stand in for what the aliases say it names.
|
| 809 |
+
named = self.resolve(stem, "model", source_config, check_hf=False)
|
| 810 |
+
if named.canonical_id in same_model:
|
| 811 |
+
return effort or stated.effort, tokens or stated.reasoning_tokens
|
| 812 |
+
return effort, tokens
|
| 813 |
+
|
| 814 |
def _enrich(
|
| 815 |
self,
|
| 816 |
raw_value: str,
|
|
|
|
| 838 |
|
| 839 |
if entity_type == "model":
|
| 840 |
fields = cs.model_metadata_fields(matched_canonical_id, matched_entity)
|
| 841 |
+
effort, reasoning_tokens = self._reasoning_run_condition(
|
| 842 |
+
raw_value, source_config, fields["canonical_id"], matched_entity
|
| 843 |
+
)
|
| 844 |
# review_status must describe the canonical the response names.
|
| 845 |
if fields["canonical_id"] != matched_canonical_id:
|
| 846 |
root_entity = cs.lookup("model", fields["canonical_id"])
|
|
|
|
| 863 |
model_family_id=fields.get("model_family_id"),
|
| 864 |
lineage_origin_model_id=fields.get("lineage_origin_model_id"),
|
| 865 |
lineage_origin_model_org_id=fields.get("lineage_origin_model_org_id"),
|
| 866 |
+
inference_platform=self._host_platform(raw_value, fields["canonical_id"]),
|
| 867 |
+
reasoning_effort=effort,
|
| 868 |
+
reasoning_tokens=reasoning_tokens,
|
| 869 |
resolution_source=fields.get("resolution_source"),
|
| 870 |
resolution_granularity=fields.get("resolution_granularity"),
|
| 871 |
parents=fields["parents"],
|
packages/eval-entity-resolver/src/eval_entity_resolver/strategies/fuzzy.py
CHANGED
|
@@ -13,28 +13,40 @@ reported quantization; consumers needing that precision must read the original
|
|
| 13 |
from __future__ import annotations
|
| 14 |
|
| 15 |
import re
|
| 16 |
-
from typing import Optional
|
| 17 |
|
| 18 |
from eval_entity_resolver.normalization import normalize
|
| 19 |
-
from eval_entity_resolver.strategies._platform_map import get_host_token_platform
|
| 20 |
|
| 21 |
|
| 22 |
# Stripped only from the end of the raw value; longer suffixes first so a
|
| 23 |
# shorter one cannot pre-empt a compound (`-int8` vs `-int8-awq`). Host
|
| 24 |
# suffixes (`-together`, `-bedrock`, `-openrouter`) are deliberately absent:
|
| 25 |
-
# they live in `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
_STRIP_SUFFIXES = [
|
| 27 |
# Evaluation-mode suffixes (BFCL).
|
| 28 |
"-fc",
|
| 29 |
"-prompt",
|
| 30 |
-
#
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
"-xhigh-effort",
|
| 34 |
-
"-high-effort",
|
| 35 |
-
"-medium-effort",
|
| 36 |
-
"-low-effort",
|
| 37 |
-
"-minimal-effort",
|
| 38 |
"-non-reasoning",
|
| 39 |
"-xhigh",
|
| 40 |
"-high",
|
|
@@ -113,13 +125,13 @@ def _strip_run_config_tokens(value: str) -> str | None:
|
|
| 113 |
|
| 114 |
def _benchmark_stem_match(
|
| 115 |
raw_value: str, alias_store, source_config: Optional[str]
|
| 116 |
-
) -> tuple[Optional[str], float
|
| 117 |
"""One candidate, built by removing run-configuration tokens. Runs after
|
| 118 |
exact and normalized, so a canonical whose name genuinely carries such a
|
| 119 |
token still wins on its own spelling."""
|
| 120 |
candidate = _strip_run_config_tokens(raw_value)
|
| 121 |
if candidate is None:
|
| 122 |
-
return None, 0.0
|
| 123 |
canonical_id = (
|
| 124 |
alias_store.lookup(candidate, "benchmark", source_config)
|
| 125 |
or alias_store.get_normalized_lookup("benchmark", source_config).get(
|
|
@@ -127,8 +139,8 @@ def _benchmark_stem_match(
|
|
| 127 |
)
|
| 128 |
)
|
| 129 |
if canonical_id is None:
|
| 130 |
-
return None, 0.0
|
| 131 |
-
return canonical_id, _STEM_CONFIDENCE
|
| 132 |
|
| 133 |
from eval_entity_resolver.fold import _ORG_ALIASES, _norm_org_key, dev_org_of_prefix # noqa: E402,F401
|
| 134 |
|
|
@@ -169,9 +181,8 @@ def _orgs_agree(
|
|
| 169 |
|
| 170 |
# Hosting platforms, gateways and missing-developer placeholders: dropped as a
|
| 171 |
# prefix so the bare model body is tried, since they are not developers.
|
| 172 |
-
# Deliberately broader than the
|
| 173 |
-
# matching is independent of platform attribution
|
| 174 |
-
# map; tokens absent there capture `None`.
|
| 175 |
_HOST_PREFIX_TOKENS: tuple[str, ...] = (
|
| 176 |
"unknown",
|
| 177 |
"bedrock", "amazon-bedrock", "aws-bedrock",
|
|
@@ -190,16 +201,10 @@ _HOST_PREFIX_TOKENS: tuple[str, ...] = (
|
|
| 190 |
"kilo", "vercel", "llmgateway", "poe",
|
| 191 |
)
|
| 192 |
|
| 193 |
-
_HOST_PREFIXES_TO_STRIP
|
| 194 |
-
token: (None if token == "unknown" else get_host_token_platform(f"{token}/"))
|
| 195 |
-
for token in _HOST_PREFIX_TOKENS
|
| 196 |
-
}
|
| 197 |
|
| 198 |
-
# Host suffixes:
|
| 199 |
-
|
| 200 |
-
suffix: get_host_token_platform(suffix)
|
| 201 |
-
for suffix in ("-together", "-bedrock", "-openrouter")
|
| 202 |
-
}
|
| 203 |
|
| 204 |
|
| 205 |
def _drop_duplicated_org_prefix(value: str) -> str | None:
|
|
@@ -258,16 +263,15 @@ def _drop_duplicated_org_prefix(value: str) -> str | None:
|
|
| 258 |
|
| 259 |
|
| 260 |
def _drop_host_prefix(value: str) -> tuple[str, Optional[str]] | None:
|
| 261 |
-
"""``(rest,
|
| 262 |
-
``host.``) is a known hosting platform, else None. ``
|
| 263 |
-
|
| 264 |
-
raw casing.
|
| 265 |
"""
|
| 266 |
if "/" in value:
|
| 267 |
org, rest = value.split("/", 1)
|
| 268 |
org_lower = org.lower()
|
| 269 |
if org_lower in _HOST_PREFIXES_TO_STRIP and rest:
|
| 270 |
-
return (rest,
|
| 271 |
if "." in value:
|
| 272 |
# Bedrock-style `bedrock.anthropic.claude-3-5-sonnet`: only the
|
| 273 |
# segment before the first dot can be the host.
|
|
@@ -276,7 +280,7 @@ def _drop_host_prefix(value: str) -> tuple[str, Optional[str]] | None:
|
|
| 276 |
rest = value[first_dot + 1:]
|
| 277 |
org_lower = org.lower()
|
| 278 |
if org_lower in _HOST_PREFIXES_TO_STRIP and rest:
|
| 279 |
-
return (rest,
|
| 280 |
return None
|
| 281 |
|
| 282 |
# Below exact (1.0) and normalized (0.95) so the tier is recoverable from the
|
|
@@ -297,18 +301,106 @@ def _strip_suffix(value: str) -> str | None:
|
|
| 297 |
return None
|
| 298 |
|
| 299 |
|
| 300 |
-
def
|
| 301 |
-
"""``(stem,
|
| 302 |
-
(`-together` / `-bedrock` / `-openrouter`), or None.
|
| 303 |
-
value, never embedded in the candidate."""
|
| 304 |
lower = value.lower()
|
| 305 |
-
for suffix
|
| 306 |
if lower.endswith(suffix):
|
| 307 |
-
|
| 308 |
-
return (stem, platform)
|
| 309 |
return None
|
| 310 |
|
| 311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
# ``qwen-2-72b`` ↔ ``qwen2-72b``. Safe because distinguishing tokens sit on the
|
| 313 |
# other side of a separator (``gpt-4`` vs ``gpt-4-mini`` keeps ``-mini``).
|
| 314 |
_LETTER_DIGIT_DASH = re.compile(r"([a-zA-Z])-(\d)")
|
|
@@ -409,25 +501,18 @@ def fuzzy_match(
|
|
| 409 |
source_config: Optional[str] = None,
|
| 410 |
org_dev_map: Optional[dict] = None,
|
| 411 |
known_orgs: Optional[frozenset] = None,
|
| 412 |
-
) -> tuple[Optional[str], float
|
| 413 |
-
"""Returns ``(canonical_id, confidence
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
``inference_platform`` is a SIDE VALUE captured from a host token and never
|
| 417 |
-
embedded in the matched candidate, so capture cannot alter the canonical_id.
|
| 418 |
-
A suffix capture (`-bedrock`) takes priority over a prefix capture
|
| 419 |
-
(`together/`): a host token in the model name is the stronger per-run signal.
|
| 420 |
-
"""
|
| 421 |
if entity_type == "benchmark":
|
| 422 |
return _benchmark_stem_match(raw_value, alias_store, source_config)
|
| 423 |
|
| 424 |
# The rewrites below are model-specific; on metrics/harnesses they would
|
| 425 |
# merge unrelated entities that merely share a host-like prefix or tail.
|
| 426 |
if entity_type != "model":
|
| 427 |
-
return None, 0.0
|
| 428 |
|
| 429 |
candidates_to_try: list[str] = []
|
| 430 |
-
captured_platform: Optional[str] = None
|
| 431 |
|
| 432 |
# Tried before the generic strip so an aliased thinking-mode canonical
|
| 433 |
# (`model-thinking`) wins over the drop-thinking stem (`model`).
|
|
@@ -435,14 +520,12 @@ def fuzzy_match(
|
|
| 435 |
if preserve_match:
|
| 436 |
candidates_to_try.append(preserve_match.group(1))
|
| 437 |
|
| 438 |
-
# Before the generic strip
|
| 439 |
-
#
|
| 440 |
-
suffix_capture =
|
| 441 |
if suffix_capture:
|
| 442 |
-
stem,
|
| 443 |
candidates_to_try.append(stem)
|
| 444 |
-
if platform is not None:
|
| 445 |
-
captured_platform = platform
|
| 446 |
stem_stripped = _strip_suffix(stem)
|
| 447 |
if stem_stripped:
|
| 448 |
candidates_to_try.append(stem_stripped)
|
|
@@ -457,10 +540,8 @@ def fuzzy_match(
|
|
| 457 |
for val in [raw_value] + candidates_to_try[:]:
|
| 458 |
host = _drop_host_prefix(val)
|
| 459 |
if host:
|
| 460 |
-
bare,
|
| 461 |
candidates_to_try.append(bare)
|
| 462 |
-
if captured_platform is None and platform is not None:
|
| 463 |
-
captured_platform = platform
|
| 464 |
stripped_bare = _strip_suffix(bare)
|
| 465 |
if stripped_bare:
|
| 466 |
candidates_to_try.append(stripped_bare)
|
|
@@ -493,11 +574,11 @@ def fuzzy_match(
|
|
| 493 |
# (`together/meta-llama/Llama-3-8B`) carries the host as its prefix.
|
| 494 |
exact_id = alias_store.lookup(candidate, entity_type, source_config)
|
| 495 |
if exact_id is not None and _orgs_agree(candidate, exact_id, org_dev_map, known_orgs):
|
| 496 |
-
return exact_id, _STEM_CONFIDENCE
|
| 497 |
|
| 498 |
norm = normalize(candidate)
|
| 499 |
canonical_id = norm_lookup.get(norm)
|
| 500 |
if canonical_id is not None and _orgs_agree(candidate, canonical_id, org_dev_map, known_orgs):
|
| 501 |
-
return canonical_id, _STEM_CONFIDENCE
|
| 502 |
|
| 503 |
-
return None, 0.0
|
|
|
|
| 13 |
from __future__ import annotations
|
| 14 |
|
| 15 |
import re
|
| 16 |
+
from typing import Mapping, NamedTuple, Optional, Sequence
|
| 17 |
|
| 18 |
from eval_entity_resolver.normalization import normalize
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
# Stripped only from the end of the raw value; longer suffixes first so a
|
| 22 |
# shorter one cannot pre-empt a compound (`-int8` vs `-int8-awq`). Host
|
| 23 |
# suffixes (`-together`, `-bedrock`, `-openrouter`) are deliberately absent:
|
| 24 |
+
# they live in `_HOST_SUFFIXES`, which `host_platform_of` reads.
|
| 25 |
+
# Reasoning-effort tiers a source welds onto the model name, mapped to the
|
| 26 |
+
# tier they state. `-max` IS an effort tier (arc-agi's low/high/max ladder).
|
| 27 |
+
# Longer spellings first so `-high-effort` is read before `-high`.
|
| 28 |
+
_EFFORT_SUFFIXES: dict[str, str] = {
|
| 29 |
+
"-xhigh-effort": "xhigh",
|
| 30 |
+
"-max-effort": "max",
|
| 31 |
+
"-high-effort": "high",
|
| 32 |
+
"-medium-effort": "medium",
|
| 33 |
+
"-low-effort": "low",
|
| 34 |
+
"-minimal-effort": "minimal",
|
| 35 |
+
"-xhigh": "xhigh",
|
| 36 |
+
"-high": "high",
|
| 37 |
+
"-medium": "medium",
|
| 38 |
+
"-low": "low",
|
| 39 |
+
"-minimal": "minimal",
|
| 40 |
+
"-max": "max",
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
_STRIP_SUFFIXES = [
|
| 44 |
# Evaluation-mode suffixes (BFCL).
|
| 45 |
"-fc",
|
| 46 |
"-prompt",
|
| 47 |
+
# Genuine `-max` products (qwen3-max) are safe because exact/normalized
|
| 48 |
+
# matching wins before fuzzy ever strips.
|
| 49 |
+
*_EFFORT_SUFFIXES,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
"-non-reasoning",
|
| 51 |
"-xhigh",
|
| 52 |
"-high",
|
|
|
|
| 125 |
|
| 126 |
def _benchmark_stem_match(
|
| 127 |
raw_value: str, alias_store, source_config: Optional[str]
|
| 128 |
+
) -> tuple[Optional[str], float]:
|
| 129 |
"""One candidate, built by removing run-configuration tokens. Runs after
|
| 130 |
exact and normalized, so a canonical whose name genuinely carries such a
|
| 131 |
token still wins on its own spelling."""
|
| 132 |
candidate = _strip_run_config_tokens(raw_value)
|
| 133 |
if candidate is None:
|
| 134 |
+
return None, 0.0
|
| 135 |
canonical_id = (
|
| 136 |
alias_store.lookup(candidate, "benchmark", source_config)
|
| 137 |
or alias_store.get_normalized_lookup("benchmark", source_config).get(
|
|
|
|
| 139 |
)
|
| 140 |
)
|
| 141 |
if canonical_id is None:
|
| 142 |
+
return None, 0.0
|
| 143 |
+
return canonical_id, _STEM_CONFIDENCE
|
| 144 |
|
| 145 |
from eval_entity_resolver.fold import _ORG_ALIASES, _norm_org_key, dev_org_of_prefix # noqa: E402,F401
|
| 146 |
|
|
|
|
| 181 |
|
| 182 |
# Hosting platforms, gateways and missing-developer placeholders: dropped as a
|
| 183 |
# prefix so the bare model body is tried, since they are not developers.
|
| 184 |
+
# Deliberately broader than the registry's platform table: stripping for
|
| 185 |
+
# matching is independent of platform attribution (`host_platform_of`).
|
|
|
|
| 186 |
_HOST_PREFIX_TOKENS: tuple[str, ...] = (
|
| 187 |
"unknown",
|
| 188 |
"bedrock", "amazon-bedrock", "aws-bedrock",
|
|
|
|
| 201 |
"kilo", "vercel", "llmgateway", "poe",
|
| 202 |
)
|
| 203 |
|
| 204 |
+
_HOST_PREFIXES_TO_STRIP = frozenset(_HOST_PREFIX_TOKENS)
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
+
# Host suffixes: stripped as a unit so the stem can match.
|
| 207 |
+
_HOST_SUFFIXES: tuple[str, ...] = ("-together", "-bedrock", "-openrouter")
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
|
| 210 |
def _drop_duplicated_org_prefix(value: str) -> str | None:
|
|
|
|
| 263 |
|
| 264 |
|
| 265 |
def _drop_host_prefix(value: str) -> tuple[str, Optional[str]] | None:
|
| 266 |
+
"""``(rest, host_token)`` when the developer prefix (``host/`` or
|
| 267 |
+
``host.``) is a known hosting platform, else None. ``host_token`` is
|
| 268 |
+
lowercased; ``rest`` keeps the raw casing.
|
|
|
|
| 269 |
"""
|
| 270 |
if "/" in value:
|
| 271 |
org, rest = value.split("/", 1)
|
| 272 |
org_lower = org.lower()
|
| 273 |
if org_lower in _HOST_PREFIXES_TO_STRIP and rest:
|
| 274 |
+
return (rest, org_lower)
|
| 275 |
if "." in value:
|
| 276 |
# Bedrock-style `bedrock.anthropic.claude-3-5-sonnet`: only the
|
| 277 |
# segment before the first dot can be the host.
|
|
|
|
| 280 |
rest = value[first_dot + 1:]
|
| 281 |
org_lower = org.lower()
|
| 282 |
if org_lower in _HOST_PREFIXES_TO_STRIP and rest:
|
| 283 |
+
return (rest, org_lower)
|
| 284 |
return None
|
| 285 |
|
| 286 |
# Below exact (1.0) and normalized (0.95) so the tier is recoverable from the
|
|
|
|
| 301 |
return None
|
| 302 |
|
| 303 |
|
| 304 |
+
def _strip_host_suffix(value: str) -> tuple[str, str] | None:
|
| 305 |
+
"""``(stem, host_suffix)`` after stripping a trailing host suffix
|
| 306 |
+
(`-together` / `-bedrock` / `-openrouter`), or None."""
|
|
|
|
| 307 |
lower = value.lower()
|
| 308 |
+
for suffix in _HOST_SUFFIXES:
|
| 309 |
if lower.endswith(suffix):
|
| 310 |
+
return (value[: len(value) - len(suffix)], suffix)
|
|
|
|
| 311 |
return None
|
| 312 |
|
| 313 |
|
| 314 |
+
class HostPlatform(NamedTuple):
|
| 315 |
+
platform_id: str
|
| 316 |
+
# The leading host token (`fireworks`) when the platform was read off a
|
| 317 |
+
# prefix; None for a suffix capture, which can never be a developer.
|
| 318 |
+
prefix_token: Optional[str]
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def host_platform_of(
|
| 322 |
+
raw_value: str, host_token_platforms: Mapping[str, str]
|
| 323 |
+
) -> Optional[HostPlatform]:
|
| 324 |
+
"""The serving platform a raw model id names through a host token
|
| 325 |
+
(`together/…`, `bedrock.…`, `…-bedrock`), or None. A function of the raw
|
| 326 |
+
id alone, so it holds whichever strategy matched the id.
|
| 327 |
+
|
| 328 |
+
``host_token_platforms`` maps a host-token spelling to a platform id
|
| 329 |
+
(``CanonicalStore.host_token_platforms``). A suffix beats a prefix: a host
|
| 330 |
+
token in the model name is the stronger per-run signal.
|
| 331 |
+
"""
|
| 332 |
+
suffix = _strip_host_suffix(raw_value)
|
| 333 |
+
if suffix:
|
| 334 |
+
platform_id = host_token_platforms.get(suffix[1])
|
| 335 |
+
if platform_id is not None:
|
| 336 |
+
return HostPlatform(platform_id, None)
|
| 337 |
+
prefix = _drop_host_prefix(raw_value)
|
| 338 |
+
if prefix:
|
| 339 |
+
platform_id = host_token_platforms.get(f"{prefix[1]}/")
|
| 340 |
+
if platform_id is not None:
|
| 341 |
+
return HostPlatform(platform_id, prefix[1])
|
| 342 |
+
return None
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class RunCondition(NamedTuple):
|
| 346 |
+
# Reasoning-effort tier (`low`, `xhigh`) the id states, or None.
|
| 347 |
+
effort: Optional[str]
|
| 348 |
+
# Thinking-token budget (`-thinking-16k` -> 16000) the id states, or None.
|
| 349 |
+
reasoning_tokens: Optional[int]
|
| 350 |
+
# The raw id without the condition (any host suffix put back): the names
|
| 351 |
+
# of the model the condition was run on, most specific first.
|
| 352 |
+
stems: tuple[str, ...]
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
_THINKING_BUDGET_RE = re.compile(r"^(.*)(-thinking)-(\d+)k$", re.IGNORECASE)
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def reasoning_run_condition_of(raw_value: str) -> Optional[RunCondition]:
|
| 359 |
+
"""The reasoning-effort tier and thinking-token budget a raw model id
|
| 360 |
+
ends in (`…-low`, `…-high-effort`, `…-thinking-16k`,
|
| 361 |
+
`…-thinking-120k-high`, `…-medium-bedrock`), or None. A function of the
|
| 362 |
+
raw id alone. A tier word can also be part of a product name
|
| 363 |
+
(`mistral-medium`), so the caller confirms the condition against the
|
| 364 |
+
model a stem resolves to (`Resolver._reasoning_run_condition`)."""
|
| 365 |
+
host = _strip_host_suffix(raw_value)
|
| 366 |
+
body, host_suffix = (host[0], raw_value[len(host[0]):]) if host else (raw_value, "")
|
| 367 |
+
effort = None
|
| 368 |
+
lower = body.lower()
|
| 369 |
+
for suffix, tier in _EFFORT_SUFFIXES.items():
|
| 370 |
+
if lower.endswith(suffix) and len(body) > len(suffix):
|
| 371 |
+
effort, body = tier, body[: len(body) - len(suffix)]
|
| 372 |
+
break
|
| 373 |
+
budget = _THINKING_BUDGET_RE.match(body)
|
| 374 |
+
if budget is None:
|
| 375 |
+
if effort is None:
|
| 376 |
+
return None
|
| 377 |
+
return RunCondition(effort, None, (body + host_suffix,))
|
| 378 |
+
base, thinking, thousands = budget.groups()
|
| 379 |
+
# A thinking-mode model (`…-thinking`) is the closer match when the
|
| 380 |
+
# registry holds one; the plain model is the fallback.
|
| 381 |
+
return RunCondition(
|
| 382 |
+
effort, int(thousands) * 1000,
|
| 383 |
+
(base + thinking + host_suffix, base + host_suffix),
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
def mode_leaf_run_condition(
|
| 388 |
+
canonical_id: str, parents: Sequence[Mapping]
|
| 389 |
+
) -> Optional[RunCondition]:
|
| 390 |
+
"""The run condition a canonical model states in its own id
|
| 391 |
+
(`openai/o3-mini-high`), when the registry holds it as a mode leaf: a
|
| 392 |
+
`variant` of a base model on `axis: mode`. ``parents`` is the canonical's
|
| 393 |
+
decoded edge list. A tier-named canonical with no such edge is its own
|
| 394 |
+
product (`qwen/qwen3-max`), so it states no condition."""
|
| 395 |
+
is_mode_leaf = any(
|
| 396 |
+
isinstance(edge, Mapping)
|
| 397 |
+
and edge.get("relationship") == "variant"
|
| 398 |
+
and edge.get("axis") == "mode"
|
| 399 |
+
for edge in parents
|
| 400 |
+
)
|
| 401 |
+
return reasoning_run_condition_of(canonical_id) if is_mode_leaf else None
|
| 402 |
+
|
| 403 |
+
|
| 404 |
# ``qwen-2-72b`` ↔ ``qwen2-72b``. Safe because distinguishing tokens sit on the
|
| 405 |
# other side of a separator (``gpt-4`` vs ``gpt-4-mini`` keeps ``-mini``).
|
| 406 |
_LETTER_DIGIT_DASH = re.compile(r"([a-zA-Z])-(\d)")
|
|
|
|
| 501 |
source_config: Optional[str] = None,
|
| 502 |
org_dev_map: Optional[dict] = None,
|
| 503 |
known_orgs: Optional[frozenset] = None,
|
| 504 |
+
) -> tuple[Optional[str], float]:
|
| 505 |
+
"""Returns ``(canonical_id, confidence)``; canonical_id is None on no
|
| 506 |
+
match."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
if entity_type == "benchmark":
|
| 508 |
return _benchmark_stem_match(raw_value, alias_store, source_config)
|
| 509 |
|
| 510 |
# The rewrites below are model-specific; on metrics/harnesses they would
|
| 511 |
# merge unrelated entities that merely share a host-like prefix or tail.
|
| 512 |
if entity_type != "model":
|
| 513 |
+
return None, 0.0
|
| 514 |
|
| 515 |
candidates_to_try: list[str] = []
|
|
|
|
| 516 |
|
| 517 |
# Tried before the generic strip so an aliased thinking-mode canonical
|
| 518 |
# (`model-thinking`) wins over the drop-thinking stem (`model`).
|
|
|
|
| 520 |
if preserve_match:
|
| 521 |
candidates_to_try.append(preserve_match.group(1))
|
| 522 |
|
| 523 |
+
# Before the generic strip; the stem is re-stripped (`model-fc-together`
|
| 524 |
+
# → drop `-together`, then `-fc`).
|
| 525 |
+
suffix_capture = _strip_host_suffix(raw_value)
|
| 526 |
if suffix_capture:
|
| 527 |
+
stem, _ = suffix_capture
|
| 528 |
candidates_to_try.append(stem)
|
|
|
|
|
|
|
| 529 |
stem_stripped = _strip_suffix(stem)
|
| 530 |
if stem_stripped:
|
| 531 |
candidates_to_try.append(stem_stripped)
|
|
|
|
| 540 |
for val in [raw_value] + candidates_to_try[:]:
|
| 541 |
host = _drop_host_prefix(val)
|
| 542 |
if host:
|
| 543 |
+
bare, _ = host
|
| 544 |
candidates_to_try.append(bare)
|
|
|
|
|
|
|
| 545 |
stripped_bare = _strip_suffix(bare)
|
| 546 |
if stripped_bare:
|
| 547 |
candidates_to_try.append(stripped_bare)
|
|
|
|
| 574 |
# (`together/meta-llama/Llama-3-8B`) carries the host as its prefix.
|
| 575 |
exact_id = alias_store.lookup(candidate, entity_type, source_config)
|
| 576 |
if exact_id is not None and _orgs_agree(candidate, exact_id, org_dev_map, known_orgs):
|
| 577 |
+
return exact_id, _STEM_CONFIDENCE
|
| 578 |
|
| 579 |
norm = normalize(candidate)
|
| 580 |
canonical_id = norm_lookup.get(norm)
|
| 581 |
if canonical_id is not None and _orgs_agree(candidate, canonical_id, org_dev_map, known_orgs):
|
| 582 |
+
return canonical_id, _STEM_CONFIDENCE
|
| 583 |
|
| 584 |
+
return None, 0.0
|
src/eval_entity_registry/services/resolution_service.py
CHANGED
|
@@ -90,6 +90,7 @@ def _build_canonical_store(registry_store: RegistryStore) -> CanonicalStore:
|
|
| 90 |
orgs_df=_table_with_pending(registry_store, "canonical_orgs") if registry_store.has_table("canonical_orgs") else None,
|
| 91 |
families_df=registry_store.table("canonical_families") if registry_store.has_table("canonical_families") else None,
|
| 92 |
composites_df=registry_store.table("canonical_composites") if registry_store.has_table("canonical_composites") else None,
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
|
|
@@ -101,6 +102,7 @@ _RESPONSE_FIELDS = (
|
|
| 101 |
# `model_group_id` / `lineage_origin_model_org_id`, kept for older consumers.
|
| 102 |
"model_group_id", "model_family_id", "lineage_origin_model_id",
|
| 103 |
"lineage_origin_model_org_id", "inference_platform",
|
|
|
|
| 104 |
"resolution_source", "resolution_granularity",
|
| 105 |
"parents", "open_weights",
|
| 106 |
"release_date", "params_billions",
|
|
|
|
| 90 |
orgs_df=_table_with_pending(registry_store, "canonical_orgs") if registry_store.has_table("canonical_orgs") else None,
|
| 91 |
families_df=registry_store.table("canonical_families") if registry_store.has_table("canonical_families") else None,
|
| 92 |
composites_df=registry_store.table("canonical_composites") if registry_store.has_table("canonical_composites") else None,
|
| 93 |
+
inference_platforms_df=registry_store.table("canonical_inference_platforms") if registry_store.has_table("canonical_inference_platforms") else None,
|
| 94 |
)
|
| 95 |
|
| 96 |
|
|
|
|
| 102 |
# `model_group_id` / `lineage_origin_model_org_id`, kept for older consumers.
|
| 103 |
"model_group_id", "model_family_id", "lineage_origin_model_id",
|
| 104 |
"lineage_origin_model_org_id", "inference_platform",
|
| 105 |
+
"reasoning_effort", "reasoning_tokens",
|
| 106 |
"resolution_source", "resolution_granularity",
|
| 107 |
"parents", "open_weights",
|
| 108 |
"release_date", "params_billions",
|
src/eval_entity_registry/store/schemas.py
CHANGED
|
@@ -164,7 +164,8 @@ _SCHEMAS: dict[str, dict] = {
|
|
| 164 |
"updated_at": pd.StringDtype(),
|
| 165 |
},
|
| 166 |
# Host-token spellings (`fireworks/`, `-bedrock`, …) live in `aliases`
|
| 167 |
-
# and are inverted into the platform map by
|
|
|
|
| 168 |
"canonical_inference_platforms": {
|
| 169 |
"id": pd.StringDtype(), # PK; = models.dev provider slug where one exists
|
| 170 |
"display_name": pd.StringDtype(),
|
|
|
|
| 164 |
"updated_at": pd.StringDtype(),
|
| 165 |
},
|
| 166 |
# Host-token spellings (`fireworks/`, `-bedrock`, …) live in `aliases`
|
| 167 |
+
# and are inverted into the platform map by the resolver's
|
| 168 |
+
# CanonicalStore.host_token_platforms().
|
| 169 |
"canonical_inference_platforms": {
|
| 170 |
"id": pd.StringDtype(), # PK; = models.dev provider slug where one exists
|
| 171 |
"display_name": pd.StringDtype(),
|