Download code/scripts/build_reference.py from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/cbc9cf220e1bfe14bbd7c11b38fd030c7d39865e/code/scripts/build_reference.py
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@cbc9cf220e1bfe14bbd7c11b38fd030c7d39865e/code/scripts/build_reference.py
-
curl -L -o build_reference.py https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/cbc9cf220e1bfe14bbd7c11b38fd030c7d39865e/code/scripts/build_reference.py
2.14 kB
| """Build hfeco/families/<family>_reference.json: official file hashes and probe values. | |
| Run once per family (and again only if an official repo changes its weights): | |
| python scripts/build_reference.py --family h3 | |
| """ | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) | |
| from hfeco import enrich, families, hub # noqa: E402 | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--family", default="h3") | |
| fam = families.get(ap.parse_args().family) | |
| ref = {"sha256": {}, "probes": []} | |
| for m in fam.members: | |
| for s in hub.info("model", m.base, files_metadata=True).siblings: | |
| if getattr(s, "lfs", None) and s.size and s.size > 1_000_000: | |
| # Members can ship identical files (H3-Image reuses H3's text encoder), so a hash | |
| # maps to every member that contains it. | |
| e = ref["sha256"].setdefault(s.lfs.sha256, {"lineages": [], "file": f"{m.base}/{s.rfilename}", | |
| "size": s.size}) | |
| if m.lineage not in e["lineages"]: | |
| e["lineages"].append(m.lineage) | |
| for lin, repo, folder in fam.probe_sources: | |
| files = [s.rfilename for s in hub.info("model", repo, files_metadata=True).siblings] | |
| idx = [f for f in files if f.startswith(folder + "/") and f.endswith(".safetensors.index.json") | |
| and f.count("/") == folder.count("/") + 1] | |
| wmap = json.loads(enrich._range(repo, idx[0], 0, 20_000_000))["weight_map"] | |
| for pn in fam.probe_names: | |
| if pn in wmap: | |
| fname = f"{folder}/{wmap[pn]}" | |
| n, h = enrich.st_header(repo, fname) | |
| v = enrich.st_values(repo, fname, n, h[pn]) | |
| ref["probes"].append({"lineage": lin, "source": f"{repo}/{folder}", "key": pn, | |
| "dtype": h[pn]["dtype"], "values": [float(x) for x in v]}) | |
| print(lin, folder, pn, h[pn]["dtype"], [round(float(x), 5) for x in v[:4]]) | |
| fam.reference_path().write_text(json.dumps(ref)) | |
| print("sha256 entries:", len(ref["sha256"]), "probes:", len(ref["probes"]), "->", fam.reference_path()) | |