Skip to content

vllm.v1.token_buffer

Classes:

  • TokenBuffer –

    Mutable int32 token ids with no per-token Python objects.

  • TokenIdsView –

    tokens followed by suffix, shortened from the end by pop().

Functions:

  • extend_from_slice –

    dst.extend(src[start:stop]), copied without Python ints when both are

  • rfind_token_sequences –

    Return (index, k) for the newest occurrence in token_ids[start:stop]

  • rfind_tokens –

    Return the index of the last token in token_ids[start:stop] that is

  • token_slice –

    tokens[start:stop]; for a TokenBuffer an int32 array, so that no

TokenBuffer

Bases: array

Mutable int32 token ids with no per-token Python objects.

TokenIdsView

Bases: Sequence[int]

tokens followed by suffix, shortened from the end by pop().

Indexing reads only the requested tokens. Iteration and membership checks materialize and cache the full view as a list.

extend_from_slice(dst, src, start, stop)

dst.extend(src[start:stop]), copied without Python ints when both are TokenBuffers.

rfind_token_sequences(token_ids, markers, start=0, stop=None)

Return (index, k) for the newest occurrence in token_ids[start:stop] of any of the multi-token markers, k being its position in markers (the first listed wins at the same index), or (-1, -1).

Candidates are found with rfind_tokens on the markers' first tokens, so a TokenBuffer is searched with numpy and only candidate positions are read.

rfind_tokens(token_ids, targets, start=0, stop=None)

Return the index of the last token in token_ids[start:stop] that is one of targets (None entries, for absent tokens, are ignored), or -1.

An int32 buffer (a TokenBuffer) is searched with numpy, in chunks growing back from stop so a recent match is found quickly, without creating a Python int per token. Other sequences are scanned backwards in Python.

token_slice(tokens, start, stop)

tokens[start:stop]; for a TokenBuffer an int32 array, so that no Python ints are made until it is read.