Datasets:
Tasks:
Text Classification
Formats:
parquet
Languages:
English
Size:
1K - 10K
Tags:
structured-decisions
calibration
probabilistic-classification
system-one
workflow-evaluation
Synthetic
License:
Add HF Jobs how-to for benchmarking a model
#40
by SaylorTwift HF Staff - opened
- README.md +21 -0
- bench/__pycache__/score_with_jobs.cpython-312.pyc +0 -0
- bench/score_with_jobs.py +114 -0
- bench/score_with_jobs.sh +10 -0
README.md
CHANGED
|
@@ -143,6 +143,27 @@ against it by setting `TYPESAFE_BASE_URL`.
|
|
| 143 |
To add a model, score it on `test` with the full distributions and open a
|
| 144 |
discussion with the numbers and the mode (specialist or general) it used.
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
### Notes on the rows
|
| 147 |
|
| 148 |
- **Liquid AI d1** was measured on 2026-09-30 through Liquid's API
|
|
|
|
| 143 |
To add a model, score it on `test` with the full distributions and open a
|
| 144 |
discussion with the numbers and the mode (specialist or general) it used.
|
| 145 |
|
| 146 |
+
### Benchmarking a model with HF Jobs
|
| 147 |
+
|
| 148 |
+
One command scores any model that serves vLLM's `/v1/systemone` (any model
|
| 149 |
+
without a native server works this way; serve it with a current nightly). It
|
| 150 |
+
runs one request per case (state + all five questions) over the `test` split
|
| 151 |
+
and prints accuracy, KL from gold, Brier and ECE:
|
| 152 |
+
|
| 153 |
+
```bash
|
| 154 |
+
hf jobs run --flavor a100-large --timeout 2h \\
|
| 155 |
+
--env MODEL_ID=your-org/your-model \\
|
| 156 |
+
--volume hf://datasets/LocalLLaMA/typed-decisions:/repo:ro \\
|
| 157 |
+
pytorch/pytorch:2.9.1-cuda12.8-cudnn9-devel \\
|
| 158 |
+
bash /repo/bench/score_with_jobs.sh
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
- Pick the `--flavor` for the model's size: `l4x1` up to ~2B, `l40sx1` or
|
| 162 |
+
`a100-large` for ~27B, `h200` above. Gated models also need `--secrets HF_TOKEN`.
|
| 163 |
+
- `bench/score_with_jobs.sh` installs vLLM nightly, serves the model, scores all
|
| 164 |
+
400 cases, and writes `results.json`.
|
| 165 |
+
- Then open a discussion with the numbers and the mode (specialist or general).
|
| 166 |
+
|
| 167 |
### Notes on the rows
|
| 168 |
|
| 169 |
- **Liquid AI d1** was measured on 2026-09-30 through Liquid's API
|
bench/__pycache__/score_with_jobs.cpython-312.pyc
ADDED
|
Binary file (7.22 kB). View file
|
|
|
bench/score_with_jobs.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Score a decision model on the Typed Decisions test split with HF Jobs.
|
| 2 |
+
|
| 3 |
+
Serves the model with vLLM's `/v1/systemone` (vLLM nightly), sends one request
|
| 4 |
+
per case (state + all five questions), and reports accuracy, KL from gold,
|
| 5 |
+
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
|
| 13 |
+
import os
|
| 14 |
+
import statistics
|
| 15 |
+
import subprocess
|
| 16 |
+
import sys
|
| 17 |
+
import time
|
| 18 |
+
|
| 19 |
+
import requests
|
| 20 |
+
from datasets import load_dataset
|
| 21 |
+
|
| 22 |
+
PORT = 8000
|
| 23 |
+
BASE = f"http://127.0.0.1:{PORT}"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def score_one(pred, gold):
|
| 27 |
+
opts = list(gold["probabilities"].keys())
|
| 28 |
+
g = [float(gold["probabilities"][o]) for o in opts]
|
| 29 |
+
if gold["type"] == "noul": # engines report yes/no; gold uses true/false
|
| 30 |
+
pred = dict(pred)
|
| 31 |
+
pred["probabilities"] = {
|
| 32 |
+
{"yes": "true", "no": "false"}.get(k, k): v for k, v in pred["probabilities"].items()
|
| 33 |
+
}
|
| 34 |
+
p = [float(pred["probabilities"].get(o, 0.0)) for o in opts]
|
| 35 |
+
s = sum(p)
|
| 36 |
+
p = [v / s for v in p] if s > 0 else [1.0 / len(opts)] * len(opts)
|
| 37 |
+
am_p = p.index(max(p))
|
| 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():
|
| 45 |
+
model = sys.argv[1]
|
| 46 |
+
flags = os.environ.get("SERVE_FLAGS", "--max-model-len 8192 --max-num-seqs 8 --logprobs-mode raw_logprobs")
|
| 47 |
+
proc = subprocess.Popen(
|
| 48 |
+
["vllm", "serve", model, "--port", str(PORT)] + flags.split(),
|
| 49 |
+
stdout=sys.stdout, stderr=sys.stdout,
|
| 50 |
+
)
|
| 51 |
+
while True:
|
| 52 |
+
if proc.poll() is not None:
|
| 53 |
+
raise SystemExit(f"vllm serve exited with code {proc.returncode}")
|
| 54 |
+
try:
|
| 55 |
+
if requests.get(BASE + "/health", timeout=5).status_code == 200:
|
| 56 |
+
break
|
| 57 |
+
except requests.RequestException:
|
| 58 |
+
pass
|
| 59 |
+
time.sleep(10)
|
| 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,
|
| 67 |
+
"state": json.loads(raw["state"]),
|
| 68 |
+
"questions": json.loads(raw["questions"]),
|
| 69 |
+
}
|
| 70 |
+
r = requests.post(BASE + "/v1/systemone", json=payload, timeout=300)
|
| 71 |
+
r.raise_for_status()
|
| 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)
|
| 79 |
+
confs.append(conf)
|
| 80 |
+
if (i + 1) % 50 == 0:
|
| 81 |
+
print(f"[bench] {i + 1}/{len(ds)} cases (acc {sum(accs) / len(accs):.4f})", flush=True)
|
| 82 |
+
|
| 83 |
+
n = len(accs)
|
| 84 |
+
n_bins = 10
|
| 85 |
+
bin_hits = [0] * n_bins
|
| 86 |
+
bin_total = [0] * n_bins
|
| 87 |
+
bin_conf = [0.0] * n_bins
|
| 88 |
+
for ok, conf in zip(accs, confs):
|
| 89 |
+
b = min(int(conf * n_bins), n_bins - 1)
|
| 90 |
+
bin_total[b] += 1
|
| 91 |
+
bin_hits[b] += int(ok)
|
| 92 |
+
bin_conf[b] += conf
|
| 93 |
+
ece = 0.0
|
| 94 |
+
for b in range(n_bins):
|
| 95 |
+
if bin_total[b]:
|
| 96 |
+
ece += bin_total[b] / n * abs(bin_hits[b] / bin_total[b] - bin_conf[b] / bin_total[b])
|
| 97 |
+
summary = {
|
| 98 |
+
"model": model,
|
| 99 |
+
"n_cases": len(ds),
|
| 100 |
+
"n_decisions": n,
|
| 101 |
+
"accuracy": sum(accs) / n,
|
| 102 |
+
"kl_from_gold": sum(kls) / n,
|
| 103 |
+
"brier": sum(briers) / n,
|
| 104 |
+
"ece": ece,
|
| 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()
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
main()
|
bench/score_with_jobs.sh
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Bootstrap for `hf jobs run`: install deps, then score $MODEL_ID on the test split.
|
| 3 |
+
# Reads $MODEL_ID (required). Optional: $SERVE_FLAGS (extra `vllm serve` flags).
|
| 4 |
+
set -euo pipefail
|
| 5 |
+
|
| 6 |
+
MODEL_ID=${MODEL_ID:?set --env MODEL_ID=org/model}
|
| 7 |
+
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
| 8 |
+
pip install -q datasets requests
|
| 9 |
+
pip install -q -U vllm --torch-backend=auto --extra-index-url https://wheels.vllm.ai/nightly
|
| 10 |
+
python "$SCRIPT_DIR/score_with_jobs.py" "$MODEL_ID"
|