vllm.distributed.eplb.rebalance_execute ¶
The actual execution of the rearrangement.
This involves the exchange of expert weights between GPUs.
RecvMetadata dataclass ¶
Metadata describing remote receives during EPLB rebalancing.
Source code in vllm/distributed/eplb/rebalance_execute.py
recv_dst_rows instance-attribute ¶
recv_dst_rows: ndarray
Target expert indices (num_local_experts,) in local tensors to send.
recv_expert_ids instance-attribute ¶
recv_expert_ids: ndarray
Expert ids (num_local_experts,) of remote primary experts.
_map_new_expert_indices_with_rank_mapping ¶
_map_new_expert_indices_with_rank_mapping(
new_global_expert_indices: Tensor,
rank_mapping: dict[int, int],
) -> Tensor
Source code in vllm/distributed/eplb/rebalance_execute.py
_map_old_expert_indices_with_rank_mapping ¶
_map_old_expert_indices_with_rank_mapping(
old_global_expert_indices: Tensor,
rank_mapping: dict[int, int],
new_ep_size: int,
) -> Tensor
Map the old global expert indices to the new global expert indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_global_expert_indices | Tensor | Shape (num_layers, old_ep_size * num_local_physical_experts). | required |
rank_mapping | dict[int, int] | Mapping from old rank to new rank. | required |
new_ep_size | int | New expert parallelism size. | required |
Returns:
| Type | Description |
|---|---|
Tensor | Mapped expert indices with shape |
Tensor | (num_layers, new_ep_size * num_local_physical_experts). |
Source code in vllm/distributed/eplb/rebalance_execute.py
get_ep_ranks_with_experts_batch ¶
get_ep_ranks_with_experts_batch(
expert_ids: ndarray,
num_local_experts: int,
old_indices: ndarray,
new_indices: ndarray,
) -> tuple[dict[int, list[int]], dict[int, list[int]]]
Get the ranks of the experts that need to be exchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expert_ids | ndarray | 1D array of expert indices to query. | required |
num_local_experts | int | The number of local experts. | required |
old_indices | ndarray | The old indices of the experts. | required |
new_indices | ndarray | The new indices of the experts. | required |
Returns:
| Type | Description |
|---|---|
dict[int, list[int]] | A tuple of two dictionaries mapping expert_id to: |
dict[int, list[int]] |
|
tuple[dict[int, list[int]], dict[int, list[int]]] |
|
Source code in vllm/distributed/eplb/rebalance_execute.py
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
move_from_buffer ¶
move_from_buffer(
expert_weights: Iterable[Tensor],
expert_weights_buffers: list[Tensor],
is_unchanged: ndarray,
is_received_locally: ndarray,
recv_metadata: RecvMetadata,
new_indices: ndarray,
ep_rank: int,
) -> None
Copies expert weights from communication buffers back to the target weight tensors after EPLB rebalancing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expert_weights | Iterable[Tensor] | List of the actual MoE layer weights used in the execution. | required |
expert_weights_buffers | list[Tensor] | Intermediate buffers containing the experts weights after the transfer is completed. | required |
is_unchanged | ndarray | (num_local_experts,), True where an expert row is unchanged. | required |
is_received_locally | ndarray | (num_local_experts,), True where a row is updated locally. | required |
recv_metadata | RecvMetadata | RecvMetadata containing remote receive metadata. | required |
new_indices | ndarray | (num_experts_total,) mapping from local rows to desired (possibly global) expert id, after rebalance. | required |
ep_rank | int | Rank of the process in the expert parallel group. | required |
Source code in vllm/distributed/eplb/rebalance_execute.py
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 | |
move_to_buffer ¶
move_to_buffer(
num_local_experts: int,
old_indices: ndarray,
new_indices: ndarray,
expert_weights: Iterable[Tensor],
expert_weights_buffers: Sequence[Tensor],
cuda_stream: Stream | None,
ep_group: ProcessGroup,
) -> MoveToBufferResult
Rearranges expert weights during EPLB rebalancing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_local_experts | int | Number of local experts. | required |
old_indices | ndarray | (num_experts_total,) ndarray of current (old) global-to-local expert assignments. | required |
new_indices | ndarray | (num_experts_total,) ndarray of desired (new) global-to-local assignments after rebalance. | required |
expert_weights | Iterable[Tensor] | Original expert weights for the layer. | required |
expert_weights_buffers | Sequence[Tensor] | Intermediate buffers (one per tensor). | required |
cuda_stream | Stream | None | CUDA stream for async copies (can be None for sync mode). | required |
ep_group | ProcessGroup | Distributed process group for expert parallel comms. | required |
Returns:
| Name | Type | Description |
|---|---|---|
is_unchanged | ndarray | (num_local_experts,), True where an expert row is unchanged after rebalance. |
is_received_locally | ndarray | (num_local_experts,), True where a row can be updated from local data. |
RecvMetadata | MoveToBufferResult | Metadata needed for completing remote weight transfers. |
Source code in vllm/distributed/eplb/rebalance_execute.py
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 | |
rearrange_expert_weights_inplace ¶
rearrange_expert_weights_inplace(
old_global_expert_indices: Tensor,
new_global_expert_indices: Tensor,
expert_weights: Sequence[Iterable[Tensor]],
ep_group: ProcessGroup,
is_profile: bool = False,
rank_mapping: dict[int, int] | None = None,
) -> None
Rearranges the expert weights in place according to the new expert indices.
The value of the indices arguments are logical indices of the experts, while keys are physical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_global_expert_indices | Tensor | Shape (num_moe_layers, num_physical_experts). | required |
new_global_expert_indices | Tensor | Shape (num_moe_layers, num_physical_experts). | required |
expert_weights | Sequence[Iterable[Tensor]] | A sequence of shape (num_moe_layers)(weight_count) of tensors of shape (num_local_physical_experts, hidden_size_i). For example, a linear layer may have up and down projection, so weight_count = 2. Each weight's hidden size can be different. | required |
ep_group | ProcessGroup | The device process group for expert parallelism. | required |
is_profile | bool | If | False |
rank_mapping | dict[int, int] | None | A dictionary mapping old rank to new rank. | None |
Source code in vllm/distributed/eplb/rebalance_execute.py
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 | |
transfer_layer async ¶
transfer_layer(
old_global_expert_indices: Tensor,
new_global_expert_indices: Tensor,
expert_weights: Sequence[Iterable[Tensor]],
expert_weights_buffer: Sequence[Tensor],
ep_group: ProcessGroup,
is_profile: bool = False,
layer: int = 0,
cuda_stream: Stream | None = None,
rank_mapping: dict[int, int] | None = None,
) -> MoveToBufferResult
Rearranges the expert weights in place according to the new expert indices.
The value of the indices arguments are logical indices of the experts, while keys are physical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_global_expert_indices | Tensor | Shape (num_moe_layers, num_physical_experts). | required |
new_global_expert_indices | Tensor | Shape (num_moe_layers, num_physical_experts). | required |
expert_weights | Sequence[Iterable[Tensor]] | A sequence of shape (num_moe_layers)(weight_count) of tensors of shape (num_local_physical_experts, hidden_size_i). For example, a linear layer may have up and down projection, so weight_count = 2. Each weight's hidden size can be different. | required |
ep_group | ProcessGroup | The device process group for expert parallelism. | required |
is_profile | bool | If | False |
Returns:
| Name | Type | Description |
|---|---|---|
is_unchanged | ndarray | (1, num_local_experts), True where expert is left unchanged. |
is_received_locally | ndarray | (1, num_local_experts), True where expert can be received locally. |
RecvMetadata | MoveToBufferResult | Metadata needed for completing remote weight transfers. |