Update src/backend/run_eval_suite.py
Browse files- src/backend/run_eval_suite.py +73 -19
src/backend/run_eval_suite.py
CHANGED
@@ -1,9 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
import os
|
3 |
import logging
|
4 |
from datetime import datetime
|
5 |
|
6 |
from lm_eval import tasks, evaluator, utils
|
|
|
7 |
|
8 |
from src.envs import RESULTS_REPO, API
|
9 |
from src.backend.manage_requests import EvalRequest
|
@@ -18,32 +75,29 @@ def run_evaluation(eval_request: EvalRequest, task_names, num_fewshot, batch_siz
|
|
18 |
task_names = ["medmcqa", "medqa_4options", "mmlu_anatomy", "mmlu_clinical_knowledge", "mmlu_college_biology", "mmlu_college_medicine", "mmlu_medical_genetics", "mmlu_professional_medicine", "pubmedqa"]
|
19 |
|
20 |
print(f"Selected Tasks: {task_names}")
|
21 |
-
results = evaluator.simple_evaluate(
|
22 |
-
model="hf-causal-experimental", # "hf-causal"
|
23 |
-
model_args=eval_request.get_model_args(),
|
24 |
-
tasks=task_names,
|
25 |
-
# num_fewshot=num_fewshot,
|
26 |
-
batch_size=batch_size,
|
27 |
-
device=device,
|
28 |
-
no_cache=no_cache,
|
29 |
-
limit=limit,
|
30 |
-
write_out=True,
|
31 |
-
output_base_path="logs"
|
32 |
-
)
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
dumped = json.dumps(
|
39 |
-
print(dumped)
|
40 |
|
41 |
output_path = os.path.join(local_dir, *eval_request.model.split("/"), f"results_{datetime.now()}.json")
|
42 |
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
43 |
with open(output_path, "w") as f:
|
44 |
f.write(dumped)
|
45 |
|
46 |
-
print(evaluator.make_table(
|
47 |
|
48 |
API.upload_file(
|
49 |
path_or_fileobj=output_path,
|
@@ -52,4 +106,4 @@ def run_evaluation(eval_request: EvalRequest, task_names, num_fewshot, batch_siz
|
|
52 |
repo_type="dataset",
|
53 |
)
|
54 |
|
55 |
-
return
|
|
|
1 |
+
# import json
|
2 |
+
# import os
|
3 |
+
# import logging
|
4 |
+
# from datetime import datetime
|
5 |
+
|
6 |
+
# from lm_eval import tasks, evaluator, utils
|
7 |
+
|
8 |
+
# from src.envs import RESULTS_REPO, API
|
9 |
+
# from src.backend.manage_requests import EvalRequest
|
10 |
+
|
11 |
+
# logging.getLogger("openai").setLevel(logging.WARNING)
|
12 |
+
|
13 |
+
# def run_evaluation(eval_request: EvalRequest, task_names, num_fewshot, batch_size, device, local_dir: str, results_repo: str, no_cache=True, limit=None):
|
14 |
+
# if limit:
|
15 |
+
# print(
|
16 |
+
# "WARNING: --limit SHOULD ONLY BE USED FOR TESTING. REAL METRICS SHOULD NOT BE COMPUTED USING LIMIT."
|
17 |
+
# )
|
18 |
+
# task_names = ["medmcqa", "medqa_4options", "mmlu_anatomy", "mmlu_clinical_knowledge", "mmlu_college_biology", "mmlu_college_medicine", "mmlu_medical_genetics", "mmlu_professional_medicine", "pubmedqa"]
|
19 |
+
|
20 |
+
# print(f"Selected Tasks: {task_names}")
|
21 |
+
# results = evaluator.simple_evaluate(
|
22 |
+
# model="hf-causal-experimental", # "hf-causal"
|
23 |
+
# model_args=eval_request.get_model_args(),
|
24 |
+
# tasks=task_names,
|
25 |
+
# # num_fewshot=num_fewshot,
|
26 |
+
# batch_size=batch_size,
|
27 |
+
# device=device,
|
28 |
+
# no_cache=no_cache,
|
29 |
+
# limit=limit,
|
30 |
+
# write_out=True,
|
31 |
+
# output_base_path="logs"
|
32 |
+
# )
|
33 |
+
|
34 |
+
# results["config"]["model_dtype"] = eval_request.precision
|
35 |
+
# results["config"]["model_name"] = eval_request.model
|
36 |
+
# results["config"]["model_sha"] = eval_request.revision
|
37 |
+
|
38 |
+
# dumped = json.dumps(results, indent=2)
|
39 |
+
# print(dumped)
|
40 |
+
|
41 |
+
# output_path = os.path.join(local_dir, *eval_request.model.split("/"), f"results_{datetime.now()}.json")
|
42 |
+
# os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
43 |
+
# with open(output_path, "w") as f:
|
44 |
+
# f.write(dumped)
|
45 |
+
|
46 |
+
# print(evaluator.make_table(results))
|
47 |
+
|
48 |
+
# API.upload_file(
|
49 |
+
# path_or_fileobj=output_path,
|
50 |
+
# path_in_repo=f"{eval_request.model}/results_{datetime.now()}.json",
|
51 |
+
# repo_id=results_repo,
|
52 |
+
# repo_type="dataset",
|
53 |
+
# )
|
54 |
+
|
55 |
+
# return results
|
56 |
+
|
57 |
import json
|
58 |
import os
|
59 |
import logging
|
60 |
from datetime import datetime
|
61 |
|
62 |
from lm_eval import tasks, evaluator, utils
|
63 |
+
import requests
|
64 |
|
65 |
from src.envs import RESULTS_REPO, API
|
66 |
from src.backend.manage_requests import EvalRequest
|
|
|
75 |
task_names = ["medmcqa", "medqa_4options", "mmlu_anatomy", "mmlu_clinical_knowledge", "mmlu_college_biology", "mmlu_college_medicine", "mmlu_medical_genetics", "mmlu_professional_medicine", "pubmedqa"]
|
76 |
|
77 |
print(f"Selected Tasks: {task_names}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
url = os.environ.get("URL")
|
80 |
+
|
81 |
+
data = {"args": f"pretrained={eval_request.model}"}
|
82 |
+
print("datasending", data)
|
83 |
+
response = requests.post(url, json=data)
|
84 |
+
print("response, response", response)
|
85 |
+
results_full = {'results': {}, 'config': {}}
|
86 |
+
|
87 |
+
results_full['results'] = response.json()['result']['results']
|
88 |
+
results_full["config"]["model_dtype"] = eval_request.precision
|
89 |
+
results_full["config"]["model_name"] = eval_request.model
|
90 |
+
results_full["config"]["model_sha"] = eval_request.revision
|
91 |
|
92 |
+
dumped = json.dumps(results_full, indent=2)
|
93 |
+
# print(dumped)
|
94 |
|
95 |
output_path = os.path.join(local_dir, *eval_request.model.split("/"), f"results_{datetime.now()}.json")
|
96 |
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
97 |
with open(output_path, "w") as f:
|
98 |
f.write(dumped)
|
99 |
|
100 |
+
# print(evaluator.make_table(results_full))
|
101 |
|
102 |
API.upload_file(
|
103 |
path_or_fileobj=output_path,
|
|
|
106 |
repo_type="dataset",
|
107 |
)
|
108 |
|
109 |
+
return results_full
|