Skip to content

vllm.v1.engine.logprobs

Classes:

LogprobsProcessor dataclass

Methods:

_append_rows(container, num_logprobs, token_ids, logprobs, ranks, detokenize)

Appends [n, S] engine rows, cut to the requested width, with the [n] ranks of their sampled tokens.

_correct_decoded_token(token_id, context_token_ids)

Correct a decoded token that contains the replacement character.

When byte-fallback tokenization splits multi-byte UTF-8 characters across tokens, individual token decoding produces the replacement character U+FFFD. This method uses preceding sampled tokens as context to reconstruct the correct text.

Parameters:

  • token_id

    (int) –

    The single token ID to correct.

  • context_token_ids

    (list[int]) –

    Preceding sampled token IDs in sequential order (oldest first). These are the actual tokens in the generated sequence, NOT top-k alternatives.

Returns:

  • str –

    The corrected decoded string, or empty string if the byte

  • str –

    sequence is genuinely incomplete at this point.

_decode_rows(token_ids, logprobs_source)

The decoded tokens of [n, S] rows about to be appended to logprobs_source, flattened. Rows with a byte-fallback piece are corrected using the tokens of the positions before them: the source's last positions and this batch's earlier rows.

_get_sampled_context_ids(logprobs_source, max_context=4) staticmethod

Extract recent sampled token IDs from a logprobs source.

The sampled (or prompt) token at each position is the first entry, since it is always inserted first by append_logprobs_for_next_position.

Parameters:

  • logprobs_source

    (SampleLogprobs | PromptLogprobs | None) –

    The logprobs container to extract from.

  • max_context

    (int, default: 4 ) –

    Maximum number of preceding tokens to return. 4 is sufficient for any UTF-8 multi-byte sequence.

Returns:

  • list[int] –

    List of sampled token IDs, oldest first, most recent last.

_update_prompt_logprobs(prompt_logprobs_tensors)

Update with prompt logprobs from EngineCore.

Parameters:

  • prompt_logprobs_tensors

    (LogprobsTensors) –

    tuple containing the prompt logprobs tensors.

_update_sample_logprobs(logprobs_lists)

Update with sample logprobs from EngineCore.

Outer lists are only of len > 1 if EngineCore made

1 tokens in prior step (e.g. in spec decoding).

Parameters:

  • logprobs_lists

    (LogprobsLists) –

    the lists of logprob tokens, logprobs, and ranks.

_verify_tokens(decoded_tokens_list, tokens, context_token_ids=None)

Verify and correct decoded tokens with replacement characters.

Parameters:

  • decoded_tokens_list

    (list[str]) –

    Decoded token strings to verify.

  • tokens

    (list[int]) –

    Token IDs corresponding to decoded_tokens_list. These are alternatives at the SAME position (e.g. [sampled, top1, top2]), NOT sequential tokens.

  • context_token_ids

    (list[int] | None, default: None ) –

    Preceding sampled token IDs providing sequential context. If None, extracted from self.logprobs.

pop_prompt_logprobs()

Pop and return all request prompt logprobs.

The logprobs processor aggregates prompt chunk logprobs over one or more prefill chunks. This method returns all prompt logprobs at once and then forgets them. Ensures correct RequestOutputKind.DELTA semantics wherein all prompt logprobs are returned at once at the end of prefill.

Returns:

  • PromptLogprobs | None –

    None if prompt logprobs are disabled for this request.

  • PromptLogprobs | None –

    List of all prompt logprobs, otherwise.

pop_prompt_token_id_logprobs()

Pop and return the fixed-ID prompt scores.