Spaces:
Running
Running
Update update_data.py
Browse files- update_data.py +49 -20
update_data.py
CHANGED
|
@@ -14,8 +14,11 @@ https://huggingface.co/spaces/elevow/benchmarks
|
|
| 14 |
**Single file:** All Aligned race branding, axis relabeling, optional org-groq tagging, and
|
| 15 |
offline ``patch_output_dict`` live here (no separate inject script).
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
Run locally (from repo root or this folder):
|
| 21 |
export HF_TOKEN=hf_...
|
|
@@ -27,6 +30,9 @@ Schedule on HF Jobs (example — point to YOUR raw file):
|
|
| 27 |
hf jobs scheduled uv run "0 8,20 * * *" \\
|
| 28 |
--secrets HF_TOKEN \\
|
| 29 |
https://huggingface.co/spaces/elevow/benchmarks/resolve/main/update_data.py
|
|
|
|
|
|
|
|
|
|
| 30 |
"""
|
| 31 |
|
| 32 |
from __future__ import annotations
|
|
@@ -53,26 +59,23 @@ ALIGNED_LOGO_URL = (
|
|
| 53 |
ALIGNED_LOGOS_KEY = "AlignedAI"
|
| 54 |
ALIGNED_COLOR = "#059669"
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
|
|
|
| 58 |
{
|
| 59 |
-
# Populate from live leaderboard responses, e.g.:
|
| 60 |
-
# "Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 61 |
-
}
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
# HF benchmark-race charts label bars with `short_name`. For models you treat as Groq-hosted
|
| 65 |
-
# Aligned references, rewrite that field to "Aligned AI — {lane} · {checkpoint}" (same lanes as
|
| 66 |
-
# client GMCQ charts). Stock Space UI ignores `race_logo_key` unless you fork index.html; it
|
| 67 |
-
# always uses `short_name` for the bar text.
|
| 68 |
-
MODEL_IDS_ALIGNED_AXIS_LABEL: frozenset[str] = frozenset(
|
| 69 |
-
{
|
| 70 |
-
# Same strings as leaderboards return, e.g.:
|
| 71 |
# "meta-llama/Llama-3.3-70B-Instruct",
|
| 72 |
# "meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
| 73 |
}
|
| 74 |
)
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
# If True, tag every row whose HF org is literally "groq" with race_logo_key (rare on leaderboards).
|
| 77 |
USE_ALIGNED_FOR_ORG_GROQ = False
|
| 78 |
|
|
@@ -154,13 +157,12 @@ def inject_aligned_race_branding(
|
|
| 154 |
for m in bm.get("models") or []:
|
| 155 |
mid = m.get("model_id") or ""
|
| 156 |
provider = mid.split("/")[0] if "/" in mid else mid
|
| 157 |
-
|
| 158 |
-
use_axis = mid in MODEL_IDS_ALIGNED_AXIS_LABEL
|
| 159 |
use_groq_org = USE_ALIGNED_FOR_ORG_GROQ and provider.lower() == "groq"
|
| 160 |
-
if
|
| 161 |
m["race_logo_key"] = ALIGNED_LOGOS_KEY
|
| 162 |
logo_n += 1
|
| 163 |
-
if
|
| 164 |
orig_sn = m.get("short_name") or (mid.split("/")[-1] if "/" in mid else mid)
|
| 165 |
m["chart_full_name"] = f"Published HF model: {orig_sn.replace('-', ' ')}"
|
| 166 |
m["short_name"] = aligned_axis_label_from_model_id(mid)
|
|
@@ -169,6 +171,25 @@ def inject_aligned_race_branding(
|
|
| 169 |
return logo_n, axis_n
|
| 170 |
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
def patch_output_dict(output: dict[str, Any]) -> dict[str, Any]:
|
| 173 |
"""Deep-copy a loaded data.json dict, apply Aligned branding in place, return the copy."""
|
| 174 |
out = json.loads(json.dumps(output))
|
|
@@ -281,6 +302,12 @@ def main() -> None:
|
|
| 281 |
all_model_ids.update(r["model_id"] for r in rows)
|
| 282 |
|
| 283 |
print(f"\n{len(all_model_ids)} unique models across {len(all_scores)} benchmarks")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
print("Fetching model dates...")
|
| 285 |
model_dates = fetch_model_dates(list(all_model_ids), hf_token)
|
| 286 |
print(f" got dates for {len(model_dates)}/{len(all_model_ids)} models")
|
|
@@ -352,6 +379,8 @@ def main() -> None:
|
|
| 352 |
finally:
|
| 353 |
Path(tmp_path).unlink(missing_ok=True)
|
| 354 |
|
|
|
|
|
|
|
| 355 |
|
| 356 |
if __name__ == "__main__":
|
| 357 |
main()
|
|
|
|
| 14 |
**Single file:** All Aligned race branding, axis relabeling, optional org-groq tagging, and
|
| 15 |
offline ``patch_output_dict`` live here (no separate inject script).
|
| 16 |
|
| 17 |
+
1. Add HF ``model_id`` strings to ``MODEL_IDS_ALIGNED_ON_RACE`` (exact strings — use
|
| 18 |
+
``DUMP_MODEL_IDS=1`` once to list them). That rewrites ``short_name`` and sets ``race_logo_key``.
|
| 19 |
+
2. **Upload the forked** ``scripts/elevow-benchmarks/index.html`` **to your Space** (same folder as
|
| 20 |
+
``data.json``). Upstream benchmark-race ignores ``race_logo_key``; without this file you will
|
| 21 |
+
not see the Aligned logo or Aligned bar color.
|
| 22 |
|
| 23 |
Run locally (from repo root or this folder):
|
| 24 |
export HF_TOKEN=hf_...
|
|
|
|
| 30 |
hf jobs scheduled uv run "0 8,20 * * *" \\
|
| 31 |
--secrets HF_TOKEN \\
|
| 32 |
https://huggingface.co/spaces/elevow/benchmarks/resolve/main/update_data.py
|
| 33 |
+
|
| 34 |
+
Upload the forked UI in the same commit as data (one shot):
|
| 35 |
+
UPLOAD_INDEX_HTML=1 uv run scripts/elevow-benchmarks/update_data.py
|
| 36 |
"""
|
| 37 |
|
| 38 |
from __future__ import annotations
|
|
|
|
| 59 |
ALIGNED_LOGOS_KEY = "AlignedAI"
|
| 60 |
ALIGNED_COLOR = "#059669"
|
| 61 |
|
| 62 |
+
# Preferred: one list for both **Aligned bar label** + **race_logo_key** + Aligned bar color.
|
| 63 |
+
# Run with DUMP_MODEL_IDS=1 once to print every model_id the script saw (copy exact strings).
|
| 64 |
+
MODEL_IDS_ALIGNED_ON_RACE: frozenset[str] = frozenset(
|
| 65 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# "meta-llama/Llama-3.3-70B-Instruct",
|
| 67 |
# "meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
| 68 |
}
|
| 69 |
)
|
| 70 |
|
| 71 |
+
# Legacy: unioned with MODEL_IDS_ALIGNED_ON_RACE (you can use any of these three sets).
|
| 72 |
+
MODEL_IDS_USE_ALIGNED_LOGO: frozenset[str] = frozenset()
|
| 73 |
+
MODEL_IDS_ALIGNED_AXIS_LABEL: frozenset[str] = frozenset()
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _all_branded_model_ids() -> frozenset[str]:
|
| 77 |
+
return MODEL_IDS_ALIGNED_ON_RACE | MODEL_IDS_USE_ALIGNED_LOGO | MODEL_IDS_ALIGNED_AXIS_LABEL
|
| 78 |
+
|
| 79 |
# If True, tag every row whose HF org is literally "groq" with race_logo_key (rare on leaderboards).
|
| 80 |
USE_ALIGNED_FOR_ORG_GROQ = False
|
| 81 |
|
|
|
|
| 157 |
for m in bm.get("models") or []:
|
| 158 |
mid = m.get("model_id") or ""
|
| 159 |
provider = mid.split("/")[0] if "/" in mid else mid
|
| 160 |
+
branded = mid in _all_branded_model_ids()
|
|
|
|
| 161 |
use_groq_org = USE_ALIGNED_FOR_ORG_GROQ and provider.lower() == "groq"
|
| 162 |
+
if branded or use_groq_org:
|
| 163 |
m["race_logo_key"] = ALIGNED_LOGOS_KEY
|
| 164 |
logo_n += 1
|
| 165 |
+
if branded:
|
| 166 |
orig_sn = m.get("short_name") or (mid.split("/")[-1] if "/" in mid else mid)
|
| 167 |
m["chart_full_name"] = f"Published HF model: {orig_sn.replace('-', ' ')}"
|
| 168 |
m["short_name"] = aligned_axis_label_from_model_id(mid)
|
|
|
|
| 171 |
return logo_n, axis_n
|
| 172 |
|
| 173 |
|
| 174 |
+
def _upload_index_html_fork(api: HfApi) -> None:
|
| 175 |
+
"""Stock benchmark-race ignores race_logo_key; upload sibling index.html when asked."""
|
| 176 |
+
flag = os.environ.get("UPLOAD_INDEX_HTML", "").lower()
|
| 177 |
+
if flag not in ("1", "true", "yes"):
|
| 178 |
+
return
|
| 179 |
+
index_path = Path(__file__).resolve().parent / "index.html"
|
| 180 |
+
if not index_path.is_file():
|
| 181 |
+
print("UPLOAD_INDEX_HTML set but scripts/elevow-benchmarks/index.html is missing.")
|
| 182 |
+
return
|
| 183 |
+
api.upload_file(
|
| 184 |
+
path_or_fileobj=str(index_path),
|
| 185 |
+
path_in_repo="index.html",
|
| 186 |
+
repo_id=SPACE_REPO,
|
| 187 |
+
repo_type="space",
|
| 188 |
+
commit_message=f"Update index.html Aligned fork ({datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M UTC')})",
|
| 189 |
+
)
|
| 190 |
+
print(f"Uploaded index.html → {SPACE_REPO}")
|
| 191 |
+
|
| 192 |
+
|
| 193 |
def patch_output_dict(output: dict[str, Any]) -> dict[str, Any]:
|
| 194 |
"""Deep-copy a loaded data.json dict, apply Aligned branding in place, return the copy."""
|
| 195 |
out = json.loads(json.dumps(output))
|
|
|
|
| 302 |
all_model_ids.update(r["model_id"] for r in rows)
|
| 303 |
|
| 304 |
print(f"\n{len(all_model_ids)} unique models across {len(all_scores)} benchmarks")
|
| 305 |
+
if os.environ.get("DUMP_MODEL_IDS"):
|
| 306 |
+
print("\n-- DUMP_MODEL_IDS (copy into MODEL_IDS_ALIGNED_ON_RACE) --")
|
| 307 |
+
for mid in sorted(all_model_ids):
|
| 308 |
+
print(mid)
|
| 309 |
+
print("-- end --\n")
|
| 310 |
+
|
| 311 |
print("Fetching model dates...")
|
| 312 |
model_dates = fetch_model_dates(list(all_model_ids), hf_token)
|
| 313 |
print(f" got dates for {len(model_dates)}/{len(all_model_ids)} models")
|
|
|
|
| 379 |
finally:
|
| 380 |
Path(tmp_path).unlink(missing_ok=True)
|
| 381 |
|
| 382 |
+
_upload_index_html_fork(api)
|
| 383 |
+
|
| 384 |
|
| 385 |
if __name__ == "__main__":
|
| 386 |
main()
|