tardellirs commited on
Commit
0f4bce1
·
verified ·
1 Parent(s): c9e8c41

bench: save per-decision probabilities and add them to the eval-results PR

Browse files

score_with_jobs.py already scores every decision but keeps only the summary. This PR:

- writes `predictions.jsonl` next to `results.json`: one line per decision with case id, workflow, question id, type and the normalized probabilities over the gold options (the vector `score_one` scores, after the yes/no to true/false mapping);
- has `submit_results.py` add that file to the model-repo PR as `eval/typed-decisions/predictions.jsonl` when it is present next to the results file (`--predictions` points elsewhere).

Scoring is unchanged. Replaying a published Jev run (OpenDecider's whole-case file, which their benchmarks README lists as Jev 1.13 through TypeSafe's API) through both versions with vLLM, HTTP and `datasets` mocked gives a byte-identical `results.json` (accuracy 0.7305), and re-scoring `predictions.jsonl` gives the same accuracy, KL, Brier and ECE.

The tie rule (first-listed option vs split credit) is left for a separate change; with the probabilities saved it can be re-applied to any run.

Context: https://huggingface.co/posts/tardellirs/145368791310880

Files changed (2) hide show
  1. bench/score_with_jobs.py +10 -4
  2. bench/submit_results.py +19 -8
bench/score_with_jobs.py CHANGED
@@ -6,7 +6,8 @@ Brier and ECE over the full distributions.
6
 
7
  Usage (inside the job, after setup): python bench/score_with_jobs.py MODEL_ID
8
  Optional env: SERVE_FLAGS (extra `vllm serve` flags).
9
- Results are printed and saved to results.json.
 
10
  """
11
  import json
12
  import math
@@ -38,7 +39,7 @@ def score_one(pred, gold):
38
  am_g = g.index(max(g))
39
  kl = sum(gi * math.log(gi / max(pi, 1e-9)) for gi, pi in zip(g, p) if gi > 0)
40
  brier = sum((pi - gi) ** 2 for pi, gi in zip(p, g))
41
- return am_p == am_g, kl, brier, max(p)
42
 
43
 
44
  def main():
@@ -60,7 +61,7 @@ def main():
60
  print(f"[bench] server ready for {model}", flush=True)
61
 
62
  ds = load_dataset("LocalLLaMA/typed-decisions", "all", split="test")
63
- accs, kls, briers, confs = [], [], [], []
64
  for i, raw in enumerate(ds):
65
  payload = {
66
  "model": model,
@@ -72,7 +73,9 @@ def main():
72
  answers = r.json()["answers"]
73
  gold = json.loads(raw["gold"])
74
  for qid, gq in gold.items():
75
- ok, kl, brier, conf = score_one(answers.get(qid, {"probabilities": {}}), gq)
 
 
76
  accs.append(ok)
77
  kls.append(kl)
78
  briers.append(brier)
@@ -105,6 +108,9 @@ def main():
105
  }
106
  with open("results.json", "w") as f:
107
  json.dump(summary, f, indent=2)
 
 
 
108
  print(json.dumps(summary, indent=2), flush=True)
109
  print("[bench] open a discussion on the dataset with these numbers and the mode (specialist or general).", flush=True)
110
  proc.terminate()
 
6
 
7
  Usage (inside the job, after setup): python bench/score_with_jobs.py MODEL_ID
8
  Optional env: SERVE_FLAGS (extra `vllm serve` flags).
9
+ Results are printed and saved to results.json; the normalized probabilities of every
10
+ decision go to predictions.jsonl, one line per decision keyed on case id and question id.
11
  """
12
  import json
13
  import math
 
39
  am_g = g.index(max(g))
40
  kl = sum(gi * math.log(gi / max(pi, 1e-9)) for gi, pi in zip(g, p) if gi > 0)
41
  brier = sum((pi - gi) ** 2 for pi, gi in zip(p, g))
42
+ return am_p == am_g, kl, brier, max(p), dict(zip(opts, p))
43
 
44
 
45
  def main():
 
61
  print(f"[bench] server ready for {model}", flush=True)
62
 
63
  ds = load_dataset("LocalLLaMA/typed-decisions", "all", split="test")
64
+ accs, kls, briers, confs, preds = [], [], [], [], []
65
  for i, raw in enumerate(ds):
66
  payload = {
67
  "model": model,
 
73
  answers = r.json()["answers"]
74
  gold = json.loads(raw["gold"])
75
  for qid, gq in gold.items():
76
+ ok, kl, brier, conf, probs = score_one(answers.get(qid, {"probabilities": {}}), gq)
77
+ preds.append({"id": raw["id"], "workflow": raw["workflow"], "question": qid,
78
+ "type": gq["type"], "probabilities": probs})
79
  accs.append(ok)
80
  kls.append(kl)
81
  briers.append(brier)
 
108
  }
109
  with open("results.json", "w") as f:
110
  json.dump(summary, f, indent=2)
111
+ with open("predictions.jsonl", "w") as f:
112
+ for p in preds:
113
+ f.write(json.dumps(p) + "\n")
114
  print(json.dumps(summary, indent=2), flush=True)
115
  print("[bench] open a discussion on the dataset with these numbers and the mode (specialist or general).", flush=True)
116
  proc.terminate()
bench/submit_results.py CHANGED
@@ -1,16 +1,20 @@
1
  """Create the Typed Decisions eval YAML and open a PR on the model repo.
2
 
3
  Usage:
4
- python submit_results.py MODEL_ID [RESULTS_JSON] [--mode general|specialist] [--dry-run]
 
5
 
6
  Reads the summary produced by score_with_jobs.py (accuracy, kl_from_gold,
7
  brier, ece), writes the Hub eval-results YAML, and opens a pull request on
8
- the model repo (`.eval_results/<model>.yaml`). With --dry-run the YAML is
9
- printed instead of uploaded.
 
 
10
  """
11
  import argparse
12
  import datetime
13
  import json
 
14
 
15
  BENCH = "LocalLLaMA/typed-decisions"
16
  TASKS = ["accuracy", "kl_from_gold", "brier", "ece"]
@@ -45,6 +49,9 @@ def main():
45
  ap.add_argument("results", nargs="?", default="results.json", help="summary JSON from score_with_jobs.py")
46
  ap.add_argument("--mode", choices=["general", "specialist"], default="general",
47
  help="specialist = fitted on the benchmark's train split")
 
 
 
48
  ap.add_argument("--dry-run", action="store_true", help="print the YAML instead of opening a PR")
49
  args = ap.parse_args()
50
 
@@ -61,14 +68,18 @@ def main():
61
  print(yaml_text)
62
  return
63
 
64
- from huggingface_hub import HfApi
65
 
 
 
 
 
 
66
  api = HfApi()
67
- commit = api.upload_file(
68
- path_or_fileobj=yaml_text.encode(),
69
- path_in_repo=f".eval_results/{file_name}",
70
  repo_id=args.model_id,
71
  repo_type="model",
 
72
  create_pr=True,
73
  commit_message="Add Typed Decisions eval results",
74
  commit_description=(
@@ -78,7 +89,7 @@ def main():
78
  ),
79
  )
80
  pr_url = getattr(commit, "pr_url", None) or getattr(commit, "pull_request_url", "")
81
- print(f"[submit] eval YAML opened as a PR on {args.model_id}: {pr_url}", flush=True)
82
 
83
 
84
  if __name__ == "__main__":
 
1
  """Create the Typed Decisions eval YAML and open a PR on the model repo.
2
 
3
  Usage:
4
+ python submit_results.py MODEL_ID [RESULTS_JSON] [--mode general|specialist]
5
+ [--predictions PATH] [--dry-run]
6
 
7
  Reads the summary produced by score_with_jobs.py (accuracy, kl_from_gold,
8
  brier, ece), writes the Hub eval-results YAML, and opens a pull request on
9
+ the model repo (`.eval_results/<model>.yaml`). When predictions.jsonl from the
10
+ same run is present (next to RESULTS_JSON unless --predictions says otherwise), the
11
+ PR also adds it as `eval/typed-decisions/predictions.jsonl` so the scores can be
12
+ re-derived. With --dry-run the YAML is printed instead of uploaded.
13
  """
14
  import argparse
15
  import datetime
16
  import json
17
+ import os
18
 
19
  BENCH = "LocalLLaMA/typed-decisions"
20
  TASKS = ["accuracy", "kl_from_gold", "brier", "ece"]
 
49
  ap.add_argument("results", nargs="?", default="results.json", help="summary JSON from score_with_jobs.py")
50
  ap.add_argument("--mode", choices=["general", "specialist"], default="general",
51
  help="specialist = fitted on the benchmark's train split")
52
+ ap.add_argument("--predictions", default=None,
53
+ help="per-decision probabilities from score_with_jobs.py (default: predictions.jsonl next to "
54
+ "the results file), added to the PR if present")
55
  ap.add_argument("--dry-run", action="store_true", help="print the YAML instead of opening a PR")
56
  args = ap.parse_args()
57
 
 
68
  print(yaml_text)
69
  return
70
 
71
+ from huggingface_hub import CommitOperationAdd, HfApi
72
 
73
+ ops = [CommitOperationAdd(path_in_repo=f".eval_results/{file_name}", path_or_fileobj=yaml_text.encode())]
74
+ predictions = args.predictions or os.path.join(os.path.dirname(args.results), "predictions.jsonl")
75
+ if os.path.exists(predictions):
76
+ ops.append(CommitOperationAdd(path_in_repo="eval/typed-decisions/predictions.jsonl",
77
+ path_or_fileobj=predictions))
78
  api = HfApi()
79
+ commit = api.create_commit(
 
 
80
  repo_id=args.model_id,
81
  repo_type="model",
82
+ operations=ops,
83
  create_pr=True,
84
  commit_message="Add Typed Decisions eval results",
85
  commit_description=(
 
89
  ),
90
  )
91
  pr_url = getattr(commit, "pr_url", None) or getattr(commit, "pull_request_url", "")
92
+ print(f"[submit] eval results opened as a PR on {args.model_id}: {pr_url}", flush=True)
93
 
94
 
95
  if __name__ == "__main__":