Spaces:
Runtime error
Runtime error
Clémentine commited on
Commit ·
ceb2102
1
Parent(s): 76a47ce
Refactor 2 - added plotting back
Browse filesOnly takes into account last submissions, but we have no way to go back at eval date apart from loading info from git commit of results files.
Also updated speed with gradio concurrency limit param
Files changed (7)
30 unmodified lines3132333434353638373839404142454344458 unmodified lines5455566057585960646566616263642 unmodified lines67686975767778798081828384707172159 unmodified lines2322332342352362372388 unmodified lines2472482492502512522538 unmodified lines2622632642652662672688 unmodified lines2772782792802812822838 unmodified lines2922932942952962972988 unmodified lines30730830931031131232232332432532632732832933033133233333433533633733833934031331431531631731831932032132232332432532632732832933033196 unmodified lines42842943044344444544644744844945043143243330 unmodified linesfrom src.submission.submit import add_new_evalfrom src.tools.collections import update_collectionsfrom src.tools.plots import ( HUMAN_BASELINES, create_metric_plot_obj, create_plot_df, create_scores_df, join_model_info_with_results,)
def restart_space(): API.restart_space(repo_id=REPO_ID, token=H4_TOKEN)
try: snapshot_download( repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=308 unmodified lines restart_space()
original_df = get_leaderboard_df(EVAL_RESULTS_PATH, COLS, BENCHMARK_COLS)raw_data, original_df = get_leaderboard_df(EVAL_RESULTS_PATH, COLS, BENCHMARK_COLS)update_collections(original_df.copy())leaderboard_df = original_df.copy()
# models = original_df["model_name_for_query"].tolist() # needed for model backlinks in their to the leaderboard# plot_df = create_plot_df(create_scores_df(join_model_info_with_results(original_df)))# to_be_dumped = f"models = {repr(models)}\n"plot_df = create_plot_df(create_scores_df(raw_data))
( finished_eval_queue_df,2 unmodified lines) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
# Basics#def change_tab(query_param: str):# query_param = query_param.replace("'", '"')# query_param = json.loads(query_param)# if isinstance(query_param, dict) and "tab" in query_param and query_param["tab"] == "evaluation":# return gr.Tabs.update(selected=1)# else:# return gr.Tabs.update(selected=0)
# Searching and filteringdef update_table( hidden_df: pd.DataFrame,159 unmodified lines search_bar, ], leaderboard_table, concurrency_limit=None, ) shown_columns.change( update_table,8 unmodified lines ], leaderboard_table, queue=True, concurrency_limit=None, ) filter_columns_type.change( update_table,8 unmodified lines ], leaderboard_table, queue=True, concurrency_limit=None, ) filter_columns_precision.change( update_table,8 unmodified lines ], leaderboard_table, queue=True, concurrency_limit=None, ) filter_columns_size.change( update_table,8 unmodified lines ], leaderboard_table, queue=True, concurrency_limit=None, ) deleted_models_visibility.change( update_table,8 unmodified lines ], leaderboard_table, queue=True, concurrency_limit=None, )
# with gr.TabItem("📈 # evolution through time", elem_id="llm-benchmark-tab-table", id=4): # with gr.Row(): # with gr.Column(): # chart = create_metric_plot_obj( # plot_df, # ["Average ⬆️"], # HUMAN_BASELINES, # title="Average of Top Scores and Human Baseline Over Time", # ) # gr.Plot(value=chart, interactive=False, width=500, height=500) # with gr.Column(): # chart = create_metric_plot_obj( # plot_df, # ["ARC", "HellaSwag", "MMLU", "TruthfulQA", "Winogrande", "GSM8K", "DROP"], # HUMAN_BASELINES, # title="Top Scores and Human Baseline Over Time", # ) # gr.Plot(value=chart, interactive=False, width=500, height=500) with gr.TabItem("📈 Metrics through time", elem_id="llm-benchmark-tab-table", id=4): with gr.Row(): with gr.Column(): chart = create_metric_plot_obj( plot_df, [AutoEvalColumn.average.name], title="Average of Top Scores and Human Baseline Over Time (from last update)", ) gr.Plot(value=chart, min_width=500) with gr.Column(): chart = create_metric_plot_obj( plot_df, BENCHMARK_COLS, title="Top Scores and Human Baseline Over Time (from last update)", ) gr.Plot(value=chart, min_width=500) with gr.TabItem("📝 About", elem_id="llm-benchmark-tab-table", id=2): gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
96 unmodified lines show_copy_button=True, )
#dummy = gr.Textbox(visible=False) #demo.load( # change_tab, # dummy, # tabs, # js=get_window_url_params, #)
scheduler = BackgroundScheduler()scheduler.add_job(restart_space, "interval", seconds=1800)scheduler.start()123456789import osfrom datetime import datetime, timezone
from huggingface_hub import HfApifrom huggingface_hub.hf_api import ModelInfo
API = HfApi()
59 unmodified lines60616263636465665 unmodified lines7273747576777879808182838485868788899091929394959697989910077101102103104105106838485868710710810911011111211311437 unmodified lines15215315413115515615715859 unmodified lines AutoEvalColumn.model.name: "<p>Baseline</p>", AutoEvalColumn.revision.name: "N/A", AutoEvalColumn.precision.name: None, AutoEvalColumn.average.name: 25.0, AutoEvalColumn.average.name: 31.0, AutoEvalColumn.arc.name: 25.0, AutoEvalColumn.hellaswag.name: 25.0, AutoEvalColumn.mmlu.name: 25.0,5 unmodified lines AutoEvalColumn.model_type.name: "",}
# Average ⬆️ human baseline is 0.897 (source: averaging human baselines below)# ARC human baseline is 0.80 (source: https://lab42.global/arc/)# HellaSwag human baseline is 0.95 (source: https://deepgram.com/learn/hellaswag-llm-benchmark-guide)# MMLU human baseline is 0.898 (source: https://openreview.net/forum?id=d7KBjmI3GmQ)# TruthfulQA human baseline is 0.94(source: https://arxiv.org/pdf/2109.07958.pdf)# Drop: https://leaderboard.allenai.org/drop/submissions/public# Winogrande: https://leaderboard.allenai.org/winogrande/submissions/public# GSM8K: paper# Define the human baselineshuman_baseline_row = { AutoEvalColumn.model.name: "<p>Human performance</p>", AutoEvalColumn.revision.name: "N/A", AutoEvalColumn.precision.name: None, AutoEvalColumn.average.name: 92.75, AutoEvalColumn.arc.name: 80.0, AutoEvalColumn.hellaswag.name: 95.0, AutoEvalColumn.mmlu.name: 89.8, AutoEvalColumn.truthfulqa.name: 94.0, AutoEvalColumn.winogrande.name: 94.0, AutoEvalColumn.gsm8k.name: 100, AutoEvalColumn.drop.name: 96.42, AutoEvalColumn.dummy.name: "human_baseline", AutoEvalColumn.model_type.name: "",}
@dataclassclass ModelInfo:class ModelTypeDetails: name: str symbol: str # emoji
class ModelType(Enum): PT = ModelInfo(name="pretrained", symbol="🟢") FT = ModelInfo(name="fine-tuned", symbol="🔶") IFT = ModelInfo(name="instruction-tuned", symbol="⭕") RL = ModelInfo(name="RL-tuned", symbol="🟦") Unknown = ModelInfo(name="", symbol="?") PT = ModelTypeDetails(name="pretrained", symbol="🟢") FT = ModelTypeDetails(name="fine-tuned", symbol="🔶") IFT = ModelTypeDetails(name="instruction-tuned", symbol="⭕") RL = ModelTypeDetails(name="RL-tuned", symbol="🟦") Unknown = ModelTypeDetails(name="", symbol="?")
def to_str(self, separator=" "): return f"{self.value.symbol}{separator}{self.value.name}"37 unmodified linesEVAL_COLS = [c.name for c in fields(EvalQueueColumn)]EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
BENCHMARK_COLS = [t.value.col_name for t in Tasks if t.value.col_name in fields(AutoEvalColumn)]BENCHMARK_COLS = [t.value.col_name for t in Tasks]
NUMERIC_INTERVALS = { "?": pd.Interval(-1, 0, closed="right"),2 unmodified lines34566789101149 unmodified lines616263646564656631 unmodified lines98991001031011021037 unmodified lines11111211311411511611742 unmodified lines16016116216516316416516627 unmodified lines1941951961971991981992002012 unmodified linesimport mathimport osfrom dataclasses import dataclassfrom typing import Dict, List, Tuple
import dateutilfrom datetime import datetimeimport numpy as np
from src.display.formatting import make_clickable_model49 unmodified lines still_on_hub, error = is_model_on_hub( full_model, config.get("model_sha", "main"), trust_remote_code=True ) if not still_on_hub: print(full_model, error)
# Extract results available in this file (some results are split in several files) results = {}31 unmodified lines results=results, precision=precision, # todo model_type=, weight_type= revision=config.get("model_sha", ""), date=config.get("submission_date", ""), still_on_hub=still_on_hub, )
7 unmodified lines self.license = request.get("license", "?") self.likes = request.get("likes", 0) self.num_params = request.get("params", 0) self.date = request.get("submitted_time", "") except Exception: print(f"Could not find request file for {self.org}/{self.model}")
42 unmodified lines return request_file
def get_eval_results(results_path: str) -> List[EvalResult]:def get_raw_eval_results(results_path: str) -> list[EvalResult]: json_filepaths = []
for root, _, files in os.walk(results_path):27 unmodified lines results = [] for v in eval_results.values(): try: v.to_dict() # we test if the dict version is complete results.append(v.to_dict()) results.append(v) except KeyError: # not all eval values present continue
5 unmodified lines6789910111213141513141516171718192021222323242526275 unmodified linesfrom src.display.formatting import has_no_nan_values, make_clickable_modelfrom src.display.utils import AutoEvalColumn, EvalQueueColumn, baseline_rowfrom src.leaderboard.filter_models import filter_modelsfrom src.leaderboard.read_evals import get_eval_resultsfrom src.leaderboard.read_evals import get_raw_eval_results
def get_leaderboard_df(results_path: str, cols: list, benchmark_cols: list) -> pd.DataFrame: all_data = get_eval_results(results_path) all_data.append(baseline_row) filter_models(all_data) raw_data = get_raw_eval_results(results_path) all_data_json = [v.to_dict() for v in raw_data] all_data_json.append(baseline_row) filter_models(all_data_json)
df = pd.DataFrame.from_records(all_data) df = pd.DataFrame.from_records(all_data_json) df = df.sort_values(by=[AutoEvalColumn.average.name], ascending=False) df = df[cols].round(decimals=2)
# filter out if any of the benchmarks have not been produced df = df[has_no_nan_values(df, benchmark_cols)] return df return raw_data, df
def get_evaluation_queue_df(save_path: str, cols: list) -> list[pd.DataFrame]:54 unmodified lines555657585859606154 unmodified lines size_pattern = size_pattern = re.compile(r"(\d\.)?\d+(b|m)") try: model_size = round(model_info.safetensors["total"] / 1e9, 3) except (AttributeError, TypeError): except (AttributeError, TypeError ): try: size_match = re.search(size_pattern, model_info.modelId.lower()) model_size = size_match.group(0)123412345678911121314151617181920212223242526272829303132333435361011394041424312134546474849505152535455565758596061626364656667686970717214157475767778798016171882838419202122232487888990919293949525262798991001011021032829303132333435105106107108109361111123738394041424344454647484950515253541155556575811959606112212312462636465129130131132666768697071727313813914014114214314474757677787980150818283842 unmodified lines87888915916090919293949516796979817099100101102103175176177104105106107179108109110111import picklefrom datetime import datetime, timezonefrom typing import Any, Dict, List, Tuple
import pandas as pdimport numpy as npimport plotly.express as pxfrom plotly.graph_objs import Figure
from src.leaderboard.filter_models import FLAGGED_MODELSfrom src.display.utils import human_baseline_row as HUMAN_BASELINE, AutoEvalColumn, Tasks, Task, BENCHMARK_COLSfrom src.leaderboard.read_evals import EvalResult
# Average ⬆️ human baseline is 0.897 (source: averaging human baselines below)# ARC human baseline is 0.80 (source: https://lab42.global/arc/)# HellaSwag human baseline is 0.95 (source: https://deepgram.com/learn/hellaswag-llm-benchmark-guide)# MMLU human baseline is 0.898 (source: https://openreview.net/forum?id=d7KBjmI3GmQ)# TruthfulQA human baseline is 0.94(source: https://arxiv.org/pdf/2109.07958.pdf)# Define the human baselinesHUMAN_BASELINES = { "Average ⬆️": 0.897 * 100, "ARC": 0.80 * 100, "HellaSwag": 0.95 * 100, "MMLU": 0.898 * 100, "TruthfulQA": 0.94 * 100,}
def to_datetime(model_info: Tuple[str, Any]) -> datetime: """ Converts the lastModified attribute of the object to datetime.
:param model_info: A tuple containing the name and object. The object must have a lastModified attribute with a string representing the date and time. :return: A datetime object converted from the lastModified attribute of the input object. """ name, obj = model_info return datetime.strptime(obj.lastModified, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
def join_model_info_with_results(results_df: pd.DataFrame) -> pd.DataFrame: """ Integrates model information with the results DataFrame by matching 'Model sha'. :param results_df: A DataFrame containing results information including 'Model sha' column. :return: A DataFrame with updated 'Results Date' columns, which are synchronized with model information.def create_scores_df(raw_data: list[EvalResult]) -> pd.DataFrame: """ # copy dataframe to avoid modifying the original df = results_df.copy(deep=True)
# Filter out FLAGGED_MODELS to ensure graph is not skewed by mistakes df = df[~df["model_name_for_query"].isin(FLAGGED_MODELS.keys())].reset_index(drop=True)
# load cache from disk try: with open("model_info_cache.pkl", "rb") as f: model_info_cache = pickle.load(f) except (EOFError, FileNotFoundError): model_info_cache = {}
# Sort date strings using datetime objects as keys sorted_dates = sorted(list(model_info_cache.items()), key=to_datetime, reverse=True) df["Results Date"] = datetime.now().replace(tzinfo=timezone.utc)
# Define the date format string date_format = "%Y-%m-%dT%H:%M:%S.%fZ"
# Iterate over sorted_dates and update the dataframe for name, obj in sorted_dates: # Convert the lastModified string to a datetime object last_modified_datetime = datetime.strptime(obj.lastModified, date_format).replace(tzinfo=timezone.utc)
# Update the "Results Date" column where "Model sha" equals obj.sha df.loc[df["Model sha"] == obj.sha, "Results Date"] = last_modified_datetime return df Generates a DataFrame containing the maximum scores until each date.
def create_scores_df(results_df: pd.DataFrame) -> pd.DataFrame: """ Generates a DataFrame containing the maximum scores until each result date.
:param results_df: A DataFrame containing result information including metric scores and result dates. :return: A new DataFrame containing the maximum scores until each result date for every metric. :param results_df: A DataFrame containing result information including metric scores and dates. :return: A new DataFrame containing the maximum scores until each date for every metric. """ # Step 1: Ensure 'Results Date' is in datetime format and sort the DataFrame by it results_df["Results Date"] = pd.to_datetime(results_df["Results Date"]) results_df.sort_values(by="Results Date", inplace=True) # Step 1: Ensure 'date' is in datetime format and sort the DataFrame by it results_df = pd.DataFrame(raw_data) #results_df["date"] = pd.to_datetime(results_df["date"], format="mixed", utc=True) results_df.sort_values(by="date", inplace=True)
# Step 2: Initialize the scores dictionary scores = { "Average ⬆️": [], "ARC": [], "HellaSwag": [], "MMLU": [], "TruthfulQA": [], "Result Date": [], "Model Name": [], } scores = {k: [] for k in BENCHMARK_COLS + [AutoEvalColumn.average.name]}
# Step 3: Iterate over the rows of the DataFrame and update the scores dictionary for i, row in results_df.iterrows(): date = row["Results Date"] for column in scores.keys(): if column == "Result Date": if not scores[column] or scores[column][-1] <= date: scores[column].append(date) for task in [t.value for t in Tasks] + [Task("Average", "avg", AutoEvalColumn.average.name)]: current_max = 0 last_date = "" column = task.col_name for _, row in results_df.iterrows(): current_model = row["full_model"] if current_model in FLAGGED_MODELS: continue if column == "Model Name": scores[column].append(row["model_name_for_query"]) continue current_max = scores[column][-1] if scores[column] else float("-inf") scores[column].append(max(current_max, row[column]))
# Step 4: Convert the dictionary to a DataFrame return pd.DataFrame(scores) current_date = row["date"] if task.benchmark == "Average": current_score = np.mean(list(row["results"].values())) else: current_score = row["results"][task.benchmark]
if current_score > current_max: if current_date == last_date and len(scores[column]) > 0: scores[column][-1] = {"model": current_model, "date": current_date, "score": current_score} else: scores[column].append({"model": current_model, "date": current_date, "score": current_score}) current_max = current_score last_date = current_date
# Step 4: Return all dictionaries as DataFrames return {k: pd.DataFrame(v) for k, v in scores.items()}
def create_plot_df(scores_df: pd.DataFrame) -> pd.DataFrame:def create_plot_df(scores_df: dict[str: pd.DataFrame]) -> pd.DataFrame: """ Transforms the scores DataFrame into a new format suitable for plotting.
:param scores_df: A DataFrame containing metric scores and result dates. :param scores_df: A DataFrame containing metric scores and dates. :return: A new DataFrame reshaped for plotting purposes. """ # Sample columns cols = ["Average ⬆️", "ARC", "HellaSwag", "MMLU", "TruthfulQA"]
# Initialize the list to store DataFrames dfs = []
# Iterate over the cols and create a new DataFrame for each column for col in cols: d = scores_df[[col, "Model Name", "Result Date"]].copy().reset_index(drop=True) d["Metric Name"] = col d.rename(columns={col: "Metric Value"}, inplace=True) for col in BENCHMARK_COLS + [AutoEvalColumn.average.name]: d = scores_df[col].reset_index(drop=True) d["task"] = col dfs.append(d)
# Concatenate all the created DataFrames concat_df = pd.concat(dfs, ignore_index=True)
# Sort values by 'Result Date' concat_df.sort_values(by="Result Date", inplace=True) concat_df.reset_index(drop=True, inplace=True)
# Drop duplicates based on 'Metric Name' and 'Metric Value' and keep the first (earliest) occurrence concat_df.drop_duplicates(subset=["Metric Name", "Metric Value"], keep="first", inplace=True)
# Sort values by 'date' concat_df.sort_values(by="date", inplace=True) concat_df.reset_index(drop=True, inplace=True) return concat_df
def create_metric_plot_obj( df: pd.DataFrame, metrics: List[str], human_baselines: Dict[str, float], title: str df: pd.DataFrame, metrics: list[str], title: str) -> Figure: """ Create a Plotly figure object with lines representing different metrics2 unmodified lines :param df: The DataFrame containing the metric values, names, and dates. :param metrics: A list of strings representing the names of the metrics to be included in the plot. :param human_baselines: A dictionary where keys are metric names and values are human baseline values for the metrics. :param title: A string representing the title of the plot. :return: A Plotly figure object with lines representing metrics and horizontal dotted lines representing human baselines. """
# Filter the DataFrame based on the specified metrics df = df[df["Metric Name"].isin(metrics)] df = df[df["task"].isin(metrics)]
# Filter the human baselines based on the specified metrics filtered_human_baselines = {k: v for k, v in human_baselines.items() if k in metrics} filtered_human_baselines = {k: v for k, v in HUMAN_BASELINE.items() if k in metrics}
# Create a line figure using plotly express with specified markers and custom data fig = px.line( df, x="Result Date", y="Metric Value", color="Metric Name", x="date", y="score", color="task", markers=True, custom_data=["Metric Name", "Metric Value", "Model Name"], custom_data=["task", "score", "model"], title=title, )
app.py+24-44
src/display/formatting.py+3
src/display/utils.py+32-8
src/leaderboard/read_evals.py+5-6
src/populate.py+7-6
src/submission/check_validity.py+1-1
src/tools/plots.py+49-120