Skip to content

Commit e7ef74e

Browse files
authored
Fix some issues with benchmark data output (#13641)
Signed-off-by: Huy Do <[email protected]>
1 parent cbae7af commit e7ef74e

File tree

7 files changed

+61
-16
lines changed

7 files changed

+61
-16
lines changed

.buildkite/nightly-benchmarks/scripts/convert-results-json-to-markdown.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ def results_to_json(latency, throughput, serving):
8484
# this result is generated via `benchmark_serving.py`
8585

8686
# attach the benchmarking command to raw_result
87-
with open(test_file.with_suffix(".commands")) as f:
88-
command = json.loads(f.read())
87+
try:
88+
with open(test_file.with_suffix(".commands")) as f:
89+
command = json.loads(f.read())
90+
except OSError as e:
91+
print(e)
92+
continue
93+
8994
raw_result.update(command)
9095

9196
# update the test name of this result
@@ -99,8 +104,13 @@ def results_to_json(latency, throughput, serving):
99104
# this result is generated via `benchmark_latency.py`
100105

101106
# attach the benchmarking command to raw_result
102-
with open(test_file.with_suffix(".commands")) as f:
103-
command = json.loads(f.read())
107+
try:
108+
with open(test_file.with_suffix(".commands")) as f:
109+
command = json.loads(f.read())
110+
except OSError as e:
111+
print(e)
112+
continue
113+
104114
raw_result.update(command)
105115

106116
# update the test name of this result
@@ -121,8 +131,13 @@ def results_to_json(latency, throughput, serving):
121131
# this result is generated via `benchmark_throughput.py`
122132

123133
# attach the benchmarking command to raw_result
124-
with open(test_file.with_suffix(".commands")) as f:
125-
command = json.loads(f.read())
134+
try:
135+
with open(test_file.with_suffix(".commands")) as f:
136+
command = json.loads(f.read())
137+
except OSError as e:
138+
print(e)
139+
continue
140+
126141
raw_result.update(command)
127142

128143
# update the test name of this result

.buildkite/nightly-benchmarks/scripts/run-performance-benchmarks.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,14 @@ run_serving_tests() {
309309

310310
new_test_name=$test_name"_qps_"$qps
311311

312+
# pass the tensor parallel size to the client so that it can be displayed
313+
# on the benchmark dashboard
312314
client_command="python3 benchmark_serving.py \
313315
--save-result \
314316
--result-dir $RESULTS_FOLDER \
315317
--result-filename ${new_test_name}.json \
316318
--request-rate $qps \
319+
--metadata "tensor_parallel_size=$tp" \
317320
$client_args"
318321

319322
echo "Running test case $test_name with qps $qps"

.buildkite/nightly-benchmarks/tests/throughput-tests.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
"backend": "vllm"
3333
}
3434
}
35-
]
35+
]

benchmarks/benchmark_latency.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import numpy as np
1313
import torch
14-
from benchmark_utils import convert_to_pytorch_benchmark_format
14+
from benchmark_utils import convert_to_pytorch_benchmark_format, write_to_json
1515
from tqdm import tqdm
1616

1717
from vllm import LLM, SamplingParams
@@ -30,8 +30,7 @@ def save_to_pytorch_benchmark_format(args: argparse.Namespace,
3030
for k in ["avg_latency", "percentiles"]})
3131
if pt_records:
3232
pt_file = f"{os.path.splitext(args.output_json)[0]}.pytorch.json"
33-
with open(pt_file, "w") as f:
34-
json.dump(pt_records, f)
33+
write_to_json(pt_file, pt_records)
3534

3635

3736
def main(args: argparse.Namespace):

benchmarks/benchmark_serving.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
except ImportError:
5757
from argparse import ArgumentParser as FlexibleArgumentParser
5858

59-
from benchmark_utils import convert_to_pytorch_benchmark_format
59+
from benchmark_utils import convert_to_pytorch_benchmark_format, write_to_json
6060

6161
MILLISECONDS_TO_SECONDS_CONVERSION = 1000
6262

@@ -841,8 +841,7 @@ def save_to_pytorch_benchmark_format(args: argparse.Namespace,
841841
if pt_records:
842842
# Don't use json suffix here as we don't want CI to pick it up
843843
pt_file = f"{os.path.splitext(file_name)[0]}.pytorch.json"
844-
with open(pt_file, "w") as f:
845-
json.dump(pt_records, f)
844+
write_to_json(pt_file, pt_records)
846845

847846

848847
def main(args: argparse.Namespace):

benchmarks/benchmark_throughput.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import torch
1313
import uvloop
14-
from benchmark_utils import convert_to_pytorch_benchmark_format
14+
from benchmark_utils import convert_to_pytorch_benchmark_format, write_to_json
1515
from PIL import Image
1616
from tqdm import tqdm
1717
from transformers import (AutoModelForCausalLM, AutoTokenizer,
@@ -366,8 +366,7 @@ def save_to_pytorch_benchmark_format(args: argparse.Namespace,
366366
if pt_records:
367367
# Don't use json suffix here as we don't want CI to pick it up
368368
pt_file = f"{os.path.splitext(args.output_json)[0]}.pytorch.json"
369-
with open(pt_file, "w") as f:
370-
json.dump(pt_records, f)
369+
write_to_json(pt_file, pt_records)
371370

372371

373372
def main(args: argparse.Namespace):

benchmarks/benchmark_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
import argparse
4+
import json
5+
import math
46
import os
57
from typing import Any, Dict, List
68

@@ -34,6 +36,34 @@ def convert_to_pytorch_benchmark_format(args: argparse.Namespace,
3436
"extra_info": extra_info,
3537
},
3638
}
39+
40+
tp = record["benchmark"]["extra_info"]["args"].get(
41+
"tensor_parallel_size")
42+
# Save tensor_parallel_size parameter if it's part of the metadata
43+
if not tp and "tensor_parallel_size" in extra_info:
44+
record["benchmark"]["extra_info"]["args"][
45+
"tensor_parallel_size"] = extra_info["tensor_parallel_size"]
46+
3747
records.append(record)
3848

3949
return records
50+
51+
52+
class InfEncoder(json.JSONEncoder):
53+
54+
def clear_inf(self, o: Any):
55+
if isinstance(o, dict):
56+
return {k: self.clear_inf(v) for k, v in o.items()}
57+
elif isinstance(o, list):
58+
return [self.clear_inf(v) for v in o]
59+
elif isinstance(o, float) and math.isinf(o):
60+
return "inf"
61+
return o
62+
63+
def iterencode(self, o: Any, *args, **kwargs) -> Any:
64+
return super().iterencode(self.clear_inf(o), *args, **kwargs)
65+
66+
67+
def write_to_json(filename: str, records: List) -> None:
68+
with open(filename, "w") as f:
69+
json.dump(records, f, cls=InfEncoder)

0 commit comments

Comments
 (0)