vllm.benchmarks.serve
¶
Benchmark online serving throughput.
On the server side, run one of the following commands
to launch the vLLM OpenAI API server:
vllm serve
On the client side, run:
vllm bench serve \
--backend
Classes:
-
DiffusionMetrics–Diffusion (dLLM) decoding metrics from the server's Prometheus endpoint.
-
SpecDecodeMetrics–Speculative decoding metrics from the server's Prometheus endpoint.
Functions:
-
calculate_metrics–Calculate the metrics for the benchmark.
-
calculate_metrics_for_embeddings–Calculate the metrics for the embedding requests.
-
compute_result_filename–Compute the result filename based on benchmark configuration.
-
fetch_diffusion_metrics–Fetch diffusion decoding metrics from the server's Prometheus endpoint.
-
fetch_spec_decode_metrics–Fetch speculative decoding metrics from the server's Prometheus endpoint.
-
get_first_model_from_server–Fetch the first model from the server's /v1/models endpoint.
-
get_request–Asynchronously generates requests at a specified rate
DiffusionMetrics
dataclass
¶
Diffusion (dLLM) decoding metrics from the server's Prometheus endpoint.
SpecDecodeMetrics
dataclass
¶
Speculative decoding metrics from the server's Prometheus endpoint.
_align_prompts_to_server_tokenizer(base_url, model_id, input_requests, ssl_context=None)
async
¶
Re-align prompts if local/server tokenizers disagree.
_merge_overrides(base, override)
¶
Shallow merge; per-request wins. Returns None if both are empty.
_rejects_cache_salt(output)
¶
Whether the server refused the request as invalid (HTTP 400 or 422), as a
server that does not accept cache_salt does. Other failures can be
transient, so they are retried with the salt.
_with_unique_cache_salt(request_func_input)
¶
Copy with a fresh cache_salt, so the request cannot hit, or be hit by,
other requests in the prefix cache.
calculate_metrics(input_requests, outputs, dur_s, tokenizer, selected_percentiles, goodput_config_dict)
¶
Calculate the metrics for the benchmark.
Parameters:
-
(input_requests¶list[SampleRequest]) –The input requests.
-
(outputs¶list[RequestFuncOutput]) –The outputs of the requests.
-
(dur_s¶float) –The duration of the benchmark.
-
(tokenizer¶TokenizerLike | None) –The tokenizer to use.
-
(selected_percentiles¶list[float]) –The percentiles to select.
-
(goodput_config_dict¶dict[str, float]) –The goodput configuration.
Returns:
calculate_metrics_for_embeddings(outputs, dur_s, selected_percentiles)
¶
Calculate the metrics for the embedding requests.
Parameters:
-
(outputs¶list[RequestFuncOutput]) –The outputs of the requests.
-
(dur_s¶float) –The duration of the benchmark.
-
(selected_percentiles¶list[float]) –The percentiles to select.
Returns:
-
EmbedBenchmarkMetrics–The calculated benchmark metrics.
compute_result_filename(args, model_id, label, current_dt)
¶
Compute the result filename based on benchmark configuration.
Parameters:
-
(args¶Namespace) –Command line arguments containing result configuration
-
(model_id¶str) –The model identifier
-
(label¶str) –The benchmark label
-
(current_dt¶str) –Current datetime string
Returns:
-
str | None–The computed filename path or None if no result saving is requested
fetch_diffusion_metrics(base_url, session)
async
¶
Fetch diffusion decoding metrics from the server's Prometheus endpoint.
Returns None if the model is not a diffusion model or metrics are not available.
fetch_spec_decode_metrics(base_url, session)
async
¶
Fetch speculative decoding metrics from the server's Prometheus endpoint.
Returns None if speculative decoding is not enabled or metrics are not available.
get_first_model_from_server(base_url, headers=None, ssl_context=None)
async
¶
Fetch the first model from the server's /v1/models endpoint.
get_request(input_requests, request_rate, burstiness=1.0, ramp_up_strategy=None, ramp_up_start_rps=None, ramp_up_end_rps=None, self_timed=False)
async
¶
Asynchronously generates requests at a specified rate with OPTIONAL burstiness and OPTIONAL ramp-up strategy.
Parameters:
-
(input_requests¶list[SampleRequest]) –A list of input requests, each represented as a SampleRequest.
-
(self_timed¶bool, default:False) –If True, the requests carry their own arrival timing and no request rate, burstiness or ramp-up is applied.
-
(request_rate¶float) –The rate at which requests are generated (requests/s).
-
(burstiness¶optional, default:1.0) –The burstiness factor of the request generation. Only takes effect when request_rate is not inf. Default value is 1, which follows a Poisson process. Otherwise, the request intervals follow a gamma distribution. A lower burstiness value (0 < burstiness < 1) results in more bursty requests, while a higher burstiness value (burstiness > 1) results in a more uniform arrival of requests.
-
(ramp_up_strategy¶optional, default:None) –The ramp-up strategy. Can be "linear" or "exponential". If None, uses constant request rate (specified by request_rate).
-
(ramp_up_start_rps¶optional, default:None) –The starting request rate for ramp-up.
-
(ramp_up_end_rps¶optional, default:None) –The ending request rate for ramp-up.