vllm.entrypoints.generate.base.serving
¶
Classes:
Functions:
-
build_per_request_timing_metrics–Build per-request timing metrics from
RequestStateStats. -
build_spec_decoding_metrics–Build per-request spec-decode acceptance metrics from the single output
-
chat_top_logprobs_limit–How many of a position's logprob candidates
/v1/chat/completions -
completion_top_logprobs_limit–How many of a position's logprob candidates
/v1/completionsreturns: -
decode_token_ids–Decode token ids individually to their token strings and UTF-8 bytes.
GenerateBaseServing
¶
Bases: BaseServing, BeamSearchOnlineMixin
_convert_generation_error_to_streaming_response(e)
¶
Convert GenerationError to streaming error response.
_get_data_parallel_rank(raw_request)
staticmethod
¶
Pulls the data parallel rank from a header, if provided.
_preflight(n=1)
¶
_raise_if_error(finish_reason, request_id)
¶
Raise GenerationError if finish_reason indicates an error.
_with_kv_transfer_rejection_cleanup(awaitable, request, raw_request)
async
¶
Wrap a create_* coroutine so that, if it raises or returns an
ErrorResponse (i.e. the request never reached the engine), the KV
connector is notified to free any pinned remote-prefill blocks.
build_per_request_timing_metrics(metrics, num_generation_tokens, first_content_token_ts=None)
¶
Build per-request timing metrics from RequestStateStats.
generation_time_ms is the decode interval only (first output token to
last output token); it excludes both queue wait and prefill/TTFT.
tokens_per_second is overall output throughput: all generated tokens
over the inference interval (scheduling to last output token), so it counts
the prefill/TTFT phase and is not simply the reciprocal of mean_itl_ms.
Each field is left None when the timestamps it depends on are
unavailable.
build_spec_decoding_metrics(final_res)
¶
Build per-request spec-decode acceptance metrics from the single output
sequence, or None when unavailable (metrics disabled, or no sequence
yet).
Only meaningful for single-sequence requests; callers suppress it for n>1.
chat_top_logprobs_limit(top_logprobs, return_all=False)
¶
How many of a position's logprob candidates /v1/chat/completions
returns, in the engine's order (sampled token first): the first
top_logprobs, none when it is unset, and all of them (None) for
top_logprobs=-1 or logprob_token_ids (return_all). Shared with
chat derender so the two cannot drift.
completion_top_logprobs_limit(logprobs, return_all=False)
¶
How many of a position's logprob candidates /v1/completions returns:
the first logprobs + 1 (the OpenAI completions convention), and all of
them (None) for logprobs=-1, logprob_token_ids (return_all)
or when logprobs is unset. Shared with completions derender so the two
cannot drift.
decode_token_ids(token_ids, tokenizer)
¶
Decode token ids individually to their token strings and UTF-8 bytes.
Uses the engine's per-token detokenization, which restores the
SentencePiece leading space that convert_tokens_to_string drops, so the
strings match the coupled endpoints. Ids are decoded in one batch (callers
pass a position's sampled id together with its top-k ids). An id with no
vocab entry decodes to ("", None).