"""Create the Typed Decisions eval YAML and open a PR on the model repo. Usage: python submit_results.py MODEL_ID [RESULTS_JSON] [--mode general|specialist] [--predictions PATH] [--dry-run] Reads the summary produced by score_with_jobs.py (accuracy, kl_from_gold, brier, ece), writes the Hub eval-results YAML, and opens a pull request on the model repo (`.eval_results/.yaml`). When predictions.jsonl from the same run is present (next to RESULTS_JSON unless --predictions says otherwise), the PR also adds it as `eval/typed-decisions/predictions.jsonl` so the scores can be re-derived. With --dry-run the YAML is printed instead of uploaded. """ import argparse import datetime import json import os BENCH = "LocalLLaMA/typed-decisions" TASKS = ["accuracy", "kl_from_gold", "brier", "ece"] NOTE_SPECIALIST = ( "Model was fitted/fine-tuned on this benchmark's train split; " "not comparable with zero-shot rows." ) def build_yaml(summary: dict, mode: str, date: str) -> str: lines = [] for task_id in TASKS: value = round(float(summary[task_id]), 4) lines += [ "- dataset:", f" id: {BENCH}", f" task_id: {task_id}", f" value: {value}", f' date: "{date}"', " source:", f" url: https://huggingface.co/datasets/{BENCH}", ' name: "Typed Decisions benchmark run on HF Jobs"', ] if mode == "specialist": lines.append(f" notes: {json.dumps(NOTE_SPECIALIST)}") return "\n".join(lines) + "\n" def main(): ap = argparse.ArgumentParser(description=__doc__) ap.add_argument("model_id", help="model repo the results belong to, e.g. org/model") ap.add_argument("results", nargs="?", default="results.json", help="summary JSON from score_with_jobs.py") ap.add_argument("--mode", choices=["general", "specialist"], default="general", help="specialist = fitted on the benchmark's train split") ap.add_argument("--predictions", default=None, help="per-decision probabilities from score_with_jobs.py (default: predictions.jsonl next to " "the results file), added to the PR if present") ap.add_argument("--dry-run", action="store_true", help="print the YAML instead of opening a PR") args = ap.parse_args() with open(args.results) as f: summary = json.load(f) missing = [t for t in TASKS if t not in summary] if missing: raise SystemExit(f"results file is missing task keys: {missing}") date = datetime.date.today().isoformat() yaml_text = build_yaml(summary, args.mode, date) file_name = args.model_id.replace("/", "__") + ".yaml" if args.dry_run: print(yaml_text) return from huggingface_hub import CommitOperationAdd, HfApi ops = [CommitOperationAdd(path_in_repo=f".eval_results/{file_name}", path_or_fileobj=yaml_text.encode())] predictions = args.predictions or os.path.join(os.path.dirname(args.results), "predictions.jsonl") if os.path.exists(predictions): ops.append(CommitOperationAdd(path_in_repo="eval/typed-decisions/predictions.jsonl", path_or_fileobj=predictions)) api = HfApi() commit = api.create_commit( repo_id=args.model_id, repo_type="model", operations=ops, create_pr=True, commit_message="Add Typed Decisions eval results", commit_description=( f"{args.mode} run on {date}: accuracy {summary['accuracy']}, " f"KL {summary['kl_from_gold']}, Brier {summary['brier']}, ECE {summary['ece']} " f"({summary['n_decisions']} decisions, one request per case)." ), ) pr_url = getattr(commit, "pr_url", None) or getattr(commit, "pull_request_url", "") print(f"[submit] eval results opened as a PR on {args.model_id}: {pr_url}", flush=True) if __name__ == "__main__": main()