-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark.py
130 lines (109 loc) · 3.26 KB
/
benchmark.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import argparse
import os
from time import perf_counter
import subprocess
from typing import List, Dict
import pandas as pd
import seaborn as sns
COMMANDS: Dict[str, List[str]] = {
"docker-cpu": ["docker", "buildx", "build", "-f", "Dockerfile", "."],
"docker-gpu": ["docker", "buildx", "build", "-f", "gpu.Dockerfile", "."],
"envd-v0-cpu": [
"envd",
"build",
"-f",
"v0.envd:build",
"--output",
"type=image,name=docker.io/tensorchord/python-cpu-v0",
],
"envd-v0-gpu": [
"envd",
"build",
"-f",
"v0.envd:gpu_build",
"--output",
"type=image,name=docker.io/tensorchord/python-gpu-v0",
],
"envd-v1-cpu": [
"envd",
"build",
"-f",
"v1.envd:build",
"--output",
"type=image,name=docker.io/tensorchord/python-cpu-v1",
],
"envd-v1-gpu": [
"envd",
"build",
"-f",
"v1.envd:gpu_build",
"--output",
"type=image,name=docker.io/tensorchord/python-gpu-v1",
],
}
NAMES = list(COMMANDS.keys())
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument("--path", required=True, help="path for the saved data file")
parser.add_argument(
"--github",
default=False,
action="store_true",
help="detect if it's running in the GitHub Actions",
)
args = parser.parse_args()
def envd_version() -> str:
version = subprocess.check_output(
["envd", "version", "--short"], universal_newlines=True
).strip()
ver = version.rsplit(" ", 1)[-1][1:]
return ver
def record(name: str, cmd: List[str]) -> float:
# envd needs to bootstrap the buildkitd
if name.startswith("envd"):
subprocess.call(["envd", "bootstrap"])
t0 = perf_counter()
code = subprocess.call(cmd)
if code != 0:
print("ERROR: ", cmd)
res = float("inf")
else:
res = perf_counter() - t0
# clean cache
if name.startswith("envd"):
subprocess.call(["envd", "prune", "--all"])
else:
subprocess.call(["docker", "buildx", "prune", "--all"])
# GitHub Action has limited disk space
# refer to https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
if os.environ.get("GITHUB_ACTIONS") or args.github:
subprocess.run(
"docker rm -vf $(docker ps -aq) && docker rmi -f $(docker images -aq)",
check=True,
shell=True,
)
return res
def run() -> List[float]:
res = []
for name, cmd in COMMANDS.items():
res.append(record(name, cmd))
print(res)
return res
def render(data: pd.DataFrame):
sns.set_theme(style="whitegrid")
ax = sns.lineplot(
data=data, palette="tab10", linewidth=2.5, markers=True, dashes=False
)
ax.get_figure().savefig("trend.png")
def combine(record: List[float], path: str) -> pd.DataFrame:
old = pd.DataFrame(columns=NAMES)
if os.path.isfile(path):
old = pd.read_csv(path)
data = pd.concat(
[old, pd.DataFrame([record], columns=NAMES)], ignore_index=True, sort=False
)
data.to_csv(path, index=False)
return data
if __name__ == "__main__":
res = run()
data = combine(res, args.path)
render(data)