ProWM-Bench / prowm_bench /__main__.py
simonlqy's picture
Initial release of ProWM-Bench v1.0.0 (part 4)
d9befd2 verified
Raw History Blame Contribute Delete
4.01 kB
"""Run from the unpacked directory: python3 -m prowm_bench --help."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from .dataset import DEFAULT_ROOT, load_dataset, verify_release
from .scoring import check_reference, score
def main() -> None:
parser = argparse.ArgumentParser(
description='ProWM-Bench: frozen inputs and five paper metrics. Python 3.9+; no pip packages, Docker or GPU needed for loading/scoring.',
epilog='Workflow: verify -> export -> send each messages array to your model without tools -> score. For a runnable HTTP client see python3 examples/run_model.py --help. '
'Prediction JSONL: {"item_id":"...","branch":"official_tests","response":"raw model JSON answer","finish_reason":"stop"}. '
'Alternatively use "prediction":{...}. Keep all item IDs; missing branches count as zero. '
'Only prompts and input images are model inputs. Targets, probes, gold images and examples/reference_predictions are scoring/audit material.',
)
parser.add_argument('--root', type=Path, default=DEFAULT_ROOT, help='unpacked dataset root (normally auto-detected)')
commands = parser.add_subparsers(dest='command', required=True)
commands.add_parser('verify', help='verify every file checksum and all 1,707 reconstructed prompt hashes')
commands.add_parser('selfcheck', help='re-score frozen reference predictions and check the original five metrics')
commands.add_parser('info', help='show populations and dataset metadata')
export = commands.add_parser('export', help='write label-free chat requests as JSONL; embedded PNGs work offline')
export.add_argument('--subset', choices=('swemm', 'rs'), required=True)
export.add_argument('--output', type=Path, required=True, help='new output file; existing files are never overwritten')
export.add_argument('--limit', type=int, help='item count for a quick integration check (not a paper result)')
grading = commands.add_parser('score', help='score predictions with the full frozen denominator')
grading.add_argument('--subset', choices=('swemm', 'rs'), required=True)
grading.add_argument('--predictions', type=Path, required=True)
grading.add_argument('--output', type=Path, help='save report to a new JSON file')
grading.add_argument('--details', action='store_true', help='include per-item scores and validation errors')
grading.add_argument('--allow-json-fences', action='store_true', help='also accept one complete ```json block; recorded in the report')
args = parser.parse_args()
if args.command == 'verify':
result = verify_release(args.root)
elif args.command == 'selfcheck':
result = {subset: check_reference(load_dataset(subset, args.root)) for subset in ('swemm', 'rs')}
elif args.command == 'info':
result = json.loads((args.root / 'manifest.json').read_text(encoding='utf-8'))
elif args.command == 'export':
if args.limit is not None and args.limit < 1:
parser.error('--limit must be positive')
dataset = load_dataset(args.subset, args.root)
count = 0
with args.output.open('x', encoding='utf-8') as output:
for request in dataset.requests(limit=args.limit):
output.write(json.dumps(request, ensure_ascii=False, allow_nan=False) + '\n')
count += 1
result = {'output': str(args.output), 'requests': count, 'subset': args.subset}
else:
result = score(load_dataset(args.subset, args.root), args.predictions,
allow_json_fences=args.allow_json_fences, details=args.details)
if args.output:
with args.output.open('x', encoding='utf-8') as output:
json.dump(result, output, ensure_ascii=False, indent=2, allow_nan=False)
output.write('\n')
print(json.dumps(result, ensure_ascii=False, indent=2, allow_nan=False))
if __name__ == '__main__':
main()