File size: 3,771 Bytes
71bdcd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Verify the public MAGAR-Bench files without reading Test gold labels."""

from __future__ import annotations

import argparse
import hashlib
import json
from collections import Counter
from pathlib import Path


EXPECTED_TASKS = {
    "train": {"assembly_decision": 736, "atomic_action": 1764, "minimal_rework": 500},
    "test": {"assembly_decision": 238, "atomic_action": 662, "minimal_rework": 100},
}


def read_jsonl(path: Path) -> list[dict]:
    return [json.loads(line) for line in path.read_text(encoding="utf-8").splitlines() if line.strip()]


def file_hash(path: Path) -> str:
    digest = hashlib.sha256()
    with path.open("rb") as stream:
        for chunk in iter(lambda: stream.read(1024 * 1024), b""):
            digest.update(chunk)
    return digest.hexdigest()


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--release-root", type=Path, default=Path(__file__).resolve().parents[1])
    root = parser.parse_args().release_root.resolve()
    train = read_jsonl(root / "data" / "train.jsonl")
    test = read_jsonl(root / "data" / "test_inputs.jsonl")
    errors: list[str] = []

    if len(train) != 3000 or len(test) != 1000:
        errors.append(f"row counts are train={len(train)}, test={len(test)}")
    for split, rows in (("train", train), ("test", test)):
        counts = Counter(row["metadata"]["task_family"] for row in rows)
        if counts != Counter(EXPECTED_TASKS[split]):
            errors.append(f"{split} task counts are {dict(counts)}")

    train_ids = {row["id"] for row in train}
    test_ids = {row["id"] for row in test}
    if len(train_ids) != len(train) or len(test_ids) != len(test):
        errors.append("duplicate sample ids")
    if train_ids & test_ids:
        errors.append("train/test id overlap")

    train_families = {row["metadata"]["assembly_id"] for row in train}
    test_families = {row["metadata"]["assembly_id"] for row in test}
    if len(train_families) != 20 or len(test_families) != 6:
        errors.append(f"family counts are train={len(train_families)}, test={len(test_families)}")
    if train_families & test_families:
        errors.append("train/test family overlap")

    train_images = {image for row in train for image in row.get("images", [])}
    test_images = {image for row in test for image in row.get("images", [])}
    if train_images & test_images:
        errors.append("train/test image overlap")
    missing = [image for image in train_images | test_images if not (root / image).exists()]
    if missing:
        errors.append(f"missing image references: {len(missing)}")
    if any(any(message.get("role") == "assistant" for message in row["messages"]) for row in test):
        errors.append("test inputs contain assistant answers")
    if any(any(key in row for key in ("target", "gold", "answer")) for row in test):
        errors.append("test inputs contain target/gold/answer fields")

    manifest = root / "MANIFEST.sha256"
    if not manifest.exists():
        errors.append("MANIFEST.sha256 is missing")
    else:
        for line in manifest.read_text(encoding="utf-8").splitlines():
            if not line.strip():
                continue
            expected, relative = line.split("  ", 1)
            target = root / relative
            if not target.exists() or file_hash(target) != expected:
                errors.append(f"manifest mismatch: {relative}")

    result = {
        "train_rows": len(train),
        "test_rows": len(test),
        "train_unique_images": len(train_images),
        "test_unique_images": len(test_images),
        "errors": errors,
    }
    print(json.dumps(result, ensure_ascii=False, indent=2))
    return 1 if errors else 0


if __name__ == "__main__":
    raise SystemExit(main())