Spaces:
Running
Running
File size: 1,245 Bytes
46f4b10 46ba2c6 0eac02e 46f4b10 0eac02e 46f4b10 46ba2c6 0eac02e 46ba2c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import json
import numpy as np
def estimate_from_measures(measures: list[float], estimator: str) -> float:
if estimator == "median":
return float(np.median(measures))
elif estimator == "mean":
return float(np.mean(measures))
raise ValueError(f"Invalid estimator: {estimator}")
class ModelBenchmarkData:
def __init__(self, json_path: str) -> None:
with open(json_path, "r") as f:
self.data = json.load(f)
def get_ttft_tpot_data(self, estimator: str = "median", use_cuda_time: bool = False) -> dict:
aggregated_data = {"ttft": [], "tpot": [], "label": [], "position": []}
time_key = "cuda_time" if use_cuda_time else "wall_time"
position = 0
for cfg_name, data in self.data.items():
x_measures = [d[time_key] for d in data["ttft"]]
y_measures = [d[time_key] for d in data["tpot"]]
aggregated_data["ttft"].append(estimate_from_measures(x_measures, estimator))
aggregated_data["tpot"].append(estimate_from_measures(y_measures, estimator))
aggregated_data["label"].append(cfg_name)
aggregated_data["position"].append(position)
position += 1
return aggregated_data
|