File size: 955 Bytes
e3571c1
 
9fd9223
e3571c1
 
 
 
 
 
 
 
 
 
176e245
 
e3571c1
 
9fd9223
e3571c1
 
9fd9223
 
 
 
 
 
e3571c1
 
 
 
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
import os
import csv
from glob import glob

import tyro
import pandas as pd


def main(data_dir: str, out_file: str) -> None:
    """Compute metrics for all models in the given directory."""
    model_names = os.listdir(data_dir)
    print(f"{model_names=}")

    if dirname := os.path.dirname(out_file):
        os.makedirs(dirname, exist_ok=True)
    out_csv = csv.writer(open(out_file, "w", newline=""))
    metrics = ["throughput", "response_length", "latency", "energy"]
    out_csv.writerow(["model", "batch_size"] + metrics)

    for model_name in model_names:
        for benchmark_file in glob(f"{data_dir}/{model_name}/benchmark_batch_*.json"):
            batch_size = int(benchmark_file.split("_")[-1][:-5])
            df = pd.read_json(benchmark_file)
            out_csv.writerow(
                [model_name.replace("--", "/"), str(batch_size)] + df[metrics].mean().to_list(),
            )


if __name__ == "__main__":
    tyro.cli(main)