Spaces:
Running
Running
yangzhitao
commited on
Commit
·
60906bd
1
Parent(s):
fe8ec74
chores: update configurations
Browse files- .env.example +1 -0
- .vscode/cspell.json +2 -0
- app.py +4 -3
- pyproject.toml +2 -0
- src/envs.py +1 -1
- src/leaderboard/read_evals.py +12 -10
- src/leaderboard/read_evals_orig.py +194 -0
- src/populate.py +65 -2
- src/submission/submit.py +3 -1
- uv.lock +4 -0
.env.example
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
HF_TOKEN=changethis
|
|
|
|
|
|
| 1 |
HF_TOKEN=changethis
|
| 2 |
+
HF_HOME=.
|
.vscode/cspell.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
{
|
| 2 |
"words": [
|
|
|
|
| 3 |
"changethis",
|
|
|
|
| 4 |
"initialisation",
|
| 5 |
"modelcard",
|
| 6 |
"sentencepiece"
|
|
|
|
| 1 |
{
|
| 2 |
"words": [
|
| 3 |
+
"accs",
|
| 4 |
"changethis",
|
| 5 |
+
"evals",
|
| 6 |
"initialisation",
|
| 7 |
"modelcard",
|
| 8 |
"sentencepiece"
|
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 3 |
from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
|
| 4 |
from huggingface_hub import snapshot_download
|
|
|
|
| 5 |
|
| 6 |
from src.about import (
|
| 7 |
CITATION_BUTTON_LABEL,
|
|
@@ -31,10 +33,10 @@ from src.submission.submit import add_new_eval
|
|
| 31 |
def restart_space():
|
| 32 |
API.restart_space(repo_id=settings.REPO_ID)
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
# Space initialisation
|
| 36 |
try:
|
| 37 |
-
print(settings.EVAL_REQUESTS_PATH)
|
| 38 |
snapshot_download(
|
| 39 |
repo_id=settings.QUEUE_REPO,
|
| 40 |
local_dir=settings.EVAL_REQUESTS_PATH,
|
|
@@ -46,7 +48,6 @@ try:
|
|
| 46 |
except Exception:
|
| 47 |
restart_space()
|
| 48 |
try:
|
| 49 |
-
print(settings.EVAL_RESULTS_PATH)
|
| 50 |
snapshot_download(
|
| 51 |
repo_id=settings.RESULTS_REPO,
|
| 52 |
local_dir=settings.EVAL_RESULTS_PATH,
|
|
@@ -73,7 +74,7 @@ LEADERBOARD_DF = get_leaderboard_df(
|
|
| 73 |
) = get_evaluation_queue_df(settings.EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 74 |
|
| 75 |
|
| 76 |
-
def init_leaderboard(dataframe):
|
| 77 |
if dataframe is None or dataframe.empty:
|
| 78 |
raise ValueError("Leaderboard DataFrame is empty or None.")
|
| 79 |
return Leaderboard(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 4 |
from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
+
from rich import print
|
| 7 |
|
| 8 |
from src.about import (
|
| 9 |
CITATION_BUTTON_LABEL,
|
|
|
|
| 33 |
def restart_space():
|
| 34 |
API.restart_space(repo_id=settings.REPO_ID)
|
| 35 |
|
| 36 |
+
print("///// --- Settings --- /////", settings.model_dump())
|
| 37 |
|
| 38 |
# Space initialisation
|
| 39 |
try:
|
|
|
|
| 40 |
snapshot_download(
|
| 41 |
repo_id=settings.QUEUE_REPO,
|
| 42 |
local_dir=settings.EVAL_REQUESTS_PATH,
|
|
|
|
| 48 |
except Exception:
|
| 49 |
restart_space()
|
| 50 |
try:
|
|
|
|
| 51 |
snapshot_download(
|
| 52 |
repo_id=settings.RESULTS_REPO,
|
| 53 |
local_dir=settings.EVAL_RESULTS_PATH,
|
|
|
|
| 74 |
) = get_evaluation_queue_df(settings.EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 75 |
|
| 76 |
|
| 77 |
+
def init_leaderboard(dataframe: pd.DataFrame) -> Leaderboard:
|
| 78 |
if dataframe is None or dataframe.empty:
|
| 79 |
raise ValueError("Leaderboard DataFrame is empty or None.")
|
| 80 |
return Leaderboard(
|
pyproject.toml
CHANGED
|
@@ -22,7 +22,9 @@ dependencies = [
|
|
| 22 |
"tokenizers>=0.15.0",
|
| 23 |
"sentencepiece",
|
| 24 |
"python-dotenv>=1.2.1",
|
|
|
|
| 25 |
"pydantic-settings>=2.11.0",
|
|
|
|
| 26 |
]
|
| 27 |
|
| 28 |
[dependency-groups]
|
|
|
|
| 22 |
"tokenizers>=0.15.0",
|
| 23 |
"sentencepiece",
|
| 24 |
"python-dotenv>=1.2.1",
|
| 25 |
+
"pydantic>=2.11.10",
|
| 26 |
"pydantic-settings>=2.11.0",
|
| 27 |
+
"rich>=14.2.0",
|
| 28 |
]
|
| 29 |
|
| 30 |
[dependency-groups]
|
src/envs.py
CHANGED
|
@@ -19,7 +19,7 @@ class Settings(BaseSettings):
|
|
| 19 |
# Change to your org - don't forget to create a results and request dataset, with the correct format!
|
| 20 |
OWNER: Annotated[
|
| 21 |
str,
|
| 22 |
-
Field("y-playground
|
| 23 |
]
|
| 24 |
|
| 25 |
@computed_field
|
|
|
|
| 19 |
# Change to your org - don't forget to create a results and request dataset, with the correct format!
|
| 20 |
OWNER: Annotated[
|
| 21 |
str,
|
| 22 |
+
Field("y-playground"),
|
| 23 |
]
|
| 24 |
|
| 25 |
@computed_field
|
src/leaderboard/read_evals.py
CHANGED
|
@@ -2,9 +2,11 @@ import glob
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
from dataclasses import dataclass
|
|
|
|
| 5 |
|
| 6 |
import dateutil
|
| 7 |
import numpy as np
|
|
|
|
| 8 |
|
| 9 |
from src.display.formatting import make_clickable_model
|
| 10 |
from src.display.utils import AutoEvalColumn, ModelType, Precision, Tasks, WeightType
|
|
@@ -32,7 +34,7 @@ class EvalResult:
|
|
| 32 |
still_on_hub: bool = False
|
| 33 |
|
| 34 |
@classmethod
|
| 35 |
-
def init_from_json_file(
|
| 36 |
"""Inits the result from the specific model result file"""
|
| 37 |
with open(json_filepath) as fp:
|
| 38 |
data = json.load(fp)
|
|
@@ -78,7 +80,7 @@ class EvalResult:
|
|
| 78 |
mean_acc = np.mean(accs) * 100.0
|
| 79 |
results[task.benchmark] = mean_acc
|
| 80 |
|
| 81 |
-
return
|
| 82 |
eval_name=result_key,
|
| 83 |
full_model=full_model,
|
| 84 |
org=org,
|
|
@@ -90,25 +92,25 @@ class EvalResult:
|
|
| 90 |
architecture=architecture,
|
| 91 |
)
|
| 92 |
|
| 93 |
-
def update_with_request_file(self, requests_path):
|
| 94 |
"""Finds the relevant request file for the current model and updates info with it"""
|
| 95 |
request_file = get_request_file_for_model(requests_path, self.full_model, self.precision.value.name)
|
| 96 |
|
| 97 |
try:
|
| 98 |
with open(request_file) as f:
|
| 99 |
-
request = json.load(f)
|
| 100 |
self.model_type = ModelType.from_str(request.get("model_type", ""))
|
| 101 |
self.weight_type = WeightType[request.get("weight_type", "Original")]
|
| 102 |
self.license = request.get("license", "?")
|
| 103 |
self.likes = request.get("likes", 0)
|
| 104 |
self.num_params = request.get("params", 0)
|
| 105 |
self.date = request.get("submitted_time", "")
|
| 106 |
-
except Exception:
|
| 107 |
print(
|
| 108 |
-
f"Could not find request file for {self.org}/{self.model} with precision {self.precision.value.name}"
|
| 109 |
)
|
| 110 |
|
| 111 |
-
def to_dict(self):
|
| 112 |
"""Converts the Eval Result to a dict compatible with our dataframe display"""
|
| 113 |
average = sum(v for v in self.results.values() if v is not None) / len(Tasks)
|
| 114 |
data_dict = {
|
|
@@ -154,7 +156,7 @@ def get_request_file_for_model(requests_path, model_name, precision):
|
|
| 154 |
|
| 155 |
def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResult]:
|
| 156 |
"""From the path of the results folder root, extract all needed info for results"""
|
| 157 |
-
model_result_filepaths = []
|
| 158 |
|
| 159 |
for root, _, files in os.walk(results_path):
|
| 160 |
# We should only have json files in model results
|
|
@@ -170,7 +172,7 @@ def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResu
|
|
| 170 |
for file in files:
|
| 171 |
model_result_filepaths.append(os.path.join(root, file))
|
| 172 |
|
| 173 |
-
eval_results = {}
|
| 174 |
for model_result_filepath in model_result_filepaths:
|
| 175 |
# Creation of result
|
| 176 |
eval_result = EvalResult.init_from_json_file(model_result_filepath)
|
|
@@ -183,7 +185,7 @@ def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResu
|
|
| 183 |
else:
|
| 184 |
eval_results[eval_name] = eval_result
|
| 185 |
|
| 186 |
-
results = []
|
| 187 |
for v in eval_results.values():
|
| 188 |
try:
|
| 189 |
v.to_dict() # we test if the dict version is complete
|
|
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
from dataclasses import dataclass
|
| 5 |
+
from typing import Any
|
| 6 |
|
| 7 |
import dateutil
|
| 8 |
import numpy as np
|
| 9 |
+
from typing_extensions import Self
|
| 10 |
|
| 11 |
from src.display.formatting import make_clickable_model
|
| 12 |
from src.display.utils import AutoEvalColumn, ModelType, Precision, Tasks, WeightType
|
|
|
|
| 34 |
still_on_hub: bool = False
|
| 35 |
|
| 36 |
@classmethod
|
| 37 |
+
def init_from_json_file(cls, json_filepath: str) -> Self:
|
| 38 |
"""Inits the result from the specific model result file"""
|
| 39 |
with open(json_filepath) as fp:
|
| 40 |
data = json.load(fp)
|
|
|
|
| 80 |
mean_acc = np.mean(accs) * 100.0
|
| 81 |
results[task.benchmark] = mean_acc
|
| 82 |
|
| 83 |
+
return cls(
|
| 84 |
eval_name=result_key,
|
| 85 |
full_model=full_model,
|
| 86 |
org=org,
|
|
|
|
| 92 |
architecture=architecture,
|
| 93 |
)
|
| 94 |
|
| 95 |
+
def update_with_request_file(self, requests_path: str) -> None:
|
| 96 |
"""Finds the relevant request file for the current model and updates info with it"""
|
| 97 |
request_file = get_request_file_for_model(requests_path, self.full_model, self.precision.value.name)
|
| 98 |
|
| 99 |
try:
|
| 100 |
with open(request_file) as f:
|
| 101 |
+
request: dict[str, Any] = json.load(f)
|
| 102 |
self.model_type = ModelType.from_str(request.get("model_type", ""))
|
| 103 |
self.weight_type = WeightType[request.get("weight_type", "Original")]
|
| 104 |
self.license = request.get("license", "?")
|
| 105 |
self.likes = request.get("likes", 0)
|
| 106 |
self.num_params = request.get("params", 0)
|
| 107 |
self.date = request.get("submitted_time", "")
|
| 108 |
+
except Exception as e:
|
| 109 |
print(
|
| 110 |
+
f"Could not find request file for {self.org}/{self.model} with precision {self.precision.value.name}. Error: {e}"
|
| 111 |
)
|
| 112 |
|
| 113 |
+
def to_dict(self) -> dict:
|
| 114 |
"""Converts the Eval Result to a dict compatible with our dataframe display"""
|
| 115 |
average = sum(v for v in self.results.values() if v is not None) / len(Tasks)
|
| 116 |
data_dict = {
|
|
|
|
| 156 |
|
| 157 |
def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResult]:
|
| 158 |
"""From the path of the results folder root, extract all needed info for results"""
|
| 159 |
+
model_result_filepaths: list[str] = []
|
| 160 |
|
| 161 |
for root, _, files in os.walk(results_path):
|
| 162 |
# We should only have json files in model results
|
|
|
|
| 172 |
for file in files:
|
| 173 |
model_result_filepaths.append(os.path.join(root, file))
|
| 174 |
|
| 175 |
+
eval_results: dict[str, EvalResult] = {}
|
| 176 |
for model_result_filepath in model_result_filepaths:
|
| 177 |
# Creation of result
|
| 178 |
eval_result = EvalResult.init_from_json_file(model_result_filepath)
|
|
|
|
| 185 |
else:
|
| 186 |
eval_results[eval_name] = eval_result
|
| 187 |
|
| 188 |
+
results: list[EvalResult] = []
|
| 189 |
for v in eval_results.values():
|
| 190 |
try:
|
| 191 |
v.to_dict() # we test if the dict version is complete
|
src/leaderboard/read_evals_orig.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import glob
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from dataclasses import dataclass
|
| 5 |
+
|
| 6 |
+
import dateutil
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
from src.display.formatting import make_clickable_model
|
| 10 |
+
from src.display.utils import AutoEvalColumn, ModelType, Precision, Tasks, WeightType
|
| 11 |
+
from src.submission.check_validity import is_model_on_hub
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass
|
| 15 |
+
class EvalResult:
|
| 16 |
+
"""Represents one full evaluation. Built from a combination of the result and request file for a given run."""
|
| 17 |
+
|
| 18 |
+
eval_name: str # org_model_precision (uid)
|
| 19 |
+
full_model: str # org/model (path on hub)
|
| 20 |
+
org: str
|
| 21 |
+
model: str
|
| 22 |
+
revision: str # commit hash, "" if main
|
| 23 |
+
results: dict
|
| 24 |
+
precision: Precision = Precision.Unknown
|
| 25 |
+
model_type: ModelType = ModelType.Unknown # Pretrained, fine tuned, ...
|
| 26 |
+
weight_type: WeightType = WeightType.Original # Original or Adapter
|
| 27 |
+
architecture: str = "Unknown"
|
| 28 |
+
license: str = "?"
|
| 29 |
+
likes: int = 0
|
| 30 |
+
num_params: int = 0
|
| 31 |
+
date: str = "" # submission date of request file
|
| 32 |
+
still_on_hub: bool = False
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def init_from_json_file(self, json_filepath):
|
| 36 |
+
"""Inits the result from the specific model result file"""
|
| 37 |
+
with open(json_filepath) as fp:
|
| 38 |
+
data = json.load(fp)
|
| 39 |
+
|
| 40 |
+
config = data.get("config")
|
| 41 |
+
|
| 42 |
+
# Precision
|
| 43 |
+
precision = Precision.from_str(config.get("model_dtype"))
|
| 44 |
+
|
| 45 |
+
# Get model and org
|
| 46 |
+
org_and_model = config.get("model_name", config.get("model_args", None))
|
| 47 |
+
org_and_model = org_and_model.split("/", 1)
|
| 48 |
+
|
| 49 |
+
if len(org_and_model) == 1:
|
| 50 |
+
org = None
|
| 51 |
+
model = org_and_model[0]
|
| 52 |
+
result_key = f"{model}_{precision.value.name}"
|
| 53 |
+
else:
|
| 54 |
+
org = org_and_model[0]
|
| 55 |
+
model = org_and_model[1]
|
| 56 |
+
result_key = f"{org}_{model}_{precision.value.name}"
|
| 57 |
+
full_model = "/".join(org_and_model)
|
| 58 |
+
|
| 59 |
+
still_on_hub, _, model_config = is_model_on_hub(
|
| 60 |
+
full_model, config.get("model_sha", "main"), trust_remote_code=True, test_tokenizer=False
|
| 61 |
+
)
|
| 62 |
+
architecture = "?"
|
| 63 |
+
if model_config is not None:
|
| 64 |
+
architectures = getattr(model_config, "architectures", None)
|
| 65 |
+
if architectures:
|
| 66 |
+
architecture = ";".join(architectures)
|
| 67 |
+
|
| 68 |
+
# Extract results available in this file (some results are split in several files)
|
| 69 |
+
results = {}
|
| 70 |
+
for task in Tasks:
|
| 71 |
+
task = task.value
|
| 72 |
+
|
| 73 |
+
# We average all scores of a given metric (not all metrics are present in all files)
|
| 74 |
+
accs = np.array([v.get(task.metric, None) for k, v in data["results"].items() if task.benchmark == k])
|
| 75 |
+
if accs.size == 0 or any(acc is None for acc in accs):
|
| 76 |
+
continue
|
| 77 |
+
|
| 78 |
+
mean_acc = np.mean(accs) * 100.0
|
| 79 |
+
results[task.benchmark] = mean_acc
|
| 80 |
+
|
| 81 |
+
return self(
|
| 82 |
+
eval_name=result_key,
|
| 83 |
+
full_model=full_model,
|
| 84 |
+
org=org,
|
| 85 |
+
model=model,
|
| 86 |
+
results=results,
|
| 87 |
+
precision=precision,
|
| 88 |
+
revision=config.get("model_sha", ""),
|
| 89 |
+
still_on_hub=still_on_hub,
|
| 90 |
+
architecture=architecture,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
def update_with_request_file(self, requests_path):
|
| 94 |
+
"""Finds the relevant request file for the current model and updates info with it"""
|
| 95 |
+
request_file = get_request_file_for_model(requests_path, self.full_model, self.precision.value.name)
|
| 96 |
+
|
| 97 |
+
try:
|
| 98 |
+
with open(request_file) as f:
|
| 99 |
+
request = json.load(f)
|
| 100 |
+
self.model_type = ModelType.from_str(request.get("model_type", ""))
|
| 101 |
+
self.weight_type = WeightType[request.get("weight_type", "Original")]
|
| 102 |
+
self.license = request.get("license", "?")
|
| 103 |
+
self.likes = request.get("likes", 0)
|
| 104 |
+
self.num_params = request.get("params", 0)
|
| 105 |
+
self.date = request.get("submitted_time", "")
|
| 106 |
+
except Exception:
|
| 107 |
+
print(
|
| 108 |
+
f"Could not find request file for {self.org}/{self.model} with precision {self.precision.value.name}"
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
def to_dict(self):
|
| 112 |
+
"""Converts the Eval Result to a dict compatible with our dataframe display"""
|
| 113 |
+
average = sum(v for v in self.results.values() if v is not None) / len(Tasks)
|
| 114 |
+
data_dict = {
|
| 115 |
+
"eval_name": self.eval_name, # not a column, just a save name,
|
| 116 |
+
AutoEvalColumn.precision.name: self.precision.value.name,
|
| 117 |
+
AutoEvalColumn.model_type.name: self.model_type.value.name,
|
| 118 |
+
AutoEvalColumn.model_type_symbol.name: self.model_type.value.symbol,
|
| 119 |
+
AutoEvalColumn.weight_type.name: self.weight_type.value.name,
|
| 120 |
+
AutoEvalColumn.architecture.name: self.architecture,
|
| 121 |
+
AutoEvalColumn.model.name: make_clickable_model(self.full_model),
|
| 122 |
+
AutoEvalColumn.revision.name: self.revision,
|
| 123 |
+
AutoEvalColumn.average.name: average,
|
| 124 |
+
AutoEvalColumn.license.name: self.license,
|
| 125 |
+
AutoEvalColumn.likes.name: self.likes,
|
| 126 |
+
AutoEvalColumn.params.name: self.num_params,
|
| 127 |
+
AutoEvalColumn.still_on_hub.name: self.still_on_hub,
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
for task in Tasks:
|
| 131 |
+
data_dict[task.value.col_name] = self.results[task.value.benchmark]
|
| 132 |
+
|
| 133 |
+
return data_dict
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def get_request_file_for_model(requests_path, model_name, precision):
|
| 137 |
+
"""Selects the correct request file for a given model. Only keeps runs tagged as FINISHED"""
|
| 138 |
+
request_files = os.path.join(
|
| 139 |
+
requests_path,
|
| 140 |
+
f"{model_name}_eval_request_*.json",
|
| 141 |
+
)
|
| 142 |
+
request_files = glob.glob(request_files)
|
| 143 |
+
|
| 144 |
+
# Select correct request file (precision)
|
| 145 |
+
request_file = ""
|
| 146 |
+
request_files = sorted(request_files, reverse=True)
|
| 147 |
+
for tmp_request_file in request_files:
|
| 148 |
+
with open(tmp_request_file) as f:
|
| 149 |
+
req_content = json.load(f)
|
| 150 |
+
if req_content["status"] in ["FINISHED"] and req_content["precision"] == precision.split(".")[-1]:
|
| 151 |
+
request_file = tmp_request_file
|
| 152 |
+
return request_file
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResult]:
|
| 156 |
+
"""From the path of the results folder root, extract all needed info for results"""
|
| 157 |
+
model_result_filepaths = []
|
| 158 |
+
|
| 159 |
+
for root, _, files in os.walk(results_path):
|
| 160 |
+
# We should only have json files in model results
|
| 161 |
+
if len(files) == 0 or any(not f.endswith(".json") for f in files):
|
| 162 |
+
continue
|
| 163 |
+
|
| 164 |
+
# Sort the files by date
|
| 165 |
+
try:
|
| 166 |
+
files.sort(key=lambda x: x.removesuffix(".json").removeprefix("results_")[:-7])
|
| 167 |
+
except dateutil.parser._parser.ParserError:
|
| 168 |
+
files = [files[-1]]
|
| 169 |
+
|
| 170 |
+
for file in files:
|
| 171 |
+
model_result_filepaths.append(os.path.join(root, file))
|
| 172 |
+
|
| 173 |
+
eval_results = {}
|
| 174 |
+
for model_result_filepath in model_result_filepaths:
|
| 175 |
+
# Creation of result
|
| 176 |
+
eval_result = EvalResult.init_from_json_file(model_result_filepath)
|
| 177 |
+
eval_result.update_with_request_file(requests_path)
|
| 178 |
+
|
| 179 |
+
# Store results of same eval together
|
| 180 |
+
eval_name = eval_result.eval_name
|
| 181 |
+
if eval_name in eval_results.keys():
|
| 182 |
+
eval_results[eval_name].results.update({k: v for k, v in eval_result.results.items() if v is not None})
|
| 183 |
+
else:
|
| 184 |
+
eval_results[eval_name] = eval_result
|
| 185 |
+
|
| 186 |
+
results = []
|
| 187 |
+
for v in eval_results.values():
|
| 188 |
+
try:
|
| 189 |
+
v.to_dict() # we test if the dict version is complete
|
| 190 |
+
results.append(v)
|
| 191 |
+
except KeyError: # not all eval values present
|
| 192 |
+
continue
|
| 193 |
+
|
| 194 |
+
return results
|
src/populate.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
|
|
@@ -9,7 +24,29 @@ from src.leaderboard.read_evals import get_raw_eval_results
|
|
| 9 |
|
| 10 |
|
| 11 |
def get_leaderboard_df(results_path: str, requests_path: str, cols: list, benchmark_cols: list) -> pd.DataFrame:
|
| 12 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
raw_data = get_raw_eval_results(results_path, requests_path)
|
| 14 |
all_data_json = [v.to_dict() for v in raw_data]
|
| 15 |
|
|
@@ -23,7 +60,33 @@ def get_leaderboard_df(results_path: str, requests_path: str, cols: list, benchm
|
|
| 23 |
|
| 24 |
|
| 25 |
def get_evaluation_queue_df(save_path: str, cols: list) -> list[pd.DataFrame]:
|
| 26 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
entries = [entry for entry in os.listdir(save_path) if not entry.startswith(".")]
|
| 28 |
all_evals = []
|
| 29 |
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data population utilities for leaderboard and evaluation queue management.
|
| 3 |
+
|
| 4 |
+
This module provides functions to create and populate pandas DataFrames from evaluation
|
| 5 |
+
results and submission data. It handles data processing for both the main leaderboard
|
| 6 |
+
display and the evaluation queue status tracking.
|
| 7 |
+
|
| 8 |
+
Key Functions:
|
| 9 |
+
get_leaderboard_df: Creates a sorted leaderboard DataFrame from evaluation results
|
| 10 |
+
get_evaluation_queue_df: Creates separate DataFrames for different evaluation statuses
|
| 11 |
+
|
| 12 |
+
The module processes JSON files containing evaluation results and submission metadata,
|
| 13 |
+
applies formatting transformations, and filters data based on completion status.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
import json
|
| 17 |
import os
|
| 18 |
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
def get_leaderboard_df(results_path: str, requests_path: str, cols: list, benchmark_cols: list) -> pd.DataFrame:
|
| 27 |
+
"""
|
| 28 |
+
Creates a sorted leaderboard DataFrame from evaluation results.
|
| 29 |
+
|
| 30 |
+
This function processes raw evaluation data from JSON files and creates a pandas
|
| 31 |
+
DataFrame suitable for leaderboard display. The resulting DataFrame is sorted by
|
| 32 |
+
average performance scores in descending order and filtered to exclude incomplete
|
| 33 |
+
evaluations.
|
| 34 |
+
|
| 35 |
+
Args:
|
| 36 |
+
results_path (str): Path to the directory containing evaluation result files
|
| 37 |
+
requests_path (str): Path to the directory containing evaluation request files
|
| 38 |
+
cols (list): List of column names to include in the final DataFrame
|
| 39 |
+
benchmark_cols (list): List of benchmark column names used for filtering
|
| 40 |
+
|
| 41 |
+
Returns:
|
| 42 |
+
pd.DataFrame: A sorted and filtered DataFrame containing leaderboard data.
|
| 43 |
+
Rows are sorted by average score (descending) and filtered to
|
| 44 |
+
exclude entries with missing benchmark results.
|
| 45 |
+
|
| 46 |
+
Note:
|
| 47 |
+
The function automatically rounds numeric values to 2 decimal places and
|
| 48 |
+
filters out any entries that have NaN values in the specified benchmark columns.
|
| 49 |
+
"""
|
| 50 |
raw_data = get_raw_eval_results(results_path, requests_path)
|
| 51 |
all_data_json = [v.to_dict() for v in raw_data]
|
| 52 |
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
def get_evaluation_queue_df(save_path: str, cols: list) -> list[pd.DataFrame]:
|
| 63 |
+
"""
|
| 64 |
+
Creates separate DataFrames for different evaluation queue statuses.
|
| 65 |
+
|
| 66 |
+
This function scans a directory for evaluation submission files (both individual
|
| 67 |
+
JSON files and files within subdirectories) and categorizes them by their status.
|
| 68 |
+
It returns three separate DataFrames: finished, running, and pending evaluations.
|
| 69 |
+
|
| 70 |
+
Args:
|
| 71 |
+
save_path (str): Path to the directory containing evaluation submission files
|
| 72 |
+
cols (list): List of column names to include in the final DataFrames
|
| 73 |
+
|
| 74 |
+
Returns:
|
| 75 |
+
list[pd.DataFrame]: A list containing three DataFrames in order:
|
| 76 |
+
1. df_finished: Evaluations with status "FINISHED*" or "PENDING_NEW_EVAL"
|
| 77 |
+
2. df_running: Evaluations with status "RUNNING"
|
| 78 |
+
3. df_pending: Evaluations with status "PENDING" or "RERUN"
|
| 79 |
+
|
| 80 |
+
Note:
|
| 81 |
+
The function processes both individual JSON files and JSON files within
|
| 82 |
+
subdirectories (excluding markdown files). Model names are automatically
|
| 83 |
+
converted to clickable links, and revision defaults to "main" if not specified.
|
| 84 |
+
|
| 85 |
+
Status categorization:
|
| 86 |
+
- FINISHED: Any status starting with "FINISHED" or "PENDING_NEW_EVAL"
|
| 87 |
+
- RUNNING: Status equals "RUNNING"
|
| 88 |
+
- PENDING: Status equals "PENDING" or "RERUN"
|
| 89 |
+
"""
|
| 90 |
entries = [entry for entry in os.listdir(save_path) if not entry.startswith(".")]
|
| 91 |
all_evals = []
|
| 92 |
|
src/submission/submit.py
CHANGED
|
@@ -59,7 +59,9 @@ def add_new_eval(
|
|
| 59 |
return styled_error(f'Base model "{base_model}" {error}')
|
| 60 |
|
| 61 |
if not weight_type == "Adapter":
|
| 62 |
-
model_on_hub, error, _ = is_model_on_hub(
|
|
|
|
|
|
|
| 63 |
if not model_on_hub:
|
| 64 |
return styled_error(f'Model "{model}" {error}')
|
| 65 |
|
|
|
|
| 59 |
return styled_error(f'Base model "{base_model}" {error}')
|
| 60 |
|
| 61 |
if not weight_type == "Adapter":
|
| 62 |
+
model_on_hub, error, _ = is_model_on_hub(
|
| 63 |
+
model_name=model, revision=revision, token=settings.TOKEN, test_tokenizer=True
|
| 64 |
+
)
|
| 65 |
if not model_on_hub:
|
| 66 |
return styled_error(f'Model "{model}" {error}')
|
| 67 |
|
uv.lock
CHANGED
|
@@ -681,9 +681,11 @@ dependencies = [
|
|
| 681 |
{ name = "matplotlib" },
|
| 682 |
{ name = "numpy" },
|
| 683 |
{ name = "pandas" },
|
|
|
|
| 684 |
{ name = "pydantic-settings" },
|
| 685 |
{ name = "python-dateutil" },
|
| 686 |
{ name = "python-dotenv" },
|
|
|
|
| 687 |
{ name = "sentencepiece" },
|
| 688 |
{ name = "tokenizers" },
|
| 689 |
{ name = "tqdm" },
|
|
@@ -707,9 +709,11 @@ requires-dist = [
|
|
| 707 |
{ name = "matplotlib" },
|
| 708 |
{ name = "numpy" },
|
| 709 |
{ name = "pandas" },
|
|
|
|
| 710 |
{ name = "pydantic-settings", specifier = ">=2.11.0" },
|
| 711 |
{ name = "python-dateutil" },
|
| 712 |
{ name = "python-dotenv", specifier = ">=1.2.1" },
|
|
|
|
| 713 |
{ name = "sentencepiece" },
|
| 714 |
{ name = "tokenizers", specifier = ">=0.15.0" },
|
| 715 |
{ name = "tqdm" },
|
|
|
|
| 681 |
{ name = "matplotlib" },
|
| 682 |
{ name = "numpy" },
|
| 683 |
{ name = "pandas" },
|
| 684 |
+
{ name = "pydantic" },
|
| 685 |
{ name = "pydantic-settings" },
|
| 686 |
{ name = "python-dateutil" },
|
| 687 |
{ name = "python-dotenv" },
|
| 688 |
+
{ name = "rich" },
|
| 689 |
{ name = "sentencepiece" },
|
| 690 |
{ name = "tokenizers" },
|
| 691 |
{ name = "tqdm" },
|
|
|
|
| 709 |
{ name = "matplotlib" },
|
| 710 |
{ name = "numpy" },
|
| 711 |
{ name = "pandas" },
|
| 712 |
+
{ name = "pydantic", specifier = ">=2.11.10" },
|
| 713 |
{ name = "pydantic-settings", specifier = ">=2.11.0" },
|
| 714 |
{ name = "python-dateutil" },
|
| 715 |
{ name = "python-dotenv", specifier = ">=1.2.1" },
|
| 716 |
+
{ name = "rich", specifier = ">=14.2.0" },
|
| 717 |
{ name = "sentencepiece" },
|
| 718 |
{ name = "tokenizers", specifier = ">=0.15.0" },
|
| 719 |
{ name = "tqdm" },
|