vllm.distributed.eplb.rebalance_execute
The actual execution of the rearrangement.
This involves the exchange of expert weights between GPUs.
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,
) -> 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
|
Source code in vllm/distributed/eplb/rebalance_execute.py
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
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 |
|