Skip to content

vllm.v1.engine.detokenizer

Classes:

Functions:

BaseIncrementalDetokenizer

Bases: IncrementalDetokenizer, ABC

Methods:

  • get_next_output_text –

    If delta is True, only new text since the last call to

  • update –

    Update RequestState for the request_id by:

get_next_output_text(finished, delta)

If delta is True, only new text since the last call to this method is returned

update(new_token_ids, stop_terminated)

Update RequestState for the request_id by

1) Detokenize the new token ids incrementally. 2) Evaluate stop criteria.

Return matched stop string or None.

check_stop_strings(output_text, new_char_count, stop, include_in_output)

Check if any stop strings are matched and truncate sequence output text accordingly.

Returns tuple (stop_string, offset) if matched or else None.

Where stop_string is the matched stop string and offset is the length to which output_text should be truncated, or -1 for no truncation.

When several stop strings match within the newly generated text (for example when speculative decoding appends multiple tokens in a single step), the stop string that completes earliest in the text is selected, so the result matches appending one token at a time. Ties are broken by stop-list order.

get_decode_stream_seed(tokenizer, prompt_token_ids, skip_special_tokens)

Return a prompt tail that primes a DecodeStream like the full prompt.

The seed only shapes the first delta, so a short tail avoids an O(prompt) decode. The tail holds INITIAL_INCREMENTAL_DETOKENIZATION_OFFSET tokens that decode to text on their own (decoders like Metaspace treat the start of the text specially), extended if its text ends in U+FFFD. Falls back to the full prompt if the prompt's own text ends in U+FFFD.

uses_fast_detokenizer(tokenizer)

Whether the engine detokenizes with FastIncrementalDetokenizer.