vllm.distributed.eplb.rebalance_execute ¶
The actual execution of the rearrangement.
This involves the exchange of expert weights between GPUs.
_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_expert ¶
get_ep_ranks_with_expert(
idx: int,
num_local_experts: int,
old_indices: Sequence[int],
new_indices: Sequence[int],
) -> tuple[MutableSequence[int], MutableSequence[int]]
Get the ranks of the experts that need to be exchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx | int | The index of the expert. | required |
num_local_experts | int | The number of local experts. | required |
old_indices | Sequence[int] | The old indices of the experts. | required |
new_indices | Sequence[int] | The new indices of the experts. | required |
Returns:
| Type | Description |
|---|---|
MutableSequence[int] | A tuple of two lists: |
MutableSequence[int] |
|
tuple[MutableSequence[int], MutableSequence[int]] |
|
Source code in vllm/distributed/eplb/rebalance_execute.py
global_idx_to_rank ¶
idx_global_to_local ¶
Convert a global expert index to a local expert index.
idx_local_to_global ¶
Convert a local expert index to a global expert index.
move_from_buffer ¶
move_from_buffer(
expert_weights: Iterable[Tensor],
expert_weights_buffer: list[Tensor],
is_unchanged: list[bool],
is_received_locally: list[bool],
experts_recv_loc: dict[int, int],
new_indices: Sequence[int],
ep_group: ProcessGroup,
) -> None
Source code in vllm/distributed/eplb/rebalance_execute.py
move_to_buffer ¶
move_to_buffer(
num_local_experts: int,
old_indices: Sequence[int],
new_indices: Sequence[int],
expert_weights: Iterable[Tensor],
expert_weights_buffer: Sequence[Tensor],
cuda_stream: Stream | None,
ep_group: ProcessGroup,
) -> tuple[list[bool], list[bool], dict[int, int]]
Perform expert weights rearrangement of one layer.
Source code in vllm/distributed/eplb/rebalance_execute.py
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 | |
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
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 | |
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,
) -> tuple[list[bool], list[bool], dict[int, int]]
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 |