vllm.distributed
Modules:
Name | Description |
---|---|
communication_op | |
device_communicators | |
envs | |
eplb | Expert parallelism load balancer (EPLB). |
kv_events | |
kv_transfer | |
parallel_state | vLLM distributed state. |
tpu_distributed_utils | |
utils | |
TensorMetadata module-attribute
¶
TensorMetadata = namedtuple(
"TensorMetadata", ["device", "dtype", "size"]
)
USE_SCHED_YIELD module-attribute
¶
USE_SCHED_YIELD = (
version_info[:3] >= (3, 11, 1)
or version_info[:2] == (3, 10)
and version_info[2] >= 8
)
DeviceCommunicatorBase ¶
Base class for device-specific communicator. It can use the cpu_group
to initialize the communicator. If the device has PyTorch integration (PyTorch can recognize its communication backend), the device_group
will also be given.
Source code in vllm/distributed/device_communicators/base_device_communicator.py
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 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 |
|
__init__ ¶
__init__(
cpu_group: ProcessGroup,
device: Optional[device] = None,
device_group: Optional[ProcessGroup] = None,
unique_name: str = "",
)
Source code in vllm/distributed/device_communicators/base_device_communicator.py
all_gather ¶
Source code in vllm/distributed/device_communicators/base_device_communicator.py
all_gatherv ¶
all_reduce ¶
combine ¶
Combine the hidden states and router logits from the appropriate device. This is a no-op in the base class.
Source code in vllm/distributed/device_communicators/base_device_communicator.py
destroy ¶
dispatch ¶
Dispatch the hidden states and router logits to the appropriate device. This is a no-op in the base class.
Source code in vllm/distributed/device_communicators/base_device_communicator.py
gather ¶
NOTE: We assume that the input tensor is on the same device across all the ranks. NOTE: dst
is the local rank of the destination rank.
Source code in vllm/distributed/device_communicators/base_device_communicator.py
prepare_communication_buffer_for_model ¶
prepare_communication_buffer_for_model(
model: Module,
) -> None
Prepare the communication buffer for the model.
Source code in vllm/distributed/device_communicators/base_device_communicator.py
recv ¶
Receives a tensor from the source rank.
Source code in vllm/distributed/device_communicators/base_device_communicator.py
reduce_scatter ¶
Source code in vllm/distributed/device_communicators/base_device_communicator.py
reduce_scatterv ¶
send ¶
Sends a tensor to the destination rank in a blocking way
Source code in vllm/distributed/device_communicators/base_device_communicator.py
GraphCaptureContext dataclass
¶
GroupCoordinator ¶
PyTorch ProcessGroup wrapper for a group of processes. PyTorch ProcessGroup is bound to one specific communication backend, e.g. NCCL, Gloo, MPI, etc. GroupCoordinator takes charge of all the communication operations among the processes in the group. It manages both CPU and device communication.
Source code in vllm/distributed/parallel_state.py
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 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 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
|
device_communicator instance-attribute
¶
device_communicator: Optional[DeviceCommunicatorBase] = None
use_cpu_custom_send_recv instance-attribute
¶
use_cpu_custom_send_recv = is_cpu() and hasattr(
_C, "init_shm_manager"
)
__init__ ¶
__init__(
group_ranks: list[list[int]],
local_rank: int,
torch_distributed_backend: Union[str, Backend],
use_device_communicator: bool,
use_message_queue_broadcaster: bool = False,
group_name: Optional[str] = None,
)
Source code in vllm/distributed/parallel_state.py
_all_gather_out_place ¶
_all_reduce_out_place ¶
_reduce_scatter_out_place ¶
all_gather ¶
Source code in vllm/distributed/parallel_state.py
all_gatherv ¶
all_gatherv(
input_: Union[Tensor, list[Tensor]],
dim: int = 0,
sizes: Optional[list[int]] = None,
)
Source code in vllm/distributed/parallel_state.py
all_reduce ¶
User-facing all-reduce function before we actually call the all-reduce operation.
We need this because Dynamo does not support passing an arbitrary object (self
in this case) to a custom op. We need to pass the group name as a string, and then look up the group coordinator from the group name, dispatch the all-reduce operation to the group coordinator.
In addition, PyTorch custom ops do not support mutation or returning a new tensor in the same op. So we always make the all-reduce operation out-of-place.
Source code in vllm/distributed/parallel_state.py
barrier ¶
Barrier synchronization among the group. NOTE: don't use device_group
here! barrier
in NCCL is terrible because it is internally a broadcast operation with secretly created GPU tensors. It is easy to mess up the current device. Use the CPU group instead.
Source code in vllm/distributed/parallel_state.py
broadcast ¶
Broadcast the input tensor. NOTE: src
is the local rank of the source rank.
Source code in vllm/distributed/parallel_state.py
broadcast_object ¶
Broadcast the input object. NOTE: src
is the local rank of the source rank.
Source code in vllm/distributed/parallel_state.py
broadcast_object_list ¶
Broadcast the input object list. NOTE: src
is the local rank of the source rank.
Source code in vllm/distributed/parallel_state.py
broadcast_tensor_dict ¶
broadcast_tensor_dict(
tensor_dict: Optional[
dict[str, Union[Tensor, Any]]
] = None,
src: int = 0,
group: Optional[ProcessGroup] = None,
metadata_group: Optional[ProcessGroup] = None,
) -> Optional[dict[str, Union[Tensor, Any]]]
Broadcast the input tensor dictionary. NOTE: src
is the local rank of the source rank.
Source code in vllm/distributed/parallel_state.py
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 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
|
destroy ¶
Source code in vllm/distributed/parallel_state.py
dispatch ¶
Source code in vllm/distributed/parallel_state.py
gather ¶
NOTE: We assume that the input tensor is on the same device across all the ranks. NOTE: dst
is the local rank of the destination rank.
Source code in vllm/distributed/parallel_state.py
graph_capture ¶
graph_capture(
graph_capture_context: Optional[
GraphCaptureContext
] = None,
)
Source code in vllm/distributed/parallel_state.py
recv ¶
Receives a tensor from the source rank.
Source code in vllm/distributed/parallel_state.py
recv_object ¶
Receive the input object list from the source rank.
Source code in vllm/distributed/parallel_state.py
recv_tensor_dict ¶
recv_tensor_dict(
src: Optional[int] = None,
all_gather_group: Optional[GroupCoordinator] = None,
) -> Optional[dict[str, Union[Tensor, Any]]]
Recv the input tensor dictionary. NOTE: src
is the local rank of the source rank.
Source code in vllm/distributed/parallel_state.py
reduce_scatter ¶
Source code in vllm/distributed/parallel_state.py
reduce_scatterv ¶
Source code in vllm/distributed/parallel_state.py
send ¶
Sends a tensor to the destination rank in a blocking way
Source code in vllm/distributed/parallel_state.py
send_object ¶
Send the input object list to the destination rank.
Source code in vllm/distributed/parallel_state.py
send_tensor_dict ¶
send_tensor_dict(
tensor_dict: dict[str, Union[Tensor, Any]],
dst: Optional[int] = None,
all_gather_group: Optional[GroupCoordinator] = None,
) -> Optional[dict[str, Union[Tensor, Any]]]
Send the input tensor dictionary. NOTE: dst
is the local rank of the source rank.
Source code in vllm/distributed/parallel_state.py
StatelessProcessGroup dataclass
¶
A dataclass to hold a metadata store, and the rank, world_size of the group. Only use it to communicate metadata between processes. For data-plane communication, create NCCL-related objects.
Source code in vllm/distributed/utils.py
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 |
|
broadcast_recv_src_counter class-attribute
instance-attribute
¶
entries class-attribute
instance-attribute
¶
recv_src_counter class-attribute
instance-attribute
¶
send_dst_counter class-attribute
instance-attribute
¶
__init__ ¶
__init__(
rank: int,
world_size: int,
store: Store,
socket: Optional[socket],
data_expiration_seconds: int = 3600,
send_dst_counter: dict[int, int] = dict(),
recv_src_counter: dict[int, int] = dict(),
broadcast_send_counter: int = 0,
broadcast_recv_src_counter: dict[int, int] = dict(),
entries: deque[tuple[str, float]] = deque(),
) -> None
__post_init__ ¶
Source code in vllm/distributed/utils.py
all_gather_obj ¶
All gather an object from all ranks.
Source code in vllm/distributed/utils.py
barrier ¶
barrier(timeout: float = 30.0)
A robust barrier to synchronize all ranks.
Uses a multi-phase approach to ensure all processes reach the barrier before proceeding:
-
Each process signals it has reached the barrier
-
Each process signals that it has confirmed the arrival of all other ranks.
-
Rank 0 waits for all other ranks to signal their departure to ensure that all ranks have departed the barrier first.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout | float | Maximum time in seconds to wait for each phase (in seconds) | 30.0 |
Raises:
Type | Description |
---|---|
RuntimeError | If coordination fails or times out |
Source code in vllm/distributed/utils.py
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 |
|
broadcast_obj ¶
Broadcast an object from a source rank to all other ranks. It does not clean up after all ranks have received the object. Use it for limited times, e.g., for initialization.
Source code in vllm/distributed/utils.py
create staticmethod
¶
create(
host: str,
port: int,
rank: int,
world_size: int,
data_expiration_seconds: int = 3600,
store_timeout: int = 300,
) -> StatelessProcessGroup
A replacement for torch.distributed.init_process_group
that does not pollute the global state.
If we have process A and process B called torch.distributed.init_process_group
to form a group, and then we want to form another group with process A, B, C, D, it is not possible in PyTorch, because process A and process B have already formed a group, and process C and process D cannot join that group. This function is a workaround for this issue.
torch.distributed.init_process_group
is a global call, while this function is a stateless call. It will return a StatelessProcessGroup
object that can be used for exchanging metadata. With this function, process A and process B can call StatelessProcessGroup.create
to form a group, and then process A, B, C, and D can call StatelessProcessGroup.create
to form another group.
Source code in vllm/distributed/utils.py
expire_data ¶
Expire data that is older than data_expiration_seconds
seconds.
Source code in vllm/distributed/utils.py
recv_obj ¶
Receive an object from a source rank.
send_obj ¶
Send an object to a destination rank.
Source code in vllm/distributed/utils.py
all_gather ¶
Source code in vllm/distributed/parallel_state.py
all_gather_fake ¶
Source code in vllm/distributed/parallel_state.py
all_reduce ¶
Source code in vllm/distributed/parallel_state.py
all_reduce_fake ¶
broadcast_tensor_dict ¶
broadcast_tensor_dict(
tensor_dict: Optional[
dict[Any, Union[Tensor, Any]]
] = None,
src: int = 0,
)
Source code in vllm/distributed/communication_op.py
cleanup_dist_env_and_memory ¶
cleanup_dist_env_and_memory(shutdown_ray: bool = False)
Source code in vllm/distributed/parallel_state.py
destroy_distributed_environment ¶
destroy_model_parallel ¶
Set the groups to none and destroy them.
Source code in vllm/distributed/parallel_state.py
direct_register_custom_op ¶
direct_register_custom_op(
op_name: str,
op_func: Callable,
mutates_args: list[str],
fake_impl: Optional[Callable] = None,
target_lib: Optional[Library] = None,
dispatch_key: str = "CUDA",
tags: tuple[Tag, ...] = (),
)
torch.library.custom_op
can have significant overhead because it needs to consider complicated dispatching logic. This function directly registers a custom op and dispatches it to the CUDA backend. See https://gist.github.com/youkaichao/ecbea9ec9fc79a45d2adce1784d7a9a5 for more details.
By default, the custom op is registered to the vLLM library. If you want to register it to a different library, you can pass the library object to the target_lib
argument.
IMPORTANT: the lifetime of the operator is tied to the lifetime of the library object. If you want to bind the operator to a different library, make sure the library object is alive when the operator is used.
Source code in vllm/utils/__init__.py
divide ¶
Ensure that numerator is divisible by the denominator and return the division value.
ensure_divisibility ¶
Ensure that numerator is divisible by the denominator.
ensure_model_parallel_initialized ¶
ensure_model_parallel_initialized(
tensor_model_parallel_size: int,
pipeline_model_parallel_size: int,
backend: Optional[str] = None,
) -> None
Helper to initialize model parallel groups if they are not initialized, or ensure tensor-parallel and pipeline-parallel sizes are equal to expected values if the model parallel groups are initialized.
Source code in vllm/distributed/parallel_state.py
get_distributed_init_method ¶
get_dp_group ¶
get_dp_group() -> GroupCoordinator
get_ep_group ¶
get_ep_group() -> GroupCoordinator
get_node_count ¶
get_node_count() -> int
Return the total number of nodes in the distributed environment.
get_pipeline_model_parallel_group ¶
get_pp_group ¶
get_pp_group() -> GroupCoordinator
get_pp_indices ¶
Try to evenly distribute layers across partitions.
If the number of layers is not divisible by the number of partitions, the remaining layers are evenly distributed across all but the last partition. The last partition is excluded because it often contains an additional norm layer and we are attempting to balance compute.
If pp_size > 2
and the number of remaining layers is 0 < x <= pp_size - 2
then the remaining layers are evenly distributed across the middle partitions. The first and last partitions are excluded because they contain the input and output embeddings respectively and we are attempting to reduce maximum memory consumption across partitions.
Source code in vllm/distributed/utils.py
get_tcp_uri ¶
get_tensor_model_parallel_group ¶
get_tensor_model_parallel_rank ¶
get_tensor_model_parallel_world_size ¶
get_tp_group ¶
get_tp_group() -> GroupCoordinator
get_world_group ¶
get_world_group() -> GroupCoordinator
graph_capture ¶
graph_capture(device: device)
graph_capture
is a context manager which should surround the code that is capturing the CUDA graph. Its main purpose is to ensure that the some operations will be run after the graph is captured, before the graph is replayed. It returns a GraphCaptureContext
object which contains the necessary data for the graph capture. Currently, it only contains the stream that the graph capture is running on. This stream is set to the current CUDA stream when the context manager is entered and reset to the default stream when the context manager is exited. This is to ensure that the graph capture is running on a separate stream from the default stream, in order to explicitly distinguish the kernels to capture from other kernels possibly launched on background in the default stream.
Source code in vllm/distributed/parallel_state.py
in_the_same_node_as ¶
in_the_same_node_as(
pg: Union[ProcessGroup, StatelessProcessGroup],
source_rank: int = 0,
) -> list[bool]
This is a collective operation that returns if each rank is in the same node as the source rank. It tests if processes are attached to the same memory system (shared access to shared memory).
Source code in vllm/distributed/parallel_state.py
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 |
|
init_distributed_environment ¶
init_distributed_environment(
world_size: int = -1,
rank: int = -1,
distributed_init_method: str = "env://",
local_rank: int = -1,
backend: str = "nccl",
)
Source code in vllm/distributed/parallel_state.py
init_gloo_process_group ¶
init_gloo_process_group(
backend: Backend,
prefix_store: PrefixStore,
group_rank: int,
group_size: int,
timeout: timedelta,
) -> ProcessGroup
Stateless init ProcessGroup with gloo backend compatible with different torch versions.
Source code in vllm/distributed/utils.py
init_logger ¶
init_logger(name: str) -> _VllmLogger
The main purpose of this function is to ensure that loggers are retrieved in such a way that we can be sure the root vllm logger has already been configured.
Source code in vllm/logger.py
init_model_parallel_group ¶
init_model_parallel_group(
group_ranks: list[list[int]],
local_rank: int,
backend: str,
use_message_queue_broadcaster: bool = False,
group_name: Optional[str] = None,
) -> GroupCoordinator
Source code in vllm/distributed/parallel_state.py
init_world_group ¶
init_world_group(
ranks: list[int], local_rank: int, backend: str
) -> GroupCoordinator
Source code in vllm/distributed/parallel_state.py
initialize_model_parallel ¶
initialize_model_parallel(
tensor_model_parallel_size: int = 1,
pipeline_model_parallel_size: int = 1,
backend: Optional[str] = None,
) -> None
Initialize model parallel groups.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor_model_parallel_size | int | number of GPUs used for tensor model parallelism. | 1 |
pipeline_model_parallel_size | int | number of GPUs used for pipeline model parallelism. | 1 |
backend | Optional[str] | name of torch distributed communication backend. | None |
Let's say we have a total of 8 GPUs denoted by g0 ... g7 and we use 2 GPUs to parallelize the model tensor, and 4 GPUs to parallelize the model pipeline. The present function will create 4 tensor model-parallel groups and 2 pipeline model-parallel groups: 4 tensor model-parallel groups: [g0, g1], [g2, g3], [g4, g5], [g6, g7] 2 pipeline model-parallel groups: [g0, g2, g4, g6], [g1, g3, g5, g7] Note that for efficiency, the caller should make sure adjacent ranks are on the same DGX box. For example if we are using 2 DGX-1 boxes with a total of 16 GPUs, rank 0 to 7 belong to the first box and ranks 8 to 15 belong to the second box.
Source code in vllm/distributed/parallel_state.py
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 |
|
is_global_first_rank ¶
is_global_first_rank() -> bool
Check if the current process is the first rank globally across all parallelism strategies (PP, TP, DP, EP, etc.).
Unlike group-specific checks like get_tensor_model_parallel_rank() == 0
or get_pp_group().is_first_rank
, this function checks the global rank across all parallelism dimensions.
Returns:
Name | Type | Description |
---|---|---|
bool | bool | True if this is the global first rank (rank 0), False otherwise. Returns True if distributed is not initialized (single process). |
Source code in vllm/distributed/parallel_state.py
is_torch_equal_or_newer ¶
Check if the installed torch version is >= the target version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | str | a version string, like "2.6.0". | required |
Returns:
Type | Description |
---|---|
bool | Whether the condition meets. |
Source code in vllm/utils/__init__.py
model_parallel_is_initialized ¶
patch_tensor_parallel_group ¶
patch_tensor_parallel_group(tp_group: GroupCoordinator)
Patch the tp group temporarily until this function ends.
This method is for draft workers of speculative decoding to run draft model with different tp degree from that of target model workers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tp_group | GroupCoordinator | the tp group coordinator | required |
Source code in vllm/distributed/parallel_state.py
prepare_communication_buffer_for_model ¶
prepare_communication_buffer_for_model(model: Module)
Prepare the communication buffer for the model. Traditional communication libraries like NCCL are almost model agnostic. However, emerging new communication libraries like MoE all2all (DeepEP) usually allocate the communication buffer based on the model shape for optimal performance.
Source code in vllm/distributed/parallel_state.py
reduce_scatter ¶
Source code in vllm/distributed/parallel_state.py
reduce_scatter_fake ¶
Source code in vllm/distributed/parallel_state.py
resolve_obj_by_qualname ¶
Resolve an object by its fully-qualified class name.
Source code in vllm/utils/__init__.py
sched_yield ¶
split_tensor_along_last_dim ¶
split_tensor_along_last_dim(
tensor: Tensor,
num_partitions: int,
contiguous_split_chunks: bool = False,
) -> Sequence[Tensor]
Split a tensor along its last dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor | Tensor | input tensor. | required |
num_partitions | int | number of partitions to split the tensor | required |
contiguous_split_chunks | bool | If True, make each chunk contiguous in memory. | False |
Returns:
Type | Description |
---|---|
Sequence[Tensor] | A list of Tensors |
Source code in vllm/distributed/utils.py
stateless_destroy_torch_distributed_process_group ¶
Destroy ProcessGroup returned by stateless_init_torch_distributed_process_group().
Source code in vllm/distributed/utils.py
stateless_init_torch_distributed_process_group ¶
stateless_init_torch_distributed_process_group(
host: str,
port: int,
rank: int,
world_size: int,
backend: str,
) -> ProcessGroup
A replacement for torch.distributed.init_process_group
that does not pollute the global state. The created ProcessGroup object can be used for some operations such as allreduce
, because it does not depend on the global rank. However, some operations such as broadcast
cannot be used because it depends on the global rank.
TODO: ask for help from PyTorch team if we need the broadcast
operation.¶
This function is useful when we are not sure about the total number of processes in the process group. For example, we may have process 1, 2, ..., 8 who want to communicate, and process 9 might be the same process as process 1, or it might be a different process; process 10 might be the same process as process 5, or it might be a different process. In this case, how can we reliably form a communication channel within process 9 and 10, without affecting the communication channel within process 1, 2, ..., 8?
One possible solution is to figure out if process 9 and 10 are the same as process 1 and 5 beforehand, and then form a communication channel based on the information, adjusting the ranks and world_size etc. However, figuring out the information is not always easy, and it will interfere with the main communication channel.
Our solution is to always form a communication channel with process 1, 2, ..., 8, and then use this function to form another communication channel with process 9 and 10. This way, regardless of whether process 9 and 10 are the same as process 1 and 5, the main communication channel is always formed with process 1, 2, ..., 8, and the additional communication channel is formed with process 9 and 10.
Source code in vllm/distributed/utils.py
tensor_model_parallel_all_gather ¶
All-gather the input tensor across model parallel group.
tensor_model_parallel_all_reduce ¶
tensor_model_parallel_gather ¶
Gather the input tensor across model parallel group.
tensor_model_parallel_reduce_scatter ¶
Reduce-Scatter the input tensor across model parallel group.