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.
Source code in vllm/logprobs.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
num_entries
property
¶
Number of (position, candidate) entries.
__getitem__(index)
¶
Extracts logprobs of a given position or slice.
Source code in vllm/logprobs.py
__iter__()
¶
Iterates the container and yields LogprobsOnePosition for each position.
Source code in vllm/logprobs.py
__len__()
¶
_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.
Source code in vllm/logprobs.py
_bounds(start, stop)
¶
Entry offsets b of positions [start, stop): position
start + i spans entries [b[i], b[i + 1]).
Source code in vllm/logprobs.py
_canonical_ranks(start, stop)
¶
Ranks of entries [start, stop) from their position's first
rank: entry j > 0 of a position has rank j.
Source code in vllm/logprobs.py
_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.
Source code in vllm/logprobs.py
_position(position, begin, end)
¶
Position position, whose entries are [begin, end).
Source code in vllm/logprobs.py
_uniform_slice(start, stop)
¶
Positions [start, stop) of same-width positions, copying each
column directly (e.g. the per-step [-n:] of DELTA outputs).
Source code in vllm/logprobs.py
append(logprobs_one_position)
¶
Appends the container with logprobs for the next position.
Source code in vllm/logprobs.py
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.
Source code in vllm/logprobs.py
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.
Source code in vllm/logprobs.py
extend(logprobs_multi_positions)
¶
Extends the container with logprobs for the next multiple positions.
Source code in vllm/logprobs.py
first_token_ids(start, stop)
¶
Token id of the first entry of each position in [start, stop)
that has entries.
Source code in vllm/logprobs.py
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.
Source code in vllm/logprobs.py
Logprob
dataclass
¶
Infos for supporting OpenAI compatible logprobs and token ranks.
Attributes:
-
logprob(float) –The logprob of chosen token
-
rank(int | None) –The vocab rank of chosen token (>=1)
-
decoded_token(str | None) –The decoded chosen token index
Source code in vllm/logprobs.py
_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).
Source code in vllm/logprobs.py
copy(start, stop)
¶
A new column holding elements [start, stop).
Source code in vllm/logprobs.py
_ColumnView
¶
A read-only view of one FlatLogprobs column that follows later
appends and converts only the elements read.
Source code in vllm/logprobs.py
_fits(values, dtype)
¶
Whether values round-trip through dtype (NaN included).
Source code in vllm/logprobs.py
append_logprobs_for_next_position(request_logprobs, token_ids, logprobs, decoded_tokens, rank, num_logprobs)
¶
Appends logprobs for the next position.
Source code in vllm/logprobs.py
create_prompt_logprobs(flat_logprobs)
¶
Creates a container to store prompt logprobs for a request.