| |
| """Audit pinned task datasets without assigning train/evaluation roles.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import csv |
| import hashlib |
| import json |
| import re |
| from pathlib import Path |
|
|
| import pyarrow.parquet as pq |
|
|
|
|
| def sha256(path: Path) -> str: |
| digest = hashlib.sha256() |
| with path.open("rb") as handle: |
| for chunk in iter(lambda: handle.read(1024 * 1024), b""): |
| digest.update(chunk) |
| return digest.hexdigest() |
|
|
|
|
| def write_csv(path: Path, rows: list[dict[str, object]]) -> None: |
| path.parent.mkdir(parents=True, exist_ok=True) |
| with path.open("w", newline="") as handle: |
| writer = csv.DictWriter(handle, fieldnames=list(rows[0])) |
| writer.writeheader() |
| writer.writerows(rows) |
|
|
|
|
| def audit_swe(path: Path, output: Path, revision: str) -> None: |
| table = pq.read_table(path, columns=["language", "repo", "base_commit", "license"]) |
| data = table.to_pydict() |
| languages = sorted(set(data["language"])) |
| rows = [] |
| for language in languages: |
| indices = [i for i, value in enumerate(data["language"]) if value == language] |
| rows.append( |
| { |
| "language": language, |
| "tasks": len(indices), |
| "unique_repositories": len({data["repo"][i] for i in indices}), |
| "unique_base_commits": len({data["base_commit"][i] for i in indices}), |
| "license_values": len({data["license"][i] for i in indices}), |
| "source_revision": revision, |
| "source_sha256": sha256(path), |
| } |
| ) |
| rows.sort(key=lambda row: (-int(row["tasks"]), str(row["language"]))) |
| write_csv(output, rows) |
|
|
|
|
| def audit_mceval_instruct(path: Path, output: Path, revision: str) -> None: |
| records = json.loads(path.read_text()) |
| grouped: dict[str, list[dict[str, str]]] = {} |
| for record in records: |
| grouped.setdefault(record["language"].casefold(), []).append(record) |
| rows = [] |
| for language, group in grouped.items(): |
| rows.append( |
| { |
| "normalized_language": language, |
| "rows": len(group), |
| "unique_instructions": len({record["instruction"] for record in group}), |
| "unique_outputs": len({record["output"] for record in group}), |
| "output_utf8_bytes": sum(len(record["output"].encode()) for record in group), |
| "original_labels": ";".join(sorted({record["language"] for record in group})), |
| "source_revision": revision, |
| "source_sha256": sha256(path), |
| } |
| ) |
| rows.sort(key=lambda row: (-int(row["rows"]), str(row["normalized_language"]))) |
| write_csv(output, rows) |
|
|
|
|
| def audit_mceval_eval(root: Path, output: Path, revision: str) -> None: |
| grouped: dict[tuple[str, str], dict[str, object]] = {} |
| source_files = sorted(root.glob("generation/*.jsonl")) |
| source_files += sorted(root.glob("explanation/*.jsonl")) |
| source_files += sorted(root.glob("completion/*/*.jsonl")) |
| for path in source_files: |
| relative = path.relative_to(root) |
| surface = "/".join(relative.parts[:-1]) |
| language = path.stem |
| group = grouped.setdefault( |
| (surface, language), |
| {"rows": 0, "base_ids": set(), "solutions": set(), "tests": set()}, |
| ) |
| with path.open() as handle: |
| for line in handle: |
| record = json.loads(line) |
| group["rows"] = int(group["rows"]) + 1 |
| match = re.match(r"^([^/]+)/(\d+)", record["task_id"]) |
| group["base_ids"].add(match.group(2) if match else record["task_id"]) |
| group["solutions"].add(record.get("canonical_solution", "")) |
| group["tests"].add(record.get("test", "")) |
| tree_hash = hashlib.sha256() |
| for path in source_files: |
| tree_hash.update(str(path.relative_to(root)).encode()) |
| tree_hash.update(bytes.fromhex(sha256(path))) |
| rows = [] |
| for (surface, language), group in grouped.items(): |
| rows.append( |
| { |
| "surface": surface, |
| "language": language, |
| "rows": group["rows"], |
| "unique_base_problem_ids": len(group["base_ids"]), |
| "unique_canonical_solutions": len(group["solutions"]), |
| "unique_tests": len(group["tests"]), |
| "source_revision": revision, |
| "audited_tree_sha256": tree_hash.hexdigest(), |
| } |
| ) |
| rows.sort(key=lambda row: (str(row["surface"]), str(row["language"]))) |
| write_csv(output, rows) |
|
|
|
|
| def audit_swe_leaderboard(root: Path, output: Path, revision: str) -> None: |
| """Inventory every frozen leaderboard split without treating it as training data.""" |
| source_files = sorted((root / "data").glob("*.parquet")) |
| if not source_files: |
| raise FileNotFoundError(f"no parquet files found under {root / 'data'}") |
| rows = [] |
| for path in source_files: |
| table = pq.read_table(path, columns=["repo", "instance_id", "base_commit"]) |
| data = table.to_pydict() |
| rows.append( |
| { |
| "split": path.stem.split("-00000", 1)[0], |
| "rows": table.num_rows, |
| "unique_instances": len(set(data["instance_id"])), |
| "unique_repositories": len(set(data["repo"])), |
| "unique_base_commits": len(set(data["base_commit"])), |
| "source_revision": revision, |
| "file_sha256": sha256(path), |
| } |
| ) |
| write_csv(output, rows) |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser() |
| subparsers = parser.add_subparsers(dest="source", required=True) |
|
|
| swe = subparsers.add_parser("swe-rebench-v2") |
| swe.add_argument("--input", type=Path, required=True) |
| swe.add_argument("--output", type=Path, required=True) |
| swe.add_argument("--revision", required=True) |
|
|
| mceval = subparsers.add_parser("mceval-instruct") |
| mceval.add_argument("--input", type=Path, required=True) |
| mceval.add_argument("--output", type=Path, required=True) |
| mceval.add_argument("--revision", required=True) |
|
|
| mceval_eval = subparsers.add_parser("mceval-eval") |
| mceval_eval.add_argument("--input", type=Path, required=True) |
| mceval_eval.add_argument("--output", type=Path, required=True) |
| mceval_eval.add_argument("--revision", required=True) |
|
|
| leaderboard = subparsers.add_parser("swe-rebench-leaderboard") |
| leaderboard.add_argument("--input", type=Path, required=True) |
| leaderboard.add_argument("--output", type=Path, required=True) |
| leaderboard.add_argument("--revision", required=True) |
|
|
| args = parser.parse_args() |
| if args.source == "swe-rebench-v2": |
| audit_swe(args.input, args.output, args.revision) |
| elif args.source == "mceval-instruct": |
| audit_mceval_instruct(args.input, args.output, args.revision) |
| elif args.source == "mceval-eval": |
| audit_mceval_eval(args.input, args.output, args.revision) |
| else: |
| audit_swe_leaderboard(args.input, args.output, args.revision) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|