forked from openai/simple-evals
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_evals.py
More file actions
429 lines (411 loc) · 15.1 KB
/
simple_evals.py
File metadata and controls
429 lines (411 loc) · 15.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
import argparse
import json
import subprocess
from datetime import datetime
import pandas as pd
from . import common
from .browsecomp_eval import BrowseCompEval
from .drop_eval import DropEval
from .gpqa_eval import GPQAEval
from .healthbench_eval import HealthBenchEval
from .healthbench_meta_eval import HealthBenchMetaEval
from .math_eval import MathEval
from .mgsm_eval import MGSMEval
from .mmlu_eval import MMLUEval
from .humaneval_eval import HumanEval
from .sampler.chat_completion_sampler import (
OPENAI_SYSTEM_MESSAGE_API,
OPENAI_SYSTEM_MESSAGE_CHATGPT,
ChatCompletionSampler,
)
from .sampler.claude_sampler import ClaudeCompletionSampler, CLAUDE_SYSTEM_MESSAGE_LMSYS
from .sampler.o_chat_completion_sampler import OChatCompletionSampler
from .sampler.responses_sampler import ResponsesSampler
from .simpleqa_eval import SimpleQAEval
def main():
parser = argparse.ArgumentParser(
description="Run sampling and evaluations using different samplers and evaluations."
)
parser.add_argument(
"--list-models", action="store_true", help="List available models"
)
parser.add_argument(
"--model",
type=str,
help="Select a model by name. Also accepts a comma-separated list of models.",
)
parser.add_argument(
"--eval",
type=str,
help="Select an eval by name. Also accepts a comma-separated list of evals.",
)
parser.add_argument(
"--n-repeats",
type=int,
default=None,
help="Number of repeats to run. Only supported for certain evals.",
)
parser.add_argument(
"--n-threads",
type=int,
default=120,
help="Number of threads to run. Only supported for HealthBench and HealthBenchMeta.",
)
parser.add_argument("--debug", action="store_true", help="Run in debug mode")
parser.add_argument(
"--examples", type=int, help="Number of examples to use (overrides default)"
)
args = parser.parse_args()
models = {
# Reasoning Models
"o3": ResponsesSampler(
model="o3-2025-04-16",
reasoning_model=True,
),
"o3-temp-1": ResponsesSampler(
model="o3-2025-04-16",
reasoning_model=True,
temperature=1.0,
),
"o3_high": ResponsesSampler(
model="o3-2025-04-16",
reasoning_model=True,
reasoning_effort="high",
),
"o3_low": ResponsesSampler(
model="o3-2025-04-16",
reasoning_model=True,
reasoning_effort="low",
),
# Default == Medium
"o4-mini": ResponsesSampler(
model="o4-mini-2025-04-16",
reasoning_model=True,
),
"o4-mini_high": ResponsesSampler(
model="o4-mini-2025-04-16",
reasoning_model=True,
reasoning_effort="high",
),
"o4-mini_low": ResponsesSampler(
model="o4-mini-2025-04-16",
reasoning_model=True,
reasoning_effort="low",
),
"o1-pro": ResponsesSampler(
model="o1-pro",
reasoning_model=True,
),
"o1": OChatCompletionSampler(
model="o1",
),
"o1_high": OChatCompletionSampler(
model="o1",
reasoning_effort="high",
),
"o1_low": OChatCompletionSampler(
model="o1",
reasoning_effort="low",
),
"o1-preview": OChatCompletionSampler(
model="o1-preview",
),
"o1-mini": OChatCompletionSampler(
model="o1-mini",
),
# Default == Medium
"o3-mini": OChatCompletionSampler(
model="o3-mini",
),
"o3-mini_high": OChatCompletionSampler(
model="o3-mini",
reasoning_effort="high",
),
"o3-mini_low": OChatCompletionSampler(
model="o3-mini",
reasoning_effort="low",
),
# GPT-4.1 models
"gpt-4.1": ChatCompletionSampler(
model="gpt-4.1-2025-04-14",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
"gpt-4.1-temp-1": ChatCompletionSampler(
model="gpt-4.1-2025-04-14",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
temperature=1.0,
),
"gpt-4.1-mini": ChatCompletionSampler(
model="gpt-4.1-mini-2025-04-14",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
"gpt-4.1-nano": ChatCompletionSampler(
model="gpt-4.1-nano-2025-04-14",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
# GPT-4o models
"gpt-4o": ChatCompletionSampler(
model="gpt-4o",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
"gpt-4o-2024-11-20": ChatCompletionSampler(
model="gpt-4o-2024-11-20",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
"gpt-4o-2024-08-06": ChatCompletionSampler(
model="gpt-4o-2024-08-06",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
"gpt-4o-2024-08-06-temp-1": ChatCompletionSampler(
model="gpt-4o-2024-08-06",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
temperature=1.0,
),
"gpt-4o-2024-05-13": ChatCompletionSampler(
model="gpt-4o-2024-05-13",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
"gpt-4o-mini": ChatCompletionSampler(
model="gpt-4o-mini-2024-07-18",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
# GPT-4.5 model
"gpt-4.5-preview": ChatCompletionSampler(
model="gpt-4.5-preview-2025-02-27",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
),
# GPT-4-turbo model
"gpt-4-turbo-2024-04-09": ChatCompletionSampler(
model="gpt-4-turbo-2024-04-09",
system_message=OPENAI_SYSTEM_MESSAGE_API,
),
# GPT-4 model
"gpt-4-0613": ChatCompletionSampler(
model="gpt-4-0613",
system_message=OPENAI_SYSTEM_MESSAGE_API,
),
# GPT-3.5 Turbo model
"gpt-3.5-turbo-0125": ChatCompletionSampler(
model="gpt-3.5-turbo-0125",
system_message=OPENAI_SYSTEM_MESSAGE_API,
),
"gpt-3.5-turbo-0125-temp-1": ChatCompletionSampler(
model="gpt-3.5-turbo-0125",
system_message=OPENAI_SYSTEM_MESSAGE_API,
temperature=1.0,
),
# Chatgpt models:
"chatgpt-4o-latest": ChatCompletionSampler(
model="chatgpt-4o-latest",
system_message=OPENAI_SYSTEM_MESSAGE_CHATGPT,
max_tokens=2048,
),
"gpt-4-turbo-2024-04-09_chatgpt": ChatCompletionSampler(
model="gpt-4-turbo-2024-04-09",
system_message=OPENAI_SYSTEM_MESSAGE_CHATGPT,
),
# Claude models:
"claude-3-opus-20240229_empty": ClaudeCompletionSampler(
model="claude-3-opus-20240229",
system_message=CLAUDE_SYSTEM_MESSAGE_LMSYS,
),
"claude-3-7-sonnet-20250219": ClaudeCompletionSampler(
model="claude-3-7-sonnet-20250219",
system_message=CLAUDE_SYSTEM_MESSAGE_LMSYS,
),
"claude-3-haiku-20240307": ClaudeCompletionSampler(
model="claude-3-haiku-20240307",
),
}
if args.list_models:
print("Available models:")
for model_name in models.keys():
print(f" - {model_name}")
return
if args.model:
models_chosen = args.model.split(",")
for model_name in models_chosen:
if model_name not in models:
print(f"Error: Model '{model_name}' not found.")
return
models = {model_name: models[model_name] for model_name in models_chosen}
print(f"Running with args {args}")
grading_sampler = ChatCompletionSampler(
model="gpt-4.1-2025-04-14",
system_message=OPENAI_SYSTEM_MESSAGE_API,
max_tokens=2048,
)
equality_checker = ChatCompletionSampler(model="gpt-4-turbo-preview")
# ^^^ used for fuzzy matching, just for math
def get_evals(eval_name, debug_mode):
num_examples = (
args.examples if args.examples is not None else (5 if debug_mode else None)
)
# Set num_examples = None to reproduce full evals
match eval_name:
case "mmlu":
return MMLUEval(num_examples=1 if debug_mode else num_examples)
case "math":
return MathEval(
equality_checker=equality_checker,
num_examples=num_examples,
n_repeats=1 if debug_mode else args.n_repeats or 10,
)
case "gpqa":
return GPQAEval(
n_repeats=1 if debug_mode else args.n_repeats or 10,
num_examples=num_examples,
)
case "mgsm":
return MGSMEval(
num_examples_per_lang=10 if debug_mode else num_examples or 250
)
case "drop":
return DropEval(
num_examples=10 if debug_mode else num_examples,
train_samples_per_prompt=3,
)
case "humaneval":
return HumanEval(num_examples=10 if debug_mode else num_examples)
case "simpleqa":
return SimpleQAEval(
grader_model=grading_sampler,
num_examples=10 if debug_mode else num_examples,
)
case "browsecomp":
return BrowseCompEval(
grader_model=grading_sampler,
num_examples=10 if debug_mode else num_examples,
)
case "healthbench":
return HealthBenchEval(
grader_model=grading_sampler,
num_examples=10 if debug_mode else num_examples,
n_repeats=args.n_repeats or 1,
n_threads=args.n_threads or 1,
subset_name=None,
)
case "healthbench_hard":
return HealthBenchEval(
grader_model=grading_sampler,
num_examples=10 if debug_mode else num_examples,
n_repeats=args.n_repeats or 1,
n_threads=args.n_threads or 1,
subset_name="hard",
)
case "healthbench_consensus":
return HealthBenchEval(
grader_model=grading_sampler,
num_examples=10 if debug_mode else num_examples,
n_repeats=args.n_repeats or 1,
n_threads=args.n_threads or 1,
subset_name="consensus",
)
case "healthbench_meta":
return HealthBenchMetaEval(
grader_model=grading_sampler,
num_examples=10 if debug_mode else num_examples,
n_repeats=args.n_repeats or 1,
n_threads=args.n_threads or 1,
)
case _:
raise Exception(f"Unrecognized eval type: {eval_name}")
if args.eval:
evals_list = args.eval.split(",")
evals = {}
for eval_name in evals_list:
try:
evals[eval_name] = get_evals(eval_name, args.debug)
except Exception:
print(f"Error: eval '{eval_name}' not found.")
return
else:
evals = {
eval_name: get_evals(eval_name, args.debug)
for eval_name in [
"mmlu",
"math",
"gpqa",
"mgsm",
"drop",
"humaneval",
"simpleqa",
"browsecomp",
"healthbench",
"healthbench_hard",
"healthbench_consensus",
"healthbench_meta",
]
}
print(evals)
debug_suffix = "_DEBUG" if args.debug else ""
print(debug_suffix)
mergekey2resultpath = {}
print(f"Running the following evals: {list(evals.keys())}")
print(f"Running evals for the following models: {list(models.keys())}")
now = datetime.now()
date_str = now.strftime("%Y%m%d_%H%M%S")
for model_name, sampler in models.items():
for eval_name, eval_obj in evals.items():
result = eval_obj(sampler)
# ^^^ how to use a sampler
file_stem = f"{eval_name}_{model_name}"
# file stem should also include the year, month, day, and time in hours and minutes
file_stem += f"_{date_str}"
report_filename = f"/tmp/{file_stem}{debug_suffix}.html"
print(f"Writing report to {report_filename}")
with open(report_filename, "w") as fh:
fh.write(common.make_report(result))
assert result.metrics is not None
metrics = result.metrics | {"score": result.score}
# Sort metrics by key
metrics = dict(sorted(metrics.items()))
print(metrics)
result_filename = f"/tmp/{file_stem}{debug_suffix}.json"
with open(result_filename, "w") as f:
f.write(json.dumps(metrics, indent=2))
print(f"Writing results to {result_filename}")
full_result_filename = f"/tmp/{file_stem}{debug_suffix}_allresults.json"
with open(full_result_filename, "w") as f:
result_dict = {
"score": result.score,
"metrics": result.metrics,
"htmls": result.htmls,
"convos": result.convos,
"metadata": result.metadata,
}
f.write(json.dumps(result_dict, indent=2))
print(f"Writing all results to {full_result_filename}")
mergekey2resultpath[f"{file_stem}"] = result_filename
merge_metrics = []
for eval_model_name, result_filename in mergekey2resultpath.items():
try:
result = json.load(open(result_filename, "r+"))
except Exception as e:
print(e, result_filename)
continue
result = result.get("f1_score", result.get("score", None))
eval_name = eval_model_name[: eval_model_name.find("_")]
model_name = eval_model_name[eval_model_name.find("_") + 1 :]
merge_metrics.append(
{"eval_name": eval_name, "model_name": model_name, "metric": result}
)
merge_metrics_df = pd.DataFrame(merge_metrics).pivot(
index=["model_name"], columns="eval_name"
)
print("\nAll results: ")
print(merge_metrics_df.to_markdown())
return merge_metrics
if __name__ == "__main__":
main()