Download evaluation/src/odu_eval/cli.py from qc316/odubench: direct link, hf CLI and curl.
- Browser
- Download file 7.7 kB
-
https://huggingface.co/datasets/qc316/odubench/resolve/main/evaluation/src/odu_eval/cli.py
- Command line
-
hf download hf://datasets/qc316/odubench/evaluation/src/odu_eval/cli.py
-
curl -L -o cli.py https://huggingface.co/datasets/qc316/odubench/resolve/main/evaluation/src/odu_eval/cli.py
7.7 kB
| """Small CLI: validate, export-inputs, infer, parse, score, aggregate.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| from pathlib import Path | |
| from . import runner | |
| from .dataset import Dataset | |
| from .io import file_digest, indexed, read_jsonl, write_json, write_jsonl | |
| from .providers import Service | |
| def build_parser(): | |
| parser = argparse.ArgumentParser(description="ODU benchmark evaluation") | |
| sub = parser.add_subparsers(dest="command", required=True) | |
| def data(command, selection=False): | |
| p = sub.add_parser(command) | |
| p.add_argument("--data-root", type=Path, required=True) | |
| p.add_argument("--subset", default="main") | |
| if selection: | |
| group = p.add_mutually_exclusive_group() | |
| group.add_argument("--smoke", action="store_true", help="Four deterministic modality/label/clip strata") | |
| group.add_argument("--limit-per-group", type=int, help="First N per modality/label group in manifest order") | |
| return p | |
| p = data("validate") | |
| p.add_argument("--checksums", action="store_true") | |
| for cmd in ["export-inputs", "infer"]: | |
| p = data(cmd, True) | |
| p.add_argument("--prompt-lang", choices=["en"], default="en") | |
| p.add_argument("--wrapped-output", action="store_true") | |
| if cmd == "export-inputs": | |
| p.add_argument("--output", type=Path, required=True) | |
| else: | |
| p.add_argument("--model", choices=["gemini-3.1-pro", "qwen3.5-omni-plus", "openai-compatible"], required=True) | |
| p.add_argument("--output-dir", type=Path, required=True) | |
| p.add_argument("--workers", type=int, default=2) | |
| p.add_argument("--overwrite", action="store_true") | |
| p.add_argument("--no-repair", action="store_true", help="Explicit protocol variation: disable the reference API JSON repair") | |
| p = sub.add_parser("parse") | |
| p.add_argument("--input", type=Path, required=True) | |
| p.add_argument("--output", type=Path, required=True) | |
| p.add_argument("--profile", choices=["api", "local"], required=True) | |
| p.add_argument("--inputs", type=Path, help="Exported inputs whose metadata describes this submission") | |
| p.add_argument("--model-tag", default="custom-model") | |
| group = p.add_mutually_exclusive_group() | |
| group.add_argument("--repair", action="store_true") | |
| group.add_argument("--no-repair", action="store_true") | |
| p.add_argument("--offline", action="store_true") | |
| p.add_argument("--repair-cache", type=Path) | |
| p = data("score", True) | |
| p.add_argument("--predictions", type=Path, required=True) | |
| p.add_argument("--judge", choices=["qwen3.6-flash", "gpt-5.4"], required=True) | |
| p.add_argument("--thinking", choices=["true", "false", "omit"], default=None, help="Qwen enable_thinking; default true") | |
| p.add_argument("--reasoning-effort", choices=["omit", "none", "minimal", "low", "medium", "high", "xhigh"], default="omit") | |
| p.add_argument("--output-dir", type=Path, required=True) | |
| p.add_argument("--judge-cache", type=Path) | |
| p.add_argument("--offline", action="store_true") | |
| p.add_argument("--workers", type=int, default=2) | |
| p.add_argument("--overwrite", action="store_true") | |
| p.add_argument("--t1-report", action="store_true") | |
| p = sub.add_parser("aggregate") | |
| p.add_argument("--runs", type=Path, nargs="+", required=True) | |
| p.add_argument("--output-dir", type=Path, required=True) | |
| p.add_argument("--t1-report", action="store_true") | |
| return parser | |
| def _run(args): | |
| if getattr(args, "workers", 1) < 1: | |
| raise ValueError("--workers must be positive") | |
| if os.environ.get("ODU_M2_DENOM", "union") != "union": | |
| raise ValueError("This release uses union M2. Unset ODU_M2_DENOM; use --t1-report for the alternate table") | |
| if args.command == "parse": | |
| rows = read_jsonl(args.input) | |
| indexed(rows) | |
| meta = runner.read_meta(args.inputs or args.input) | |
| if args.inputs: | |
| allowed = set(meta.get("scene_ids", [])) | |
| if not allowed or set(indexed(rows)) - allowed: | |
| raise ValueError("Submission IDs must belong to the exported inputs") | |
| repair = args.repair or (args.profile == "api" and not args.no_repair) | |
| results, info = runner.parse_rows(rows, args.profile, repair=repair, | |
| cache_dir=args.repair_cache or args.output.parent / "repair_cache", offline=args.offline) | |
| write_jsonl(args.output, results) | |
| write_json(runner.meta_path(args.output), {**meta, "model": args.model_tag, "parser_profile": args.profile, | |
| "predictions_hash": file_digest(args.output), "repair": info}) | |
| summary = {"expected": len(results), "ok": sum(r["status"] == "ok" for r in results)} | |
| status = 0 if summary["ok"] == summary["expected"] else 1 | |
| elif args.command == "aggregate": | |
| summary = runner.aggregate_runs(args.runs, args.output_dir, args.t1_report) | |
| status = 0 | |
| else: | |
| dataset = Dataset(args.data_root, args.subset) | |
| if args.command == "validate": | |
| summary, status = dataset.validate(args.checksums), 0 | |
| else: | |
| rows = dataset.select(smoke=args.smoke, limit_per_group=args.limit_per_group) | |
| selection = "smoke" if args.smoke else (f"limit-per-group-{args.limit_per_group}" if args.limit_per_group else "full") | |
| if args.command == "export-inputs": | |
| summary = runner.export_inputs(dataset, rows, args.output, language=args.prompt_lang, | |
| flat=not args.wrapped_output, selection=selection) | |
| status = 0 | |
| elif args.command == "infer": | |
| summary = runner.infer(dataset, rows, Service(args.model), args.output_dir, workers=args.workers, | |
| language=args.prompt_lang, flat=not args.wrapped_output, | |
| selection=selection, overwrite=args.overwrite, repair=not args.no_repair) | |
| status = 0 if summary["ok"] == summary["expected"] else 1 | |
| else: | |
| if args.judge == "gpt-5.4" and args.thinking is not None: | |
| raise ValueError("Use --reasoning-effort for OpenAI") | |
| if args.judge == "qwen3.6-flash" and args.reasoning_effort != "omit": | |
| raise ValueError("Use --thinking for Qwen") | |
| thinking = (args.thinking or "true") if args.judge == "qwen3.6-flash" else "omit" | |
| service = Service(args.judge, thinking=thinking, reasoning=args.reasoning_effort) | |
| summary = runner.score(dataset, rows if args.smoke or args.limit_per_group else None, | |
| args.predictions, service, args.output_dir, workers=args.workers, | |
| offline=args.offline, judge_cache=args.judge_cache, | |
| overwrite=args.overwrite, t1_report=args.t1_report) | |
| status = 0 if summary["scored"] == summary["expected"] else 1 | |
| print(json.dumps(summary, ensure_ascii=False, indent=2)) | |
| return status | |
| def main(argv=None): | |
| args = build_parser().parse_args(argv) | |
| try: | |
| return _run(args) | |
| except (ValueError, RuntimeError) as exc: | |
| print(f"error: {exc}", file=sys.stderr) | |
| return 2 | |
| except (OSError, KeyError, TypeError) as exc: | |
| # OS/SDK exceptions can include local paths. Expose the category only. | |
| print(f"error: {type(exc).__name__}; check input files and the documented schema", file=sys.stderr) | |
| return 2 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |