Benchmarks an API endpoint using a given set of sample inputs and returns
(
backend: str,
api_url: str,
base_url: str,
model_id: str,
model_name: str,
input_requests: list[SampleRequest],
hyper_parameters: dict,
logprobs: Optional[int],
request_rate: float,
burstiness: float,
disable_tqdm: bool,
profile: bool,
selected_percentile_metrics: list[str],
selected_percentiles: list[float],
ignore_eos: bool,
goodput_config_dict: dict[str, float],
max_concurrency: Optional[int],
lora_modules: Optional[Iterable[str]],
extra_body: Optional[dict],
)
| 300 | |
| 301 | |
| 302 | async def benchmark( |
| 303 | backend: str, |
| 304 | api_url: str, |
| 305 | base_url: str, |
| 306 | model_id: str, |
| 307 | model_name: str, |
| 308 | input_requests: list[SampleRequest], |
| 309 | hyper_parameters: dict, |
| 310 | logprobs: Optional[int], |
| 311 | request_rate: float, |
| 312 | burstiness: float, |
| 313 | disable_tqdm: bool, |
| 314 | profile: bool, |
| 315 | selected_percentile_metrics: list[str], |
| 316 | selected_percentiles: list[float], |
| 317 | ignore_eos: bool, |
| 318 | goodput_config_dict: dict[str, float], |
| 319 | max_concurrency: Optional[int], |
| 320 | lora_modules: Optional[Iterable[str]], |
| 321 | extra_body: Optional[dict], |
| 322 | ): |
| 323 | """Benchmarks an API endpoint using a given set of sample inputs and returns""" |
| 324 | if backend in ASYNC_REQUEST_FUNCS: |
| 325 | request_func = ASYNC_REQUEST_FUNCS[backend] |
| 326 | else: |
| 327 | raise ValueError(f"Unknown backend: {backend}") |
| 328 | |
| 329 | if check_health(base_url): |
| 330 | print("服务健康,可开始评测") |
| 331 | else: |
| 332 | print("服务异常,跳过或报警") |
| 333 | exit(33) |
| 334 | |
| 335 | if lora_modules: |
| 336 | # For each input request, choose a LoRA module at random. |
| 337 | lora_modules = iter([random.choice(lora_modules) for _ in range(len(input_requests))]) |
| 338 | |
| 339 | if profile: |
| 340 | print("Starting profiler...") |
| 341 | test_prompt = None |
| 342 | test_output_len = None |
| 343 | profile_input = RequestFuncInput( |
| 344 | model=model_id, |
| 345 | model_name=model_name, |
| 346 | prompt=test_prompt, |
| 347 | api_url=base_url + "/start_profile", |
| 348 | output_len=test_output_len, |
| 349 | logprobs=logprobs, |
| 350 | ignore_eos=ignore_eos, |
| 351 | extra_body=extra_body, |
| 352 | ) |
| 353 | profile_output = await request_func(request_func_input=profile_input) |
| 354 | if profile_output.success: |
| 355 | print("Profiler started") |
| 356 | |
| 357 | if burstiness == 1.0: |
| 358 | distribution = "Poisson process" |
| 359 | else: |
no test coverage detected