# SPDX-License-Identifier: Apache-2.0 import os import sys from html import escape from datetime import datetime import plotly.express as px import pandas as pd try: from fastvideo.performance.hf_store import load_as_dataframe, sync_from_hf except ImportError: repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")) if repo_root not in sys.path: sys.path.insert(0, repo_root) from fastvideo.performance.hf_store import load_as_dataframe, sync_from_hf TRACKING_ROOT = os.environ.get( "PERFORMANCE_TRACKING_ROOT", "/tmp/perf-tracking", ) PERF_REPORTS_DIR = os.environ.get("PERF_REPORTS_DIR", "/root/data/perf_reports") METRICS = ( "latency", "throughput", "memory", "text_encoder_time_s", "dit_time_s", "vae_decode_time_s", ) # ----------------------------- # 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) -> tuple[list, list[dict[str, object]]]: figs = [] skipped_metrics: list[dict[str, object]] = [] 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 METRICS: if metric not in g.columns: skipped_metrics.append({ "model_id": model_id, "gpu_type": gpu_type, "metric": metric, "reason": "column missing from loaded records", "records": len(g), "non_null": 0, }) continue non_null = int(g[metric].notna().sum()) if non_null == 0: skipped_metrics.append({ "model_id": model_id, "gpu_type": gpu_type, "metric": metric, "reason": "no non-null values in loaded records", "records": len(g), "non_null": non_null, }) 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, skipped_metrics def render_skipped_metrics(skipped_metrics: list[dict[str, object]]) -> str: if not skipped_metrics: return "" rows = [ "
| Model | GPU | Metric | " "Records | Non-null | Reason |
|---|---|---|---|---|---|
| {escape(str(item['model_id']))} | " f"{escape(str(item['gpu_type']))} | " f"{escape(str(item['metric']))} | " f"{item['records']} | " f"{item['non_null']} | " f"{escape(str(item['reason']))} | " "