vllm.worker.worker_base
DelegateWorkerBase
¶
Bases: WorkerBase
A class that delegates all methods to another WorkerBase instance. This is useful for creating a WorkerBase that wraps another WorkerBase instance, e.g. speculative decoding.
Source code in vllm/worker/worker_base.py
__getattr__
¶
__init__
¶
add_lora
¶
add_lora(lora_request: LoRARequest) -> bool
determine_num_available_blocks
¶
execute_model
¶
execute_model(
execute_model_req: Optional[ExecuteModelRequest] = None,
) -> Optional[List[SamplerOutput]]
init_device
¶
initialize_cache
¶
list_loras
¶
load_model
¶
pin_lora
¶
LoRANotSupportedWorkerBase
¶
Bases: WorkerBase
Partial implementation of WorkerBase that raises exceptions when LoRA methods are invoked.
Source code in vllm/worker/worker_base.py
LocalOrDistributedWorkerBase
¶
Bases: WorkerBase
Partial implementation of WorkerBase that has a default execute_model
definition to perform metadata transfer between workers when in distributed
mode. Subclasses of this interface should use model runners that inherit
from ModelRunnerBase, and should only need to implement worker-local logic.
If custom control plane logic is needed to transfer metadata, or if the
model runner cannot inherit from ModelRunnerBase, use WorkerBase instead.
Source code in vllm/worker/worker_base.py
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 |
|
do_metadata_broadcast
abstractmethod
property
¶
do_metadata_broadcast: bool
Used by the default execute_model
to check whether broadcast is
needed to transfer request inputs from the driver worker to other
workers in the TP group. If WorkerBase subclass only supports
single-worker execution, then this method should return False.
kv_cache
abstractmethod
property
¶
Gets the list of kv caches to pass to the worker's model runner. Each
element in the list is a kv cache corresponding to a particular virtual
engine (PP stream). Used by the default execute_model
. If the worker's
model runner does not follow the ModelRunnerBase interface, then inherit
from WorkerBase instead.
observability_config
class-attribute
instance-attribute
¶
observability_config: Optional[ObservabilityConfig] = None
_execute_model_spmd
¶
_execute_model_spmd(
execute_model_req: ExecuteModelRequest,
intermediate_tensors: Optional[
IntermediateTensors
] = None,
) -> Optional[List[SamplerOutput]]
Execute model in Single Program Multiple Data (SPMD) fashion. All workers take the same request, prepare the input and execute the model.
Source code in vllm/worker/worker_base.py
_get_driver_input_and_broadcast
¶
_get_driver_input_and_broadcast(
execute_model_req: ExecuteModelRequest,
) -> Tuple[
BroadcastableModelInput, WorkerInput, Dict[str, Tensor]
]
Get the driver input and broadcast it to other workers.
Source code in vllm/worker/worker_base.py
_get_worker_input_from_broadcast
¶
_get_worker_input_from_broadcast() -> Optional[
Tuple[
BroadcastableModelInput,
WorkerInput,
Dict[str, Tensor],
]
]
Get the worker input from the broadcasted tensor dict.
Source code in vllm/worker/worker_base.py
execute_model
¶
execute_model(
execute_model_req: Optional[ExecuteModelRequest] = None,
) -> Optional[List[SamplerOutput]]
Executes at least one model step on the given sequences, unless no sequences are provided.
Source code in vllm/worker/worker_base.py
execute_worker
abstractmethod
¶
execute_worker(worker_input: WorkerInput) -> None
prepare_input
¶
prepare_input(
execute_model_req: Optional[ExecuteModelRequest] = None,
) -> Optional[
Tuple[
BroadcastableModelInput,
WorkerInput,
Dict[str, Tensor],
]
]
Prepare the inputs to ModelRunner and workers.
Source code in vllm/worker/worker_base.py
prepare_worker_input
abstractmethod
¶
prepare_worker_input(
execute_model_req: ExecuteModelRequest,
) -> WorkerInput
Prepare the inputs to WorkerBase.execute_worker from an execution request. This method may move data to the worker's local device. It is not allowed to communicate with other workers or devices.
Source code in vllm/worker/worker_base.py
WorkerBase
¶
Worker interface that allows vLLM to cleanly separate implementations for different hardware. Also abstracts control plane communication, e.g., to communicate request metadata to other workers.
Source code in vllm/worker/worker_base.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 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 |
|
__init__
¶
__init__(vllm_config: VllmConfig) -> None
Source code in vllm/worker/worker_base.py
add_lora
¶
add_lora(lora_request: LoRARequest) -> bool
determine_num_available_blocks
¶
Determine the number of available blocks for the GPU KV cache and swappable CPU KV cache.
The implementation may run profiling or other heuristics to determine the size of caches.
Returns a Tuple[num_gpu_blocks, num_cpu_blocks], where num_gpu_blocks are blocks that are "active" on the device and can be appended to. num_cpu_blocks refers to "swapped" blocks in CPU memory and cannot be appended to.
Source code in vllm/worker/worker_base.py
execute_model
¶
execute_model(
execute_model_req: Optional[ExecuteModelRequest] = None,
) -> Optional[List[SamplerOutput]]
get_cache_block_size_bytes
¶
get_cache_block_size_bytes() -> int
Return the size of a single cache block, in bytes. Used in speculative decoding.
init_device
¶
initialize_cache
¶
list_loras
¶
load_model
¶
pin_lora
¶
remove_lora
¶
start_worker_execution_loop
¶
Execute model loop in parallel worker.
You can stop the loop by executing a driver worker with an empty output.
See stop_remote_worker_execution_loop
for more details.
Source code in vllm/worker/worker_base.py
WorkerInput
dataclass
¶
Local inputs to each worker. May contain device-specific data. These fields should be broadcastable to other workers.
Source code in vllm/worker/worker_base.py
__init__
¶
__init__(
num_seq_groups: Optional[int] = None,
blocks_to_swap_in: Optional[Tensor] = None,
blocks_to_swap_out: Optional[Tensor] = None,
blocks_to_copy: Optional[Tensor] = None,
virtual_engine: int = 0,
num_steps: int = 1,
) -> None
as_broadcastable_tensor_dict
¶
Extract broadcastable fields.
Source code in vllm/worker/worker_base.py
from_broadcasted_tensor_dict
classmethod
¶
from_broadcasted_tensor_dict(
tensor_dict: Dict[str, Any],
) -> WorkerInput
Pop fields from the given tensor_dict and populate a new instance of WorkerInput.
Source code in vllm/worker/worker_base.py
WorkerWrapperBase
¶
This class represents one process in an executor/engine. It is responsible
for lazily initializing the worker and handling the worker's lifecycle.
We first instantiate the WorkerWrapper, which remembers the worker module
and class name. Then, when we call update_environment_variables
, and the
real initialization happens in init_worker
.
Source code in vllm/worker/worker_base.py
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 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
|
__getattr__
¶
__init__
¶
__init__(
vllm_config: VllmConfig, rpc_rank: int = 0
) -> None
Initialize the worker wrapper with the given vllm_config and rpc_rank. Note: rpc_rank is the rank of the worker in the executor. In most cases, it is also the rank of the worker in the distributed group. However, when multiple executors work together, they can be different. e.g. in the case of SPMD-style offline inference with TP=2, users can launch 2 engines/executors, each with only 1 worker. All workers have rpc_rank=0, but they have different ranks in the TP group.
Source code in vllm/worker/worker_base.py
adjust_rank
¶
Adjust the rpc_rank based on the given mapping. It is only used during the initialization of the executor, to adjust the rpc_rank of workers after we create all workers.
Source code in vllm/worker/worker_base.py
execute_method
¶
Source code in vllm/worker/worker_base.py
init_device
¶
init_worker
¶
Here we inject some common logic before initializing the worker. Arguments are passed to the worker class constructor.
Source code in vllm/worker/worker_base.py
initialize_from_config
¶
update_environment_variables
¶
Source code in vllm/worker/worker_base.py
extract_previous_hidden_states
¶
extract_previous_hidden_states(
data: Union[ExecuteModelRequest, Dict[str, Tensor]],
) -> Dict[str, Tensor]
If data contains previous_hidden_states, extract it. This returns a dict which can be used directly as additional kwargs in any following execute_model calls. This is used in draft models like EAGLE.