File size: 6,061 Bytes
4c842c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269618a
 
 
4c842c6
 
 
 
 
 
269618a
 
 
 
 
f5bfaa0
269618a
f5bfaa0
 
 
 
 
269618a
 
 
 
 
 
f5bfaa0
 
269618a
 
4c842c6
 
269618a
 
 
4c842c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/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())