saladday1's picture
code: sync from git
2eaa456 verified
Raw History Blame
4.37 kB
"""Daily job: snapshot -> probe new/changed repos -> classify -> dashboard data -> push.
Then the org-wide pass for the landing page: every public MiniMaxAI release, the community
models declared on it, and one data file per category page.
python scripts/daily.py [--family h3 ...] [--push] [--skip-snapshot] [--skip-org]
Runs the same way locally and on HF Jobs. With --push it first mirrors the dataset repo,
stores each family's raw snapshot before anything else (the one step that cannot be
redone later), then pushes labels, the probe cache and the dashboard data.
HF_TOKEN must be able to write the dataset repo and the Space repo.
"""
import argparse
import json
import sys
import time
from pathlib import Path
import pandas as pd
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
from hfeco import authors, classify, discover, families, metrics, org, pipeline, store # noqa: E402
from hfeco.hub import api # noqa: E402
SPACE_REPO = "MiniMaxAI/ecosystem"
ap = argparse.ArgumentParser()
ap.add_argument("--family", nargs="*", default=list(families.FAMILIES))
ap.add_argument("--push", action="store_true")
ap.add_argument("--skip-snapshot", action="store_true")
ap.add_argument("--skip-org", action="store_true")
args = ap.parse_args()
t0 = time.time()
def log(m):
print(f"[{time.time() - t0:6.0f}s] {m}", flush=True)
if args.push:
log("pull dataset")
store.pull()
for key in args.family:
fam = families.get(key)
log(f"== {fam.title}")
if not args.skip_snapshot:
raw_path = store.write_raw(discover.discover(fam, log=log), fam.key)
if args.push:
store.push([raw_path], f"{fam.key}: snapshot {raw_path.stem}")
raw = store.read_raw(fam.key)
today = raw[raw.day == raw.day.max()]
cache, cache_path = pipeline.enrich_all(today, fam, log=log)
labels = classify.classify_all(today, cache, fam)
lab_path = store.LOCAL / "labels" / fam.key / "latest.parquet"
lab_path.parent.mkdir(parents=True, exist_ok=True)
ldf = pd.DataFrame(labels)
for c in ("evidence", "flags"):
ldf[c] = ldf[c].apply(lambda v: json.dumps(v, ensure_ascii=False))
ldf.to_parquet(lab_path, index=False)
fam_ids = [x["repo_id"] for x in labels if x.get("family") and x["kind"] == "model"]
who, who_path = authors.update({i.split("/")[0] for i in fam_ids} | {b.split("/")[0] for b in fam.bases}, log=log)
data = metrics.build(raw, labels, metrics.hf_tree_counts(today, fam), fam, who)
data_path = store.LOCAL / "dashboard" / f"{fam.key}.json"
metrics.dump(data, data_path)
log(f"{fam.key}: {len(labels)} labels, {len(data['repos'])} repos on the dashboard")
if args.push:
store.push([lab_path, cache_path, who_path], f"{fam.key}: labels {data['today']}")
if args.skip_org:
sys.exit(0)
# ---- org-wide pass: the landing page and one data file per category -------------------------
log("== MiniMaxAI")
pub = org.public_models()
rels = org.group(pub, log=log)
deep = {}
for key in {r["deep"][0] for r in rels.values() if r["deep"]}:
deep[key] = json.loads((store.LOCAL / "dashboard" / f"{key}.json").read_text())
in_families = {x["id"] for d in deep.values() for x in d["repos"]}
roots = {m.id: k for k, r in rels.items() if not r["deep"] for m in r["models"]}
found = org.crawl(roots, skip=in_families, log=log)
snap_path = org.snapshot(rels, found)
if args.push:
store.push([snap_path], f"org: snapshot {snap_path.stem}")
who, who_path = authors.update({i.split("/")[0] for i in found} | {org.ORG}, log=log)
site, pages = org.build(rels, found, deep, who)
public_ids = {m.id for m in pub}
out = [("site", site)] + list(pages.items())
paths = []
for name, obj in out:
org.check_public(obj, public_ids)
paths.append(store.LOCAL / "dashboard" / f"{name}.json")
metrics.dump(obj, paths[-1])
log(f"org: {len(rels)} releases, {sum(r['n'] for r in site['releases'])} community models, "
f"pages: {', '.join(pages)}")
if args.push:
from huggingface_hub import CommitOperationAdd
store.push([who_path], f"org: authors {site['today']}")
api.create_commit(SPACE_REPO, [CommitOperationAdd(path_in_repo=f"data/{p.name}", path_or_fileobj=str(p))
for p in paths],
commit_message=f"data {site['today']}", repo_type="space")
log("pushed")