-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathupload_benchmark_results.py
executable file
·207 lines (172 loc) · 5.53 KB
/
upload_benchmark_results.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python3
import glob
import gzip
import json
import logging
import os
import platform
import socket
import time
from argparse import Action, ArgumentParser, Namespace
from logging import info, warning
from typing import Any, Dict, List, Optional, Tuple
import boto3
import psutil
import torch
from git import Repo
logging.basicConfig(level=logging.INFO)
REPO = "vllm-project/vllm"
class ValidateDir(Action):
def __call__(
self,
parser: ArgumentParser,
namespace: Namespace,
values: Any,
option_string: Optional[str] = None,
) -> None:
if os.path.isdir(values):
setattr(namespace, self.dest, values)
return
parser.error(f"{values} is not a valid directory")
def parse_args() -> Any:
parser = ArgumentParser("Upload vLLM benchmarks results to S3")
parser.add_argument(
"--vllm",
type=str,
required=True,
action=ValidateDir,
help="the directory that vllm repo is checked out",
)
parser.add_argument(
"--benchmark-results",
type=str,
required=True,
action=ValidateDir,
help="the directory with the benchmark results",
)
parser.add_argument(
"--s3-bucket",
type=str,
required=False,
default="ossci-benchmarks",
help="the S3 bucket to upload the benchmark results",
)
parser.add_argument(
"--device",
type=str,
required=True,
help="the name of the GPU device coming from nvidia-smi or amd-smi",
)
parser.add_argument(
"--dry-run",
action="store_true",
)
return parser.parse_args()
def get_git_metadata(vllm_dir: str) -> Tuple[str, str]:
repo = Repo(vllm_dir)
try:
return repo.active_branch.name, repo.head.object.hexsha
except TypeError:
# This is a detached HEAD, default the branch to main
return "main", repo.head.object.hexsha
def get_benchmark_metadata(head_branch: str, head_sha: str) -> Dict[str, Any]:
timestamp = int(time.time())
return {
"timestamp": timestamp,
"schema_version": "v3",
"name": "vLLM benchmark",
"repo": REPO,
"head_branch": head_branch,
"head_sha": head_sha,
"workflow_id": os.getenv("WORKFLOW_ID", timestamp),
"run_attempt": os.getenv("RUN_ATTEMPT", 1),
"job_id": os.getenv("JOB_ID", timestamp),
}
def get_runner_info() -> Dict[str, Any]:
if torch.cuda.is_available() and torch.version.hip:
name = "rocm"
elif torch.cuda.is_available() and torch.version.cuda:
name = "cuda"
return {
"name": name,
"type": torch.cuda.get_device_name(),
"cpu_info": platform.processor(),
"cpu_count": psutil.cpu_count(),
"avail_mem_in_gb": int(psutil.virtual_memory().total / (1024 * 1024 * 1024)),
"gpu_info": torch.cuda.get_device_name(),
"gpu_count": torch.cuda.device_count(),
"avail_gpu_mem_in_gb": int(
torch.cuda.get_device_properties(0).total_memory / (1024 * 1024 * 1024)
),
"extra_info": {
"hostname": socket.gethostname(),
},
}
def load(benchmark_results: str) -> Dict[str, List]:
results = {}
for file in glob.glob(f"{benchmark_results}/*.json"):
filename = os.path.basename(file)
with open(file) as f:
try:
r = json.load(f)
except json.JSONDecodeError as e:
warning(f"Fail to load {file}: {e}")
continue
if not r:
warning(f"Find no benchmark results in {file}")
continue
if type(r) is not list or "benchmark" not in r[0]:
warning(f"Find no PyToch benchmark results in {file}")
continue
results[filename] = r
return results
def aggregate(
metadata: Dict[str, Any], runner: Dict[str, Any], benchmark_results: Dict[str, List]
) -> List[Dict[str, Any]]:
aggregated_results = []
for _, results in benchmark_results.items():
for result in results:
r: Dict[str, Any] = {**metadata, **result}
r["runners"] = [runner]
aggregated_results.append(r)
return aggregated_results
def upload_to_s3(
s3_bucket: str,
head_branch: str,
head_sha: str,
aggregated_results: List[Dict[str, Any]],
device: str,
dry_run: bool = True,
) -> None:
s3_path = f"v3/{REPO}/{head_branch}/{head_sha}/{device}/benchmark_results.json"
info(f"Upload benchmark results to s3://{s3_bucket}/{s3_path}")
if not dry_run:
# Write in JSONEachRow format
data = "\n".join([json.dumps(r) for r in aggregated_results])
boto3.resource("s3").Object(
f"{s3_bucket}",
f"{s3_path}",
).put(
ACL="public-read",
Body=gzip.compress(data.encode()),
ContentEncoding="gzip",
ContentType="application/json",
)
def main() -> None:
args = parse_args()
head_branch, head_sha = get_git_metadata(args.vllm)
# Gather some information about the benchmark
metadata = get_benchmark_metadata(head_branch, head_sha)
runner = get_runner_info()
# Extract and aggregate the benchmark results
aggregated_results = aggregate(metadata, runner, load(args.benchmark_results))
upload_to_s3(
args.s3_bucket,
head_branch,
head_sha,
aggregated_results,
args.device,
args.dry_run,
)
if __name__ == "__main__":
main()