vllm.v1.utils
APIServerProcessManager
¶
Manages a group of API server processes.
Handles creation, monitoring, and termination of API server worker processes. Also monitors extra processes to check if they are healthy.
Source code in vllm/v1/utils.py
__init__
¶
__init__(
target_server_fn: Callable,
listen_address: str,
sock: Any,
args: Namespace,
num_servers: int,
input_addresses: list[str],
output_addresses: list[str],
stats_update_address: Optional[str] = None,
)
Initialize and start API server worker processes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_server_fn
|
Callable
|
Function to call for each API server process |
required |
listen_address
|
str
|
Address to listen for client connections |
required |
sock
|
Any
|
Socket for client connections |
required |
args
|
Namespace
|
Command line arguments |
required |
num_servers
|
int
|
Number of API server processes to start |
required |
input_addresses
|
list[str]
|
Input addresses for each API server |
required |
output_addresses
|
list[str]
|
Output addresses for each API server |
required |
stats_update_address
|
Optional[str]
|
Optional stats update address |
None
|
Source code in vllm/v1/utils.py
ConstantList
¶
Source code in vllm/v1/utils.py
CoreEngine
¶
One per data parallel rank.
Source code in vllm/v1/utils.py
CoreEngineActorManager
¶
Utility class to handle creation, readiness, and shutdown of core engine Ray actors used by the AsyncLLM and LLMEngine.
Different from CoreEngineProcManager, this class manages core engines for both local and remote nodes.
Source code in vllm/v1/utils.py
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 | |
__init__
¶
__init__(
vllm_config: VllmConfig,
addresses: EngineZmqAddresses,
executor_class: type[Executor],
log_stats: bool,
placement_groups: Optional[list[PlacementGroup]] = None,
local_dp_ranks: Optional[list[int]] = None,
)
Source code in vllm/v1/utils.py
close
¶
create_dp_placement_groups
staticmethod
¶
create_dp_placement_groups(
vllm_config: VllmConfig,
) -> tuple[list[PlacementGroup], list[int]]
Source code in vllm/v1/utils.py
CoreEngineProcManager
¶
Utility class to handle creation, readiness, and shutdown of background processes used by the AsyncLLM and LLMEngine.
Source code in vllm/v1/utils.py
__init__
¶
__init__(
target_fn: Callable,
local_engine_count: int,
start_index: int,
local_start_index: int,
vllm_config: VllmConfig,
on_head_node: bool,
handshake_address: str,
executor_class: type[Executor],
log_stats: bool,
)
Source code in vllm/v1/utils.py
close
¶
finished_procs
¶
Returns dict of proc name -> exit code for any finished procs.
join_first
¶
EngineHandshakeMetadata
dataclass
¶
Metadata sent to each engine process during startup handshake, including addresses of the front-end ZMQ queues that they should connect to.
Source code in vllm/v1/utils.py
EngineZmqAddresses
dataclass
¶
Source code in vllm/v1/utils.py
bind_kv_cache
¶
bind_kv_cache(
kv_caches: dict[str, Tensor],
forward_context: dict[str, Attention],
runner_kv_caches: list[Tensor],
) -> None
Bind the allocated KV cache to both ModelRunner and forward context so that the KV cache can be used in the forward pass.
This function
1) Fills the ModelRunner's kv cache list (runner_kv_caches) with
kv_caches.
2) Associates each attention layer in the forward_context with its
corresponding KV cache in kv_caches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kv_caches
|
dict[str, Tensor]
|
The allocated kv_caches with layer names as keys. |
required |
forward_context
|
dict[str, Attention]
|
The global forward context containing all Attention |
required |
runner_kv_caches
|
list[Tensor]
|
The kv_cache declared by ModelRunner. |
required |
Source code in vllm/v1/utils.py
copy_slice
¶
Copy the first length elements of a tensor into another tensor in a non-blocking manner.
Used to copy pinned CPU tensor data to pre-allocated GPU tensors.
Returns the sliced target tensor.
Source code in vllm/v1/utils.py
get_engine_client_zmq_addr
¶
report_usage_stats
¶
report_usage_stats(
vllm_config,
usage_context: UsageContext = ENGINE_CONTEXT,
) -> None
Report usage statistics if enabled.
Source code in vllm/v1/utils.py
shutdown
¶
shutdown(procs: list[BaseProcess])
Source code in vllm/v1/utils.py
wait_for_completion_or_failure
¶
wait_for_completion_or_failure(
api_server_manager: APIServerProcessManager,
engine_manager: Optional[
Union[CoreEngineProcManager, CoreEngineActorManager]
] = None,
coordinator: Optional[DPCoordinator] = None,
) -> None
Wait for all processes to complete or detect if any fail.
Raises an exception if any process exits with a non-zero status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_server_manager
|
APIServerProcessManager
|
The manager for API servers. |
required |
engine_manager
|
Optional[Union[CoreEngineProcManager, CoreEngineActorManager]]
|
The manager for engine processes. If CoreEngineProcManager, it manages local engines; if CoreEngineActorManager, it manages all engines. |
None
|
coordinator
|
Optional[DPCoordinator]
|
The coordinator for data parallel. |
None
|
Source code in vllm/v1/utils.py
wait_for_engine_startup
¶
wait_for_engine_startup(
handshake_socket: Socket,
addresses: EngineZmqAddresses,
core_engines: list[CoreEngine],
parallel_config: ParallelConfig,
cache_config: CacheConfig,
proc_manager: Optional[CoreEngineProcManager],
coord_process: Optional[Process],
)
Source code in vllm/v1/utils.py
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 540 541 542 543 544 545 546 547 548 | |