# SPDX-License-Identifier: Apache-2.0 import os from datetime import datetime import plotly.express as px import pandas as pd from hf_store import sync_from_hf, load_as_dataframe # ----------------------------- # 1. Grouping # ----------------------------- def group_data(df: pd.DataFrame): # Group only by model+GPU so each group produces a time-series line. # config_id (commit SHA) is carried as a column for hover/color use. keys = ["model_id", "gpu_type"] return df.groupby(keys, dropna=False) # ----------------------------- # 2. Plot builder # ----------------------------- def build_plots(df: pd.DataFrame) -> list: figs = [] for (model_id, gpu_type), g in group_data(df): g = g.sort_values("timestamp") # One chart per metric so the y-axes aren't on wildly different scales for metric in ("latency", "throughput", "memory"): if g[metric].isna().all(): continue fig = px.line( g, x="timestamp", y=metric, markers=True, hover_data=["config_id", "commit_sha"], title=f"{model_id} | {gpu_type} | {metric}", labels={"timestamp": "Time", metric: metric}, ) figs.append(fig) return figs # ----------------------------- # 3. Render HTML dashboard # ----------------------------- def render_html(figs: list, days: int) -> str: html_parts = [ "", "
", "", "", f"