pytorch
50 строк · 1.8 Кб
1"""
2This file will take the csv outputs from server.py, calculate the mean and
3variance of the warmup_latency, average_latency, throughput and gpu_util
4and write these to the corresponding `results/output_{batch_size}_{compile}.md`
5file, appending to the file if it exists or creatng a new one otherwise.
6"""
7
8import argparse9import os10
11import pandas as pd12
13if __name__ == "__main__":14parser = argparse.ArgumentParser(description="Parse output files")15parser.add_argument("--csv", type=str, help="Path to csv file")16parser.add_argument("--name", type=str, help="Name of experiment")17args = parser.parse_args()18
19input_csv = "./results/" + args.csv20df = pd.read_csv(input_csv)21
22batch_size = int(os.path.basename(args.csv).split("_")[1])23compile = os.path.basename(args.csv).split("_")[-1].split(".")[0]24
25# Calculate mean and standard deviation for a subset of metrics26metrics = ["warmup_latency", "average_latency", "throughput", "gpu_util"]27means = dict()28stds = dict()29
30for metric in metrics:31means[metric] = df[metric].mean()32stds[metric] = df[metric].std()33
34output_md = f"results/output_{batch_size}_{compile}.md"35write_header = os.path.isfile(output_md) is False36
37with open(output_md, "a+") as f:38if write_header:39f.write(f"## Batch Size {batch_size} Compile {compile}\n\n")40f.write(41"| Experiment | Warmup_latency (s) | Average_latency (s) | Throughput (samples/sec) | GPU Utilization (%) |\n"42)43f.write(44"| ---------- | ------------------ | ------------------- | ------------------------ | ------------------- |\n"45)46
47line = f"| {args.name} |"48for metric in metrics:49line += f" {means[metric]:.3f} +/- {stds[metric]:.3f} |"50f.write(line + "\n")51