-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathget_results.py
More file actions
executable file
·343 lines (301 loc) · 14.4 KB
/
get_results.py
File metadata and controls
executable file
·343 lines (301 loc) · 14.4 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
import json
import os
import shutil
import numpy as np
from numpy import mean
from glob import glob
from utils import *
from tqdm import tqdm
import pandas as pd
import itertools
import math
from datasets import Dataset, DatasetDict, load_dataset
from transformers import AutoTokenizer
def update_model_info(model_info):
for model, info in model_info.items():
if "https://huggingface.co/" in info["link"]:
hf_model = info["link"].split("https://huggingface.co/")[-1]
print(hf_model)
try:
tokenizer = AutoTokenizer.from_pretrained(hf_model, trust_remote_code=True)
if tokenizer.chat_template is None:
model_info[model]["direct_complete"] = True
else:
model_info[model]["direct_complete"] = False
except:
model_info[model]["direct_complete"] = True
else:
model_info[model]["direct_complete"] = False
return model_info
def get_results(tids):
results = {}
for model, info in model_info.items():
results[info["name"]] = {
"link": info["link"],
"open-data": info["open-data"],
"pass@1": {
"complete": None,
"instruct": None,
"complete-cal": None,
"instruct-cal": None,
},
"prompted": info["prompted"],
"moe": info["moe"],
"size": info["size"],
"act_param": info["act_param"],
# "direct_complete": info["direct_complete"],
}
for model, info in model_info.items():
model = model.replace("/", "--")
hf_model = ""
files = glob(f"results/{model}--bigcodebench-*_eval_results.json")
assert files, f"No files found for results/{model}--bigcodebench-*_eval_results.json"
for file in files:
try:
_, suffix = os.path.basename(file).split("--bigcodebench-hard-")
with open("results/"+model+"--bigcodebench-hard-"+suffix, "r") as f:
data = json.load(f)
except:
_, suffix = os.path.basename(file).split("--bigcodebench-")
with open("results/"+model+"--bigcodebench-"+suffix, "r") as f:
data = json.load(f)
status = []
if len(data["eval"]) < len(tids):
continue
for key, value in data["eval"].items():
if key not in tids:
continue
if value[0]["status"] == "pass":
status.append(1)
else:
status.append(0)
if suffix.startswith("complete"):
task = "complete"
elif suffix.startswith("instruct"):
task = "instruct"
else:
raise ValueError("Unknown task")
mode = ""
if "calibrated" in file:
mode = "-cal"
results[info["name"]][f"pass@1"][f"{task}{mode}"] = round(mean(status)*100,1)
if not info["prompted"]:# or info["direct_complete"]:
results[info["name"]][f"pass@1"][f"{task}-cal"] = round(mean(status)*100,1)
for model, result in results.items():
for task in ["complete"]:
origin = result["pass@1"].pop(task)
# assert origin, f"Missing original complete results for {model}"
calibrate = result["pass@1"].pop(f"{task}-cal")
if calibrate:
# if calibrate - origin > 1:
# results[model]["lazy"] = True
# else:
# results[model]["lazy"] = False
results[model]["pass@1"][task] = calibrate
else:
# results[model]["lazy"] = False
results[model]["pass@1"][task] = origin
calibrate_instruct = result["pass@1"].pop(f"instruct-cal")
result["pass@1"]["instruct"] = calibrate_instruct
return results
def check_valid(results):
for model, result in results.items():
if result["prompted"] and model not in ["Granite-Code-3B-Instruct", "Granite-Code-8B-Instruct"]:
assert result["pass@1"]["instruct"], model
assert result["pass@1"]["complete"]
def split_gen():
shutil.rmtree("sanitized_samples", ignore_errors=True)
shutil.rmtree("sanitized_calibrated_samples", ignore_errors=True)
os.makedirs("sanitized_samples/complete", exist_ok=True)
os.makedirs("sanitized_samples/instruct", exist_ok=True)
os.makedirs("sanitized_calibrated_samples/complete", exist_ok=True)
os.makedirs("sanitized_calibrated_samples/instruct", exist_ok=True)
for model, info in model_info.items():
model = model.replace("/", "--")
files = glob(f"results/{model}--bigcodebench-*.jsonl")
if info["link"].startswith("https://huggingface.co/"):
model = info["link"].split("https://huggingface.co/")[-1].replace("/", "--")
for file in files:
_, suffix = os.path.basename(file).split("--bigcodebench-")
with open(file, "r") as f:
data = f.readlines()
if "-sanitized" in file:
if "calibrated" in file:
if info["prompted"]:
if suffix.startswith("complete"):
with open(f"sanitized_calibrated_samples/complete/{model}--bigcodebench-{suffix}", "w") as f:
f.writelines(data)
else:
with open(f"sanitized_calibrated_samples/instruct/{model}--bigcodebench-{suffix}", "w") as f:
f.writelines(data)
else:
if suffix.startswith("complete"):
with open(f"sanitized_samples/complete/{model}--bigcodebench-{suffix}", "w") as f:
f.writelines(data)
else:
with open(f"sanitized_samples/instruct/{model}--bigcodebench-{suffix}", "w") as f:
f.writelines(data)
def read_task_perf(tids, task="complete"):
model_results = dict()
result_files = []
for model, info in model_info.items():
if task == "instruct" and (not info["prompted"] or info["name"] in ["Granite-Code-3B-Instruct", "Granite-Code-8B-Instruct"]):
continue
task_perf = dict()
model = model.replace("/", "--")
try:
try:
try:
if info["prompted"]:
files = glob(f"results/{model}--bigcodebench-{task}*-0-1-sanitized*calibrated_eval_results.json")
if files:
file = files[0]
else:
file = glob(f"results/{model}--bigcodebench-{task}*-0-1-sanitized_eval_results.json")[0]
else:
file = glob(f"results/{model}--bigcodebench-{task}*-0-1-sanitized_eval_results.json")[0]
except:
if info["prompted"]:# and not info["direct_complete"]:
files = glob(f"results/{model}--bigcodebench-{task}*-0-1-sanitized*calibrated_hard_eval_results.json")
if files:
file = files[0]
else:
file = glob(f"results/{model}--bigcodebench-{task}*-0-1-sanitized_hard_eval_results.json")[0]
else:
file = glob(f"results/{model}--bigcodebench-{task}*-0-1-sanitized_hard_eval_results.json")[0]
except:
try:
if info["prompted"]:# and not info["direct_complete"]:
files = glob(f"results/{model}--bigcodebench-hard-{task}*-0-1-sanitized*calibrated_hard_eval_results.json")
if files:
file = files[0]
else:
file = glob(f"results/{model}--bigcodebench-hard-{task}*-0-1-sanitized_hard_eval_results.json")[0]
else:
file = glob(f"results/{model}--bigcodebench-hard-{task}*-0-1-sanitized_hard_eval_results.json")[0]
except:
if info["prompted"]:
files = glob(f"results/{model}--bigcodebench-hard-{task}*-0-1-sanitized*calibrated_eval_results.json")
if files:
file = files[0]
else:
file = glob(f"results/{model}--bigcodebench-hard-{task}*-0-1-sanitized_eval_results.json")[0]
else:
file = glob(f"results/{model}--bigcodebench-hard-{task}*-0-1-sanitized_eval_results.json")[0]
except:
continue
result_files.append(file)
with open(file, "r") as f:
data = json.load(f)
if len(data["eval"]) < len(tids):
continue
for task_id, perfs in data["eval"].items():
if task_id in tids:
status = 1 if perfs[0]["status"] == "pass" else 0
task_perf[task_id] = status
model_results[info["name"]] = task_perf
return model_results, result_files
def get_domain_perf(data_dict, task2domain):
domain_perfs = {
"Model": [],
"Computation": [],
"General": [],
"Visualization": [],
"System": [],
"Time": [],
"Network": [],
"Cryptography": []
}
for model, task_perf in data_dict.items():
model_domain = {"Computation": [], "General": [], "Visualization": [], "System": [], "Time": [], "Network": [], "Cryptography": []}
for task_id, status in task_perf.items():
domains = task2domain[task_id]
for domain in domains:
model_domain[domain].append(status)
domain_perf = {domain: round(np.mean(perfs)*100, 1) for domain, perfs in model_domain.items()}
domain_perfs["Model"].append(model)
for domain in model_domain.keys():
domain_perfs[domain].append(domain_perf[domain])
return Dataset.from_dict(domain_perfs)
def get_solve_rate(data_dict, task="complete"):
task_solve_count = dict()
for model, task_perf in data_dict.items():
for task_id, score in task_perf.items():
if task_id not in task_solve_count:
task_solve_count[task_id] = []
task_solve_count[task_id].append(score)
solve_rate = {task_id: round(np.mean(perfs) * 100, 1) for task_id, perfs in task_solve_count.items()}
return Dataset.from_dict({"task_id": list(solve_rate.keys()), "solve_rate": list(solve_rate.values())})
def get_hf_ds(results):
hf_dataset = {"model": [], "link": [], "moe": [], "size": [], "act_param": [], "type": [], #"lazy": [],# "direct_complete": [],
"complete": [], "instruct": []}
for model, result in results.items():
hf_dataset["model"].append(model)
hf_dataset["link"].append(result["link"])
hf_dataset["moe"].append(result["moe"])
hf_dataset["size"].append(result["size"])
hf_dataset["act_param"].append(result["act_param"])
hf_dataset["type"].append("🔶" if result["prompted"] else "🟢")
# hf_dataset["lazy"].append(result["lazy"])
hf_dataset["complete"].append(result["pass@1"]["complete"])
hf_dataset["instruct"].append(result["pass@1"]["instruct"])
# hf_dataset["direct_complete"].append(result["direct_complete"])
return Dataset.from_dict(hf_dataset)
def get_bootstrap_scores(df):
bars = pd.DataFrame(dict(
lower = df.quantile(.025),
rating = df.quantile(.5),
upper = df.quantile(.975))).reset_index(names="model").sort_values("rating", ascending=False)
bars['error_y'] = bars['upper'] - bars["rating"]
bars['error_y_minus'] = bars['rating'] - bars["lower"]
bars['rating_rounded'] = np.round(bars['rating'], 2)
return Dataset.from_pandas(bars)
def push_ds(ds, path, local=False):
if local:
ds.save_to_disk(path)
else:
ds.push_to_hub(path)
def get_perf_df(data_dict):
perfs = {"Model": []}
for task_id in data_dict[list(data_dict.keys())[0]]:
perfs[task_id] = []
for model, task_perf in data_dict.items():
perfs["Model"].append(model)
for task_id, status in task_perf.items():
perfs[task_id].append(status)
return pd.DataFrame(perfs)
if __name__ == "__main__":
# split_gen()
bcb_orig = load_dataset("bigcode/bigcodebench", split="v0.1.1")
bcb_hard = load_dataset("bigcode/bigcodebench-hard", split="v0.1.1")
bcb_config = {
"": bcb_orig,
"-hard": bcb_hard,
}
for suffix, bcb in bcb_config.items():
results = get_results(bcb["task_id"])
files = []
complete_data, complete_files = read_task_perf(bcb["task_id"], "complete")
instruct_data, instruct_files = read_task_perf(bcb["task_id"], "instruct")
complete_df = get_perf_df(complete_data)
instruct_df = get_perf_df(instruct_data)
push_ds(DatasetDict({"complete": Dataset.from_pandas(complete_df), "instruct": Dataset.from_pandas(instruct_df)}), f"bigcode/bigcodebench{suffix}-perf")
with open("task2domain.json", "r") as f:
task2domain = json.load(f)
domain_complete = get_domain_perf(complete_data, task2domain)
domain_instruct = get_domain_perf(instruct_data, task2domain)
DatasetDict({"complete": domain_complete, "instruct": domain_instruct}).push_to_hub(f"bigcode/bigcodebench{suffix}-domain")
files.extend(complete_files)
files.extend(instruct_files)
shutil.rmtree("eval_results", ignore_errors=True)
os.makedirs("eval_results", exist_ok=True)
for file in files:
shutil.copy(file, "eval_results")
complete_solve_rate = get_solve_rate(complete_data, task="complete")
instruct_solve_rate = get_solve_rate(instruct_data, task="instruct")
solve_rate_ds = DatasetDict({"complete": complete_solve_rate, "instruct": instruct_solve_rate})
push_ds(solve_rate_ds, f"bigcode/bigcodebench{suffix}-solve-rate")
with open(f"results{suffix}.json", "w") as f:
json.dump(results, f, indent=4)
ds = get_hf_ds(results)
push_ds(ds, f"bigcode/bigcodebench{suffix}-results")