main
py 64 lines 1.96 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import math
5 import pickle
6 from collections import defaultdict
7
8 import matplotlib.pyplot as plt
9 import pandas as pd
10 import regex as re
11 import seaborn as sns
12 from torch.utils.benchmark import Measurement as TMeasurement
13
14 from vllm.utils.argparse_utils import FlexibleArgumentParser
15
16 if __name__ == "__main__":
17 parser = FlexibleArgumentParser(
18 description="Benchmark the latency of processing a single batch of "
19 "requests till completion."
20 )
21 parser.add_argument("filename", type=str)
22
23 args = parser.parse_args()
24
25 with open(args.filename, "rb") as f:
26 data = pickle.load(f)
27 raw_results: list[TMeasurement] = data["results"]
28
29 results = defaultdict(lambda: list())
30 for v in raw_results:
31 result = re.search(r"MKN=\(\d+x(\d+x\d+)\)", v.task_spec.sub_label)
32 if result is not None:
33 KN = result.group(1)
34 else:
35 raise Exception("MKN not found")
36 result = re.search(r"MKN=\((\d+)x\d+x\d+\)", v.task_spec.sub_label)
37 if result is not None:
38 M = result.group(1)
39 else:
40 raise Exception("MKN not found")
41
42 kernel = v.task_spec.description
43 results[KN].append({"kernel": kernel, "batch_size": M, "median": v.median})
44
45 rows = int(math.ceil(len(results) / 2))
46 fig, axs = plt.subplots(rows, 2, figsize=(12, 5 * rows))
47 axs = axs.flatten()
48 for axs_idx, (shape, data) in enumerate(results.items()):
49 plt.sca(axs[axs_idx])
50 df = pd.DataFrame(data)
51 sns.lineplot(
52 data=df,
53 x="batch_size",
54 y="median",
55 hue="kernel",
56 style="kernel",
57 markers=True,
58 dashes=False,
59 palette="Dark2",
60 )
61 plt.title(f"Shape: {shape}")
62 plt.ylabel("time (median, s)")
63 plt.tight_layout()
64 plt.savefig("graph_machete_bench.pdf")