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.
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: Optional[dict[int, int]] = 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 | Optional[dict[int, int]] | A dictionary mapping old rank to new rank. | None |
Source code in vllm/distributed/eplb/rebalance_execute.py
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 |
|
shuffle_layer ¶
shuffle_layer(
num_local_experts: int,
ep_rank: int,
old_indices: Sequence[int],
new_indices: Sequence[int],
expert_weights: Iterable[Tensor],
expert_weights_buffer: Sequence[Tensor],
ep_group: ProcessGroup,
) -> None
Perform expert weights rearrangement of one layer.
Source code in vllm/distributed/eplb/rebalance_execute.py
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 |
|