Skip to content

vllm.entrypoints.scale_out.token_in_token_out.serving

Classes:

  • ServingTokens –

    Provides Tokens IN <> Tokens OUT functionality to vLLM API.

ServingTokens

Bases: GenerateBaseServing

Provides Tokens IN <> Tokens OUT functionality to vLLM API.

_build_response_fields(request, final_res, request_id, model_name, created_time, num_generated_tokens, request_metadata, completion_tokens_details=None)

Build the fields shared by every non-streaming response level.

_create_text_logprobs(token_ids, top_logprobs, tokenizer=None, top_limit=None)

Create OpenAI style logprobs for the text and derender levels.

With a tokenizer the tokens are decoded strings and carry bytes. Without one (--return-tokens-as-token-ids) they are token_id:N placeholders. top_logprobs keeps the first top_limit candidates the engine returned (the sampled token first, then the top k) or all of them when top_limit is None, as in tokens mode.

_create_tokens_logprobs(token_ids, top_logprobs)

Create generate-shaped logprobs (integer token ids, no tokenizer).

top_logprobs carries every candidate the engine returned for the position: the sampled token first, then the top k, so k entries when the sampled token is in the top k and k + 1 when it is not. It is not cut to the requested count: /v1/chat/completions and /v1/completions cut differently, and derender applies each endpoint's cut the way the coupled server does.

The engine reports rank 0 for a sampled token whose logprob is NaN; that is not a rank, so it is sent as None (the logprob is clamped).

_logprob_settings(sampling_params, derender_mode) staticmethod

Logprob count to gate on and the top_logprobs cut.

The derender level returns chat logprobs, so it honors logprob_token_ids and applies the chat top_logprobs cut.

_logprobs_tokenizer(request, text_mode)

Tokenizer that resolves logprob tokens, or None for placeholders.

_MMTensorRefs

Server-wide state for features.kwargs_refs, created at startup.

_clamp_logprob(logprob)

The OpenAI shapes' floor for a logprob: -inf and NaN become -9999.0.

max(nan, -9999.0) is NaN in Python, so NaN needs its own check; NaN would otherwise fail JSONResponse or reach the client as null.

_close_result_generator(result_generator, request_id) async

Close generate() so it aborts this request by its internal ID.

_logprob_token(token_id, logprob, tokenizer)

Token string and UTF-8 bytes for one logprob entry.

Without a tokenizer the token is a token_id:N placeholder with no bytes.