vllm.v1.token_buffer
¶
Classes:
-
TokenBuffer–Mutable int32 token ids with no per-token Python objects.
-
TokenIdsView–tokensfollowed bysuffix, 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 intoken_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.
Source code in vllm/v1/token_buffer.py
TokenIdsView
¶
tokens followed by suffix, shortened from the end by pop().
Copied into a list only when read element-wise, so a caller that ignores
it, or searches it with rfind_tokens, doesn't copy tokens.
Source code in vllm/v1/token_buffer.py
extend_from_slice(dst, src, start, stop)
¶
dst.extend(src[start:stop]), copied without Python ints when both are
TokenBuffers.
Source code in vllm/v1/token_buffer.py
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.
Source code in vllm/v1/token_buffer.py
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.
Source code in vllm/v1/token_buffer.py
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.