Datasets:
Download scripts/verify_coverage.py from leo20240112/MBMamba-Eval: direct link, hf CLI and curl.
- Browser
- Download file 6.06 kB
-
https://huggingface.co/datasets/leo20240112/MBMamba-Eval/resolve/main/scripts/verify_coverage.py
- Command line
-
hf download hf://datasets/leo20240112/MBMamba-Eval/scripts/verify_coverage.py
-
curl -L -o verify_coverage.py https://huggingface.co/datasets/leo20240112/MBMamba-Eval/resolve/main/scripts/verify_coverage.py
6.06 kB
| #!/usr/bin/env python3 | |
| """Coverage matrix report for a downloaded MBMamba-Eval asset tree. | |
| Prints one status per benchmark x length x task cell: | |
| PUBLIC_READY all published files for the cell are present+verified | |
| OFFICIAL_DOWNLOAD_READY only protocol metadata is published; corpus must be | |
| fetched from the pinned official source | |
| REGENERATION_REQUIRED source available but the tokenizer-specific prepared | |
| view still has to be materialised locally | |
| MISSING nothing usable was found | |
| FAILED files exist but failed verification | |
| Usage | |
| ----- | |
| python verify_coverage.py --root /shared/mbmamba/eval_assets | |
| python verify_coverage.py --root ... --lengths 16384,32768 --tasks all | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| def load(root: Path, rel: str) -> dict | None: | |
| p = root / rel | |
| if not p.exists(): | |
| return None | |
| return json.loads(p.read_text(encoding="utf-8")) | |
| def file_ok(root: Path, rel: str, meta: dict) -> bool: | |
| p = root / rel | |
| return p.exists() and p.stat().st_size == int(meta.get("size", -1)) | |
| def main() -> int: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--root", required=True) | |
| ap.add_argument("--lengths", default="8192,16384,32768") | |
| ap.add_argument("--tasks", default="all") | |
| ap.add_argument("--json", action="store_true") | |
| args = ap.parse_args() | |
| root = Path(args.root).expanduser().resolve() | |
| lengths = [int(x) for x in args.lengths.split(",") if x.strip()] | |
| wanted = [] if args.tasks == "all" else [x.strip() for x in args.tasks.split(",") if x.strip()] | |
| ruler = load(root, "ruler/manifest.json") | |
| helmet = load(root, "helmet/manifest.json") | |
| cells: list[dict] = [] | |
| if ruler: | |
| for length in lengths: | |
| if length not in ruler.get("lengths", []): | |
| continue | |
| for task in ruler.get("tasks", []): | |
| if wanted and task not in wanted: | |
| continue | |
| files = {rel: m for rel, m in ruler["files"].items() | |
| if m.get("role") in ("source", "prepared") | |
| and m.get("length") == length and m.get("task") == task} | |
| present = [rel for rel, m in files.items() if file_ok(root, rel, m)] | |
| if not files: | |
| status = "MISSING" | |
| elif len(present) == len(files): | |
| status = "PUBLIC_READY" | |
| elif any(m.get("role") == "source" for rel, m in files.items() if rel in present): | |
| status = "REGENERATION_REQUIRED" | |
| else: | |
| status = "MISSING" | |
| cells.append({"benchmark": "RULER", "length": length, "task": task, | |
| "category": files[next(iter(files))]["category"] if files else None, | |
| "status": status, | |
| "files": len(present), "expected": len(files)}) | |
| if helmet: | |
| configs = {rel: m for rel, m in helmet.get("files", {}).items() | |
| if m.get("role") == "config"} | |
| present_cfg = [rel for rel, m in configs.items() if file_ok(root, rel, m)] | |
| for key, b in helmet.get("bindings", {}).items(): | |
| length = int(b["length"]) | |
| if length not in lengths: | |
| continue | |
| if wanted and b["dataset"] not in wanted: | |
| continue | |
| declared = b.get("status", "OFFICIAL_DOWNLOAD_READY") | |
| ds_files = {rel: m for rel, m in helmet.get("files", {}).items() | |
| if m.get("role") in ("source", "prepared") | |
| and m.get("task") == b["dataset"] | |
| and m.get("length") in (None, length)} | |
| if ds_files: | |
| present = [rel for rel, m in ds_files.items() if file_ok(root, rel, m)] | |
| if len(present) == len(ds_files): | |
| # Source rows are published here, but the tokenizer-specific | |
| # eval-ready view still has to be materialised locally. | |
| status = "PUBLIC_READY" if declared == "PUBLIC_READY" \ | |
| else "REGENERATION_REQUIRED" | |
| elif present: | |
| status = "FAILED" | |
| else: | |
| status = "MISSING" | |
| n_files, n_expected = len(present), len(ds_files) | |
| else: | |
| # Corpus text is not published for this dataset; only the | |
| # pinned recipe + configs can be asserted locally. | |
| status = "OFFICIAL_DOWNLOAD_READY" if present_cfg else "MISSING" | |
| n_files, n_expected = len(present_cfg), len(configs) | |
| cells.append({"benchmark": "HELMET", "length": length, | |
| "task": b["dataset"], "category": b["category"], | |
| "status": status, "files": n_files, | |
| "expected": n_expected, | |
| "declared_status": declared}) | |
| summary: dict[str, int] = {} | |
| for c in cells: | |
| summary[c["status"]] = summary.get(c["status"], 0) + 1 | |
| if args.json: | |
| print(json.dumps({"root": str(root), "cells": cells, "summary": summary}, indent=2)) | |
| else: | |
| print(f"root: {root}") | |
| print(f"{'benchmark':10s} {'len':>6s} {'category':22s} {'task':34s} status") | |
| print("-" * 100) | |
| for c in cells: | |
| print(f"{c['benchmark']:10s} {c['length']:>6d} {str(c['category']):22s} " | |
| f"{c['task']:34s} {c['status']}") | |
| print("-" * 100) | |
| for k in sorted(summary): | |
| print(f" {k:26s} {summary[k]}") | |
| total = len(cells) | |
| ready = summary.get("PUBLIC_READY", 0) | |
| print(f"\n PUBLIC_READY coverage: {ready}/{total} cells") | |
| return 0 if summary.get("MISSING", 0) == 0 and summary.get("FAILED", 0) == 0 else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |