Spaces:
Running
Running
Commit
Β·
89c30b1
1
Parent(s):
6d848c3
regions
Browse files- app.py +27 -1
- src/leaderboard/read_evals.py +28 -5
- src/populate.py +8 -4
app.py
CHANGED
|
@@ -89,6 +89,21 @@ def init_leaderboard(dataframe):
|
|
| 89 |
interactive=False,
|
| 90 |
)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
demo = gr.Blocks(css=custom_css)
|
| 94 |
with demo:
|
|
@@ -97,7 +112,18 @@ with demo:
|
|
| 97 |
|
| 98 |
with gr.Tabs(elem_classes="tab-buttons") as tabs:
|
| 99 |
with gr.TabItem("π
mSTEB Text Benchmark", elem_id="llm-benchmark-tab-table", id=0):
|
| 100 |
-
leaderboard = init_leaderboard(LEADERBOARD_DF)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
with gr.TabItem("π About", elem_id="llm-benchmark-tab-table", id=2):
|
| 103 |
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
|
|
|
|
| 89 |
interactive=False,
|
| 90 |
)
|
| 91 |
|
| 92 |
+
region_dropdown = gr.Dropdown(
|
| 93 |
+
choices=["All", "region_1", "region_2"], # Add all available regions
|
| 94 |
+
label="Select Region",
|
| 95 |
+
value="All",
|
| 96 |
+
interactive=True,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# Initialize the leaderboard with the default region ("All")
|
| 100 |
+
leaderboard_table = gr.Dataframe(
|
| 101 |
+
value=LEADERBOARD_DF,
|
| 102 |
+
headers=COLS,
|
| 103 |
+
datatype=[c.type for c in fields(AutoEvalColumn)],
|
| 104 |
+
row_count=5,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
|
| 108 |
demo = gr.Blocks(css=custom_css)
|
| 109 |
with demo:
|
|
|
|
| 112 |
|
| 113 |
with gr.Tabs(elem_classes="tab-buttons") as tabs:
|
| 114 |
with gr.TabItem("π
mSTEB Text Benchmark", elem_id="llm-benchmark-tab-table", id=0):
|
| 115 |
+
# leaderboard = init_leaderboard(LEADERBOARD_DF)
|
| 116 |
+
with gr.Row():
|
| 117 |
+
region_dropdown.render() # Render the dropdown for region selection
|
| 118 |
+
leaderboard_table.render() # Render the leaderboard table
|
| 119 |
+
# Update leaderboard dynamically based on region selection
|
| 120 |
+
region_dropdown.change(
|
| 121 |
+
lambda region: LEADERBOARD_DF if region == "All" else get_leaderboard_df(EVAL_RESULTS_PATH,
|
| 122 |
+
EVAL_REQUESTS_PATH, COLS,
|
| 123 |
+
BENCHMARK_COLS, region),
|
| 124 |
+
inputs=[region_dropdown],
|
| 125 |
+
outputs=[leaderboard_table],
|
| 126 |
+
)
|
| 127 |
|
| 128 |
with gr.TabItem("π About", elem_id="llm-benchmark-tab-table", id=2):
|
| 129 |
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
|
src/leaderboard/read_evals.py
CHANGED
|
@@ -31,6 +31,7 @@ class EvalResult:
|
|
| 31 |
num_params: int = 0
|
| 32 |
date: str = "" # submission date of request file
|
| 33 |
still_on_hub: bool = False
|
|
|
|
| 34 |
|
| 35 |
@classmethod
|
| 36 |
def init_from_json_file(self, json_filepath):
|
|
@@ -39,6 +40,7 @@ class EvalResult:
|
|
| 39 |
data = json.load(fp)
|
| 40 |
|
| 41 |
config = data.get("config")
|
|
|
|
| 42 |
|
| 43 |
# Precision
|
| 44 |
precision = Precision.from_str(config.get("model_dtype"))
|
|
@@ -78,6 +80,21 @@ class EvalResult:
|
|
| 78 |
|
| 79 |
mean_acc = np.mean(accs) * 100.0
|
| 80 |
results[task.benchmark] = mean_acc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
return self(
|
| 82 |
eval_name=result_key,
|
| 83 |
full_model=full_model,
|
|
@@ -87,7 +104,8 @@ class EvalResult:
|
|
| 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):
|
|
@@ -106,13 +124,14 @@ class EvalResult:
|
|
| 106 |
except Exception:
|
| 107 |
print(f"Could not find request file for {self.org}/{self.model} with precision {self.precision.value.name}")
|
| 108 |
|
| 109 |
-
def to_dict(self):
|
| 110 |
"""Converts the Eval Result to a dict compatible with our dataframe display"""
|
| 111 |
# print(self.results)
|
|
|
|
| 112 |
acc_values = [
|
| 113 |
-
|
| 114 |
for task in Tasks
|
| 115 |
-
if task.value.metric == "acc" and task.value.benchmark in
|
| 116 |
]
|
| 117 |
# print(acc_values)
|
| 118 |
|
|
@@ -136,7 +155,7 @@ class EvalResult:
|
|
| 136 |
}
|
| 137 |
|
| 138 |
for task in Tasks:
|
| 139 |
-
data_dict[task.value.col_name] =
|
| 140 |
|
| 141 |
return data_dict
|
| 142 |
|
|
@@ -185,6 +204,8 @@ def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResu
|
|
| 185 |
for model_result_filepath in model_result_filepaths:
|
| 186 |
# Creation of result
|
| 187 |
eval_result = EvalResult.init_from_json_file(model_result_filepath)
|
|
|
|
|
|
|
| 188 |
eval_result.update_with_request_file(requests_path)
|
| 189 |
|
| 190 |
# Store results of same eval together
|
|
@@ -201,5 +222,7 @@ def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResu
|
|
| 201 |
results.append(v)
|
| 202 |
except KeyError: # not all eval values present
|
| 203 |
continue
|
|
|
|
|
|
|
| 204 |
|
| 205 |
return results
|
|
|
|
| 31 |
num_params: int = 0
|
| 32 |
date: str = "" # submission date of request file
|
| 33 |
still_on_hub: bool = False
|
| 34 |
+
regions: dict = None
|
| 35 |
|
| 36 |
@classmethod
|
| 37 |
def init_from_json_file(self, json_filepath):
|
|
|
|
| 40 |
data = json.load(fp)
|
| 41 |
|
| 42 |
config = data.get("config")
|
| 43 |
+
regions = data.get("regions", {}) # Parse regions from JSON
|
| 44 |
|
| 45 |
# Precision
|
| 46 |
precision = Precision.from_str(config.get("model_dtype"))
|
|
|
|
| 80 |
|
| 81 |
mean_acc = np.mean(accs) * 100.0
|
| 82 |
results[task.benchmark] = mean_acc
|
| 83 |
+
|
| 84 |
+
regions_processed_results = {}
|
| 85 |
+
for region, region_results in regions.items():
|
| 86 |
+
processed = {}
|
| 87 |
+
for task in Tasks:
|
| 88 |
+
task = task.value
|
| 89 |
+
|
| 90 |
+
# We average all scores of a given metric (not all metrics are present in all files)
|
| 91 |
+
accs = np.array([v.get(task.metric, None) for k, v in region_results.items() if task.benchmark == k])
|
| 92 |
+
if accs.size == 0 or any([acc is None for acc in accs]):
|
| 93 |
+
continue
|
| 94 |
+
|
| 95 |
+
mean_acc = np.mean(accs) * 100.0
|
| 96 |
+
processed[task.benchmark] = mean_acc
|
| 97 |
+
regions_processed_results[region] = processed
|
| 98 |
return self(
|
| 99 |
eval_name=result_key,
|
| 100 |
full_model=full_model,
|
|
|
|
| 104 |
precision=precision,
|
| 105 |
revision= config.get("model_sha", ""),
|
| 106 |
still_on_hub=still_on_hub,
|
| 107 |
+
architecture=architecture,
|
| 108 |
+
regions=regions_processed_results
|
| 109 |
)
|
| 110 |
|
| 111 |
def update_with_request_file(self, requests_path):
|
|
|
|
| 124 |
except Exception:
|
| 125 |
print(f"Could not find request file for {self.org}/{self.model} with precision {self.precision.value.name}")
|
| 126 |
|
| 127 |
+
def to_dict(self, region=None):
|
| 128 |
"""Converts the Eval Result to a dict compatible with our dataframe display"""
|
| 129 |
# print(self.results)
|
| 130 |
+
results = self.results if region is None else self.regions.get(region, {})
|
| 131 |
acc_values = [
|
| 132 |
+
results[task.value.benchmark]
|
| 133 |
for task in Tasks
|
| 134 |
+
if task.value.metric == "acc" and task.value.benchmark in results
|
| 135 |
]
|
| 136 |
# print(acc_values)
|
| 137 |
|
|
|
|
| 155 |
}
|
| 156 |
|
| 157 |
for task in Tasks:
|
| 158 |
+
data_dict[task.value.col_name] = results[task.value.benchmark]
|
| 159 |
|
| 160 |
return data_dict
|
| 161 |
|
|
|
|
| 204 |
for model_result_filepath in model_result_filepaths:
|
| 205 |
# Creation of result
|
| 206 |
eval_result = EvalResult.init_from_json_file(model_result_filepath)
|
| 207 |
+
print('testing this one')
|
| 208 |
+
print(eval_result)
|
| 209 |
eval_result.update_with_request_file(requests_path)
|
| 210 |
|
| 211 |
# Store results of same eval together
|
|
|
|
| 222 |
results.append(v)
|
| 223 |
except KeyError: # not all eval values present
|
| 224 |
continue
|
| 225 |
+
print('results')
|
| 226 |
+
print(results)
|
| 227 |
|
| 228 |
return results
|
src/populate.py
CHANGED
|
@@ -8,17 +8,21 @@ from src.display.utils import AutoEvalColumn, EvalQueueColumn
|
|
| 8 |
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 |
"""Creates a dataframe from all the individual experiment results"""
|
| 13 |
raw_data = get_raw_eval_results(results_path, requests_path)
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
df = pd.DataFrame.from_records(all_data_json)
|
|
|
|
| 17 |
df = df.sort_values(by=[AutoEvalColumn.average.name], ascending=False)
|
| 18 |
df = df[cols].round(decimals=2)
|
| 19 |
-
|
| 20 |
# filter out if any of the benchmarks have not been produced
|
| 21 |
df = df[has_no_nan_values(df, benchmark_cols)]
|
|
|
|
| 22 |
return df
|
| 23 |
|
| 24 |
|
|
|
|
| 8 |
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, region=None) -> pd.DataFrame:
|
| 12 |
"""Creates a dataframe from all the individual experiment results"""
|
| 13 |
raw_data = get_raw_eval_results(results_path, requests_path)
|
| 14 |
+
# this here if region is none gets main results. I have to pass region value here to get region based results
|
| 15 |
+
# and they should come.
|
| 16 |
+
all_data_json = [v.to_dict(region) for v in raw_data]
|
| 17 |
+
print('all_data_json', all_data_json)
|
| 18 |
df = pd.DataFrame.from_records(all_data_json)
|
| 19 |
+
print('df', df)
|
| 20 |
df = df.sort_values(by=[AutoEvalColumn.average.name], ascending=False)
|
| 21 |
df = df[cols].round(decimals=2)
|
| 22 |
+
print('df after sorting', df)
|
| 23 |
# filter out if any of the benchmarks have not been produced
|
| 24 |
df = df[has_no_nan_values(df, benchmark_cols)]
|
| 25 |
+
print('df after filtering', df)
|
| 26 |
return df
|
| 27 |
|
| 28 |
|