Skip to content

Commit 9606fb1

Browse files
committed
update benchmark tools
1 parent 832d253 commit 9606fb1

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

benchmarks/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ python -m pip install -r requirements.txt
4141
--metric-percentiles 80,95,99,99.9,99.95,99.99:性能结果中展示的性能指标分位值
4242
--num-prompts 1:总计发送多少条请求
4343
--max-concurrency 1:压测并发数
44-
--save-result:开启结果保存,结果文件会存入json
44+
--save-result:开启结果保存,结果文件会存入json,默认False不保存
45+
--debug:开启debug模式,逐条打印payload和output内容,默认False
46+
--shuffle:是否打乱数据集,默认False不打乱
47+
--seed:打乱数据集时的随机种子,默认0
4548
```
4649

4750
##### /v1/chat/completions接口压测单条数据调试

benchmarks/backend_request_func.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class RequestFuncInput:
5050
multi_modal_content: Optional[dict] = None
5151
ignore_eos: bool = False
5252
language: Optional[str] = None
53+
debug: bool = False
5354

5455

5556
@dataclass
@@ -98,7 +99,8 @@ async def async_request_eb_openai_chat_completions(
9899
if request_func_input.ignore_eos:
99100
payload["ignore_eos"] = request_func_input.ignore_eos
100101

101-
print(f"payload:{json.dumps(payload, ensure_ascii=False)}")
102+
if request_func_input.debug:
103+
print(f"payload:{json.dumps(payload, ensure_ascii=False)}")
102104

103105
headers = {
104106
"Content-Type": "application/json",
@@ -179,7 +181,8 @@ async def async_request_eb_openai_chat_completions(
179181
f.write(str(output) + "\n")
180182
if pbar:
181183
pbar.update(1)
182-
print("#####final_output:", output)
184+
if request_func_input.debug:
185+
print("#####final_output:", output)
183186
return output
184187

185188

@@ -209,7 +212,8 @@ async def async_request_eb_openai_completions(
209212
if request_func_input.ignore_eos:
210213
payload["ignore_eos"] = request_func_input.ignore_eos
211214

212-
print("payload:", json.dumps(payload, ensure_ascii=False))
215+
if request_func_input.debug:
216+
print("payload:", json.dumps(payload, ensure_ascii=False))
213217

214218
headers = {
215219
"Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
@@ -288,7 +292,8 @@ async def async_request_eb_openai_completions(
288292
exc_info = sys.exc_info()
289293
output.error = "".join(traceback.format_exception(*exc_info))
290294

291-
print(f"final_output:{output}")
295+
if request_func_input.debug:
296+
print(f"final_output:{output}")
292297

293298
if pbar:
294299
pbar.update(1)

benchmarks/benchmark_dataset.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(
5757
self,
5858
dataset_path: Optional[str] = None,
5959
random_seed: int = DEFAULT_SEED,
60+
shuffle: bool = False,
6061
hyperparameter_path: Optional[str] = None,
6162
) -> None:
6263
"""
@@ -72,6 +73,7 @@ def __init__(
7273
# default seed.
7374
self.random_seed = random_seed if random_seed is not None else self.DEFAULT_SEED
7475
self.data = None
76+
self.shuffle = shuffle
7577
self.hyperparameter_path = hyperparameter_path
7678
self.hyperparameters = {}
7779

@@ -211,6 +213,10 @@ def load_data(self) -> None:
211213
with open(self.dataset_path, encoding="utf-8") as f:
212214
self.data = [json.loads(i.strip()) for i in f.readlines()]
213215

216+
if self.shuffle:
217+
random.seed(self.random_seed)
218+
random.shuffle(self.data)
219+
214220
def sample(
215221
self,
216222
num_requests: int,
@@ -270,6 +276,10 @@ def load_data(self) -> None:
270276
with open(self.dataset_path, encoding="utf-8") as f:
271277
self.data = [json.loads(i.strip()) for i in f.readlines()]
272278

279+
if self.shuffle:
280+
random.seed(self.random_seed)
281+
random.shuffle(self.data)
282+
273283
def sample(
274284
self,
275285
num_requests: int,

benchmarks/benchmark_serving.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ async def benchmark(
317317
selected_percentile_metrics: list[str],
318318
selected_percentiles: list[float],
319319
ignore_eos: bool,
320+
debug: bool,
320321
goodput_config_dict: dict[str, float],
321322
max_concurrency: Optional[int],
322323
lora_modules: Optional[Iterable[str]],
@@ -348,6 +349,7 @@ async def benchmark(
348349
output_len=test_output_len,
349350
logprobs=logprobs,
350351
ignore_eos=ignore_eos,
352+
debug=debug,
351353
extra_body=extra_body,
352354
)
353355

@@ -435,6 +437,7 @@ async def limited_request_func(request_func_input, pbar):
435437
api_url=api_url,
436438
output_len=output_len,
437439
logprobs=logprobs,
440+
debug=debug,
438441
ignore_eos=ignore_eos,
439442
extra_body=extra_body,
440443
)
@@ -819,11 +822,12 @@ def main(args: argparse.Namespace):
819822

820823
# For datasets that follow a similar structure, use a mapping.
821824
dataset_mapping = {
822-
"EB": lambda: EBDataset(random_seed=args.seed, dataset_path=args.dataset_path).sample(
825+
"EB": lambda: EBDataset(random_seed=args.seed, dataset_path=args.dataset_path, shuffle=args.shuffle).sample(
823826
num_requests=args.num_prompts,
824827
output_len=args.sharegpt_output_len,
825828
),
826-
"EBChat": lambda: EBChatDataset(random_seed=args.seed, dataset_path=args.dataset_path).sample(
829+
"EBChat": lambda: EBChatDataset(random_seed=args.seed, dataset_path=args.dataset_path,
830+
shuffle=args.shuffle).sample(
827831
num_requests=args.num_prompts,
828832
output_len=args.sharegpt_output_len,
829833
),
@@ -883,6 +887,7 @@ def main(args: argparse.Namespace):
883887
selected_percentile_metrics=args.percentile_metrics.split(","),
884888
selected_percentiles=[float(p) for p in args.metric_percentiles.split(",")],
885889
ignore_eos=args.ignore_eos,
890+
debug=args.debug,
886891
goodput_config_dict=goodput_config_dict,
887892
max_concurrency=args.max_concurrency,
888893
lora_modules=args.lora_modules,
@@ -1071,6 +1076,11 @@ def main(args: argparse.Namespace):
10711076
"results in a more uniform arrival of requests.",
10721077
)
10731078
parser.add_argument("--seed", type=int, default=0)
1079+
parser.add_argument(
1080+
"--shuffle",
1081+
action="store_true",
1082+
help="shuffle dataset",
1083+
)
10741084
parser.add_argument(
10751085
"--trust-remote-code",
10761086
action="store_true",
@@ -1091,6 +1101,11 @@ def main(args: argparse.Namespace):
10911101
action="store_true",
10921102
help="Specify to save benchmark results to a json file",
10931103
)
1104+
parser.add_argument(
1105+
"--debug",
1106+
action="store_true",
1107+
help="print debug information (output)",
1108+
)
10941109
parser.add_argument(
10951110
"--save-detailed",
10961111
action="store_true",

0 commit comments

Comments
 (0)