Add HF Jobs how-to for benchmarking a model

#42
by SaylorTwift HF Staff - opened
Files changed (3) hide show
  1. README.md +5 -2
  2. bench/score_with_jobs.sh +8 -1
  3. bench/submit_results.py +85 -0
README.md CHANGED
@@ -153,16 +153,19 @@ and prints accuracy, KL from gold, Brier and ECE:
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
 
 
153
  ```bash
154
  hf jobs run --flavor a100-large --timeout 2h \\
155
  --env MODEL_ID=your-org/your-model \\
156
+ --secrets HF_TOKEN \\
157
  --volume hf://datasets/LocalLLaMA/typed-decisions:/repo:ro \\
158
  pytorch/pytorch:2.9.1-cuda12.8-cudnn9-devel \\
159
  bash /repo/bench/score_with_jobs.sh
160
  ```
161
 
162
  - Pick the `--flavor` for the model's size: `l4x1` up to ~2B, `l40sx1` or
163
+ `a100-large` for ~27B, `h200` above.
164
  - `bench/score_with_jobs.sh` installs vLLM nightly, serves the model, scores all
165
  400 cases, and writes `results.json`.
166
+ - The run finishes by creating the eval YAML and opening a PR on the model repo
167
+ with the four scores, so they show on the Hub leaderboard once merged. Add
168
+ `--env MODE=specialist` if you fitted the model on `train`.
169
 
170
  ### Notes on the rows
171
 
bench/score_with_jobs.sh CHANGED
@@ -1,6 +1,7 @@
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}
@@ -8,3 +9,9 @@ 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"
 
 
 
 
 
 
 
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
+ # $MODE=general|specialist, $HF_TOKEN (opens the eval-results PR automatically).
5
  set -euo pipefail
6
 
7
  MODEL_ID=${MODEL_ID:?set --env MODEL_ID=org/model}
 
9
  pip install -q datasets requests
10
  pip install -q -U vllm --torch-backend=auto --extra-index-url https://wheels.vllm.ai/nightly
11
  python "$SCRIPT_DIR/score_with_jobs.py" "$MODEL_ID"
12
+
13
+ if [ -n "${HF_TOKEN:-}" ]; then
14
+ python "$SCRIPT_DIR/submit_results.py" "$MODEL_ID" results.json --mode "${MODE:-general}"
15
+ else
16
+ echo "[submit] pass --secrets HF_TOKEN to also open a PR with the eval results on the model repo"
17
+ fi
bench/submit_results.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]
17
+ NOTE_SPECIALIST = (
18
+ "Model was fitted/fine-tuned on this benchmark's train split; "
19
+ "not comparable with zero-shot rows."
20
+ )
21
+
22
+
23
+ def build_yaml(summary: dict, mode: str, date: str) -> str:
24
+ lines = []
25
+ for task_id in TASKS:
26
+ value = round(float(summary[task_id]), 4)
27
+ lines += [
28
+ "- dataset:",
29
+ f" id: {BENCH}",
30
+ f" task_id: {task_id}",
31
+ f" value: {value}",
32
+ f' date: "{date}"',
33
+ " source:",
34
+ f" url: https://huggingface.co/datasets/{BENCH}",
35
+ ' name: "Typed Decisions benchmark run on HF Jobs"',
36
+ ]
37
+ if mode == "specialist":
38
+ lines.append(f" notes: {json.dumps(NOTE_SPECIALIST)}")
39
+ return "\n".join(lines) + "\n"
40
+
41
+
42
+ def main():
43
+ ap = argparse.ArgumentParser(description=__doc__)
44
+ ap.add_argument("model_id", help="model repo the results belong to, e.g. org/model")
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
+
51
+ with open(args.results) as f:
52
+ summary = json.load(f)
53
+ missing = [t for t in TASKS if t not in summary]
54
+ if missing:
55
+ raise SystemExit(f"results file is missing task keys: {missing}")
56
+ date = datetime.date.today().isoformat()
57
+ yaml_text = build_yaml(summary, args.mode, date)
58
+
59
+ file_name = args.model_id.replace("/", "__") + ".yaml"
60
+ if args.dry_run:
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=(
75
+ f"{args.mode} run on {date}: accuracy {summary['accuracy']}, "
76
+ f"KL {summary['kl_from_gold']}, Brier {summary['brier']}, ECE {summary['ece']} "
77
+ f"({summary['n_decisions']} decisions, one request per case)."
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__":
85
+ main()