vllm.v1.sample.logits_processor
AddedRequest
module-attribute
¶
AddedRequest = tuple[
int, Union[SamplingParams, PoolingParams], list[int]
]
BatchUpdate
dataclass
¶
Persistent batch state change info for logitsprocs
Source code in vllm/v1/sample/logits_processor.py
__init__
¶
__init__(
batch_size: int,
removed: Sequence[RemovedRequest],
moved: Sequence[MovedRequest],
added: Sequence[AddedRequest],
) -> None
BatchUpdateBuilder
¶
Helps track persistent batch state changes and build a batch update data structure for logitsprocs
Assumptions: * All information about requests removed from persistent batch during a step is aggregated in self._removed through calls to self.removed_append() at the beginning of a step. This must happen before the first time that self.removed, self.pop_removed() or self.peek_removed() are invoked in a given step * After the first time that self.removed, self.pop_removed() or self.peek_removed() are read in a step, no new removals are registered using self.removed_append() * Elements of self._removed are never directly modified, added or removed (i.e. modification is only via self.removed_append() and self.pop_removed())
Guarantees under above assumptions: * self.removed is always sorted in descending order * self.pop_removed() and self.peek_removed() both return the lowest removed request index in the current step
Source code in vllm/v1/sample/logits_processor.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 |
|
__init__
¶
__init__(
removed: Optional[list[RemovedRequest]] = None,
moved: Optional[list[MovedRequest]] = None,
added: Optional[list[AddedRequest]] = None,
) -> None
Source code in vllm/v1/sample/logits_processor.py
_ensure_removed_sorted
¶
Sort removed request indices in descending order.
Idempotent after first call in a given step, until reset.
Source code in vllm/v1/sample/logits_processor.py
get_and_reset
¶
get_and_reset(batch_size: int) -> Optional[BatchUpdate]
Generate a logitsprocs batch update data structure and reset internal batch update builder state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size
|
int
|
current persistent batch size |
required |
Returns:
Type | Description |
---|---|
Optional[BatchUpdate]
|
Frozen logitsprocs batch update instance; |
Source code in vllm/v1/sample/logits_processor.py
peek_removed
¶
pop_removed
¶
removed_append
¶
removed_append(index: int) -> None
Register the removal of a request from the persistent batch.
Must not be called after the first time self.removed, self.pop_removed() or self.peek_removed() are invoked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
request index |
required |
Source code in vllm/v1/sample/logits_processor.py
LogitBiasLogitsProcessor
¶
Bases: LogitsProcessor
Source code in vllm/v1/sample/logits_processor.py
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 |
|
logits_slice
instance-attribute
¶
__init__
¶
Source code in vllm/v1/sample/logits_processor.py
_device_tensor
¶
apply
¶
is_argmax_invariant
¶
is_argmax_invariant() -> bool
Logit bias can rebalance token probabilities and change the outcome of argmax in greedy sampling.
update_state
¶
update_state(batch_update: Optional[BatchUpdate])
Source code in vllm/v1/sample/logits_processor.py
LogitsProcessor
¶
Bases: ABC
Source code in vllm/v1/sample/logits_processor.py
apply
abstractmethod
¶
is_argmax_invariant
abstractmethod
¶
is_argmax_invariant() -> bool
True if logits processor has no impact on the argmax computation in greedy sampling. NOTE: may or may not have the same value for all instances of a given LogitsProcessor subclass, depending on subclass implementation. TODO(andy): won't be utilized until logits processors are user-extensible
Source code in vllm/v1/sample/logits_processor.py
update_state
abstractmethod
¶
update_state(batch_update: Optional[BatchUpdate]) -> None
Called when there are new output tokens, prior to each forward pass.
Source code in vllm/v1/sample/logits_processor.py
LogitsProcessorManager
dataclass
¶
Encapsulates initialized logitsproc objects.
Source code in vllm/v1/sample/logits_processor.py
argmax_invariant
class-attribute
instance-attribute
¶
argmax_invariant: list[LogitsProcessor] = field(
default_factory=list
)
non_argmax_invariant
class-attribute
instance-attribute
¶
non_argmax_invariant: list[LogitsProcessor] = field(
default_factory=list
)
__init__
¶
__init__(
argmax_invariant: list[LogitsProcessor] = list(),
non_argmax_invariant: list[LogitsProcessor] = list(),
) -> None
MinPLogitsProcessor
¶
Bases: LogitsProcessor
Source code in vllm/v1/sample/logits_processor.py
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 |
|
min_p_cpu_tensor
instance-attribute
¶
min_p_cpu_tensor = zeros(
(max_num_reqs,),
dtype=float32,
device="cpu",
pin_memory=pin_memory,
)
min_p_device
instance-attribute
¶
__init__
¶
Source code in vllm/v1/sample/logits_processor.py
apply
¶
Source code in vllm/v1/sample/logits_processor.py
get_min_p_by_index
¶
update_state
¶
update_state(batch_update: Optional[BatchUpdate])
Source code in vllm/v1/sample/logits_processor.py
MinTokensLogitsProcessor
¶
Bases: LogitsProcessor
Source code in vllm/v1/sample/logits_processor.py
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 |
|
logits_slice
instance-attribute
¶
__init__
¶
Source code in vllm/v1/sample/logits_processor.py
_device_tensor
¶
apply
¶
is_argmax_invariant
¶
is_argmax_invariant() -> bool
By censoring stop tokens, min-tokens can change the outcome of the argmax operation in greedy sampling.
update_state
¶
update_state(batch_update: Optional[BatchUpdate])
Source code in vllm/v1/sample/logits_processor.py
init_builtin_logitsprocs
¶
init_builtin_logitsprocs(
pin_memory_available: bool,
max_num_reqs: int,
device: device,
) -> LogitsProcessorManager
Construct 'builtin' vLLM logitsprocs which the engine loads by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pin_memory_available
|
bool
|
pinned memory is available for use for use by logitsproc |
required |
max_num_reqs
|
int
|
ceiling on request count in persistent batch |
required |
device
|
device
|
inference device |
required |
Returns:
Type | Description |
---|---|
LogitsProcessorManager
|
Data structure encapsulating loaded logitsprocs |