code update
Browse files- src/leaderboard/read_evals.py +81 -13
src/leaderboard/read_evals.py
CHANGED
|
@@ -153,28 +153,95 @@ def get_request_file_for_model(requests_path, model_name, precision):
|
|
| 153 |
return request_file
|
| 154 |
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResult]:
|
| 157 |
"""From the path of the results folder root, extract all needed info for results"""
|
| 158 |
model_result_filepaths = []
|
| 159 |
|
| 160 |
print(f"DEBUG: Results path: {results_path}")
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
continue
|
| 169 |
|
| 170 |
-
#
|
| 171 |
try:
|
| 172 |
-
|
| 173 |
-
except dateutil.parser._parser.ParserError:
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
model_result_filepaths.append(os.path.join(root, file))
|
|
|
|
| 178 |
|
| 179 |
eval_results = {}
|
| 180 |
for model_result_filepath in model_result_filepaths:
|
|
@@ -195,6 +262,7 @@ def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResu
|
|
| 195 |
v.to_dict() # we test if the dict version is complete
|
| 196 |
results.append(v)
|
| 197 |
except KeyError: # not all eval values present
|
|
|
|
| 198 |
continue
|
| 199 |
|
| 200 |
return results
|
|
|
|
| 153 |
return request_file
|
| 154 |
|
| 155 |
|
| 156 |
+
# def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResult]:
|
| 157 |
+
# """From the path of the results folder root, extract all needed info for results"""
|
| 158 |
+
# model_result_filepaths = []
|
| 159 |
+
|
| 160 |
+
# print(f"DEBUG: Results path: {results_path}")
|
| 161 |
+
# files = os.listdir(results_path)
|
| 162 |
+
# for f in files:
|
| 163 |
+
# print(f)
|
| 164 |
+
|
| 165 |
+
# for root, _, files in os.walk(results_path):
|
| 166 |
+
# # We should only have json files in model results
|
| 167 |
+
# if len(files) == 0 or any([not f.endswith(".json") for f in files]):
|
| 168 |
+
# continue
|
| 169 |
+
|
| 170 |
+
# # Sort the files by date
|
| 171 |
+
# try:
|
| 172 |
+
# files.sort(key=lambda x: x.removesuffix(".json").removeprefix("results_")[:-7])
|
| 173 |
+
# except dateutil.parser._parser.ParserError:
|
| 174 |
+
# files = [files[-1]]
|
| 175 |
+
|
| 176 |
+
# for file in files:
|
| 177 |
+
# model_result_filepaths.append(os.path.join(root, file))
|
| 178 |
+
|
| 179 |
+
# eval_results = {}
|
| 180 |
+
# for model_result_filepath in model_result_filepaths:
|
| 181 |
+
# # Creation of result
|
| 182 |
+
# eval_result = EvalResult.init_from_json_file(model_result_filepath)
|
| 183 |
+
# eval_result.update_with_request_file(requests_path)
|
| 184 |
+
|
| 185 |
+
# # Store results of same eval together
|
| 186 |
+
# eval_name = eval_result.eval_name
|
| 187 |
+
# if eval_name in eval_results.keys():
|
| 188 |
+
# eval_results[eval_name].results.update({k: v for k, v in eval_result.results.items() if v is not None})
|
| 189 |
+
# else:
|
| 190 |
+
# eval_results[eval_name] = eval_result
|
| 191 |
+
|
| 192 |
+
# results = []
|
| 193 |
+
# for v in eval_results.values():
|
| 194 |
+
# try:
|
| 195 |
+
# v.to_dict() # we test if the dict version is complete
|
| 196 |
+
# results.append(v)
|
| 197 |
+
# except KeyError: # not all eval values present
|
| 198 |
+
# continue
|
| 199 |
+
|
| 200 |
+
# return results
|
| 201 |
+
|
| 202 |
def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResult]:
|
| 203 |
"""From the path of the results folder root, extract all needed info for results"""
|
| 204 |
model_result_filepaths = []
|
| 205 |
|
| 206 |
print(f"DEBUG: Results path: {results_path}")
|
| 207 |
+
try:
|
| 208 |
+
files = os.listdir(results_path)
|
| 209 |
+
for f in files:
|
| 210 |
+
print(f)
|
| 211 |
+
except FileNotFoundError:
|
| 212 |
+
print(f"Error: Directory not found at {results_path}")
|
| 213 |
+
return [] # Exit early if path doesn't exist
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
# Change signature from (root, _, files) to (root, dirs, files)
|
| 218 |
+
# This allows us to modify 'dirs' to stop unwanted recursion.
|
| 219 |
+
for root, dirs, files in os.walk(results_path):
|
| 220 |
+
|
| 221 |
+
# 1. Prevent recursion into hidden directories (like .cache, .git)
|
| 222 |
+
dirs[:] = [d for d in dirs if not d.startswith('.')]
|
| 223 |
+
|
| 224 |
+
# 2. Filter the 'files' list to only include .json files
|
| 225 |
+
json_files = [f for f in files if f.endswith(".json")]
|
| 226 |
+
|
| 227 |
+
# 3. If no .json files were found in this directory, skip it
|
| 228 |
+
if not json_files:
|
| 229 |
continue
|
| 230 |
|
| 231 |
+
# 4. Now, apply the sorting logic ONLY to the filtered json_files
|
| 232 |
try:
|
| 233 |
+
json_files.sort(key=lambda x: x.removesuffix(".json").removeprefix("results_")[:-7])
|
| 234 |
+
except (dateutil.parser._parser.ParserError, IndexError): # Added IndexError for safety
|
| 235 |
+
# Original logic: if parsing fails, just use the last file.
|
| 236 |
+
if json_files:
|
| 237 |
+
json_files = [json_files[-1]]
|
| 238 |
+
else:
|
| 239 |
+
continue # Should not happen, but good to be safe
|
| 240 |
+
|
| 241 |
+
# 5. Add the full paths of the sorted json files to our list
|
| 242 |
+
for file in json_files:
|
| 243 |
model_result_filepaths.append(os.path.join(root, file))
|
| 244 |
+
|
| 245 |
|
| 246 |
eval_results = {}
|
| 247 |
for model_result_filepath in model_result_filepaths:
|
|
|
|
| 262 |
v.to_dict() # we test if the dict version is complete
|
| 263 |
results.append(v)
|
| 264 |
except KeyError: # not all eval values present
|
| 265 |
+
print(f"Warning: Skipping {v.eval_name} due to missing eval values.")
|
| 266 |
continue
|
| 267 |
|
| 268 |
return results
|