vllm.logprobs
¶
Classes:
-
FlatLogprobs–Logprobs of a request in a few append-only numpy columns, with no
-
Logprob–Infos for supporting OpenAI compatible logprobs and token ranks.
Functions:
-
append_logprobs_for_next_position–Appends logprobs for the next position.
-
create_prompt_logprobs–Creates a container to store prompt logprobs for a request.
-
create_sample_logprobs–Creates a container to store decode logprobs for a request.
FlatLogprobs
¶
Bases: MutableSequence[LogprobsOnePosition | None]
Logprobs of a request in a few append-only numpy columns, with no Python object per position or entry (about 8.5 bytes per entry).
Token ids and logprobs are int32 / float32, the engine's dtypes, widened
to int64 / float64 if a value would not round-trip. A position's first
entry keeps its rank and entry j > 0 has rank j, as
append_logprobs_for_next_position gives; any other rank switches to a
per-entry rank column. Decoded tokens are kept once one is not None.
It supports the key Sequence APIs of list[LogprobsOnePosition]. The
column attributes (start_indices, end_indices, token_ids,
logprobs, ranks, decoded_tokens) are read-only views.
Methods:
-
__getitem__–Extracts logprobs of a given position or slice.
-
__iter__–Iterates the container and yields LogprobsOnePosition for
-
__len__–Gets number of positions stored in the container.
-
append–Appends the container with logprobs for the next position.
-
append_fast–Appends logprobs for the next position without creating
-
append_rows–Appends
npositions given as engine rows:[n, S]token ids -
extend–Extends the container with logprobs for the next multiple positions.
-
first_token_ids–Token id of the first entry of each position in
[start, stop) -
rows–The entries as engine rows: int32
token_ids[N, S], float32
Attributes:
-
num_entries(int) –Number of (position, candidate) entries.
num_entries
property
¶
Number of (position, candidate) entries.
__getitem__(index)
¶
Extracts logprobs of a given position or slice.
__iter__()
¶
Iterates the container and yields LogprobsOnePosition for each position.
__len__()
¶
Gets number of positions stored in the container.
_append(widths, token_ids, logprobs, first_ranks, ranks=None, decoded_tokens=None)
¶
Appends len(first_ranks) positions of widths entries (one for
all, or each), with every entry's rank in ranks if not canonical.
_bounds(start, stop)
¶
Entry offsets b of positions [start, stop): position
start + i spans entries [b[i], b[i + 1]).
_canonical_ranks(start, stop)
¶
Ranks of entries [start, stop) from their position's first
rank: entry j > 0 of a position has rank j.
_entry_ranks(start, stop)
¶
Ranks of entries [start, stop), with _NO_RANK for None.
_extend_from(source, start, stop)
¶
Appends positions [start, stop) of source.
_position(position, begin, end)
¶
Position position, whose entries are [begin, end).
_uniform_slice(start, stop)
¶
Positions [start, stop) of same-width positions, copying each
column directly (e.g. the per-step [-n:] of DELTA outputs).
append(logprobs_one_position)
¶
Appends the container with logprobs for the next position.
append_fast(token_ids, logprobs, ranks, decoded_tokens)
¶
Appends logprobs for the next position without creating
the intermediate logprob dictionary. Like zip, stops at the
shortest input.
append_rows(token_ids, logprobs, first_ranks, decoded_tokens=None)
¶
Appends n positions given as engine rows: [n, S] token ids
and logprobs, the [n] ranks of slot 0 and optionally the n * S
decoded tokens.
extend(logprobs_multi_positions)
¶
Extends the container with logprobs for the next multiple positions.
first_token_ids(start, stop)
¶
Token id of the first entry of each position in [start, stop)
that has entries.
rows()
¶
The entries as engine rows: int32 token_ids[N, S], float32
logprobs[N, S] and the int64 ranks of slot 0 [N]; None unless
all positions have S > 0 entries, canonical ranks and no column
was widened.
Logprob
dataclass
¶
_Column
¶
An append-only 1-D array in a buffer that doubles when full, widened
from dtype to wide when a value would not round-trip. Growing
allocates a new buffer, so earlier views stay valid.
Methods:
-
copy–A new column holding elements
[start, stop).
copy(start, stop)
¶
A new column holding elements [start, stop).
_ColumnView
¶
_fits(values, dtype)
¶
Whether values round-trip through dtype (NaN included).
append_logprobs_for_next_position(request_logprobs, token_ids, logprobs, decoded_tokens, rank, num_logprobs)
¶
Appends logprobs for the next position.
create_prompt_logprobs(flat_logprobs)
¶
Creates a container to store prompt logprobs for a request.
create_sample_logprobs(flat_logprobs)
¶
Creates a container to store decode logprobs for a request.