vllm.distributed.eplb.eplb_state
Expert parallelism load balancer (EPLB) metrics and states.
Glossary¶
- Logical Expert: An expert that is part of the model's logical structure. It holds a set of weights and is replicated across multiple physical experts.
- Redundant Expert: To achieve load balancing, for some popular logical experts, we create additional copies of the expert weights. During inference, each of these copies can be routed to by the same set of tokens.
- Physical Expert: An expert that is instantiated on a specific device. It is a replica of a logical expert and can be rearranged across devices. I.e., one logical expert may have multiple sets of weights initialized on different devices, and each of these sets is a physical expert.
- Local Physical Expert: A physical expert that is instantiated on the current device.
For example: DeepSeek-R1 has 256 logical experts, so each MoE layer has 256 sets of linear layer weights in the model parameters. If we add 32 redundant experts, DeepSeek-R1 will have 256 + 32 = 288 physical experts in total. And when deploying, we'll have 288 sets of linear layer weights for each MoE layer. If we have 32 EP ranks, then each GPU will hold 288 / 32 = 9 local physical experts.
EplbState
dataclass
¶
EPLB metrics.
Source code in vllm/distributed/eplb/eplb_state.py
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 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 420 421 422 423 424 425 426 427 428 429 430 431 432 |
|
expert_load_pass
instance-attribute
¶
expert_load_pass: Tensor
Expert load during this forward pass. We use the token count each expert processes as the load.
Shape: (num_moe_layers, num_local_physical_experts)
expert_load_window
instance-attribute
¶
expert_load_window: Tensor
A sliding window of expert load.
Shape: (window_size, num_moe_layers, num_local_physical_experts)
expert_load_window_size
class-attribute
instance-attribute
¶
expert_load_window_size: int = 0
Size of the expert load sliding window. This is a constant and is taken from the config.
expert_load_window_step
class-attribute
instance-attribute
¶
expert_load_window_step: int = 0
Current step in the sliding window.
Different from expert_rearrangement_step
, each EP rank may have its own
expert_load_window_step
.
expert_rearrangement_step
class-attribute
instance-attribute
¶
expert_rearrangement_step: int = 0
Steps after last rearrangement. Will trigger a rearrangement if it exceeds the threshold.
NOTE: Keep in mind that all EP ranks need to have the same
expert_rearrangement_step
value to ensure synchronization.
Otherwise, the rearrangement will hang at collective
communication calls.
expert_rearrangement_step_interval
class-attribute
instance-attribute
¶
expert_rearrangement_step_interval: int = 0
Interval for expert rearrangement steps. This is a constant and is taken from the config.
logical_replica_count
instance-attribute
¶
logical_replica_count: Tensor
Number of replicas for each logical expert.
This is exactly the non--1
count in the logical_to_physical_map
.
Shape: (num_moe_layers, num_logical_experts)
Example¶
For a 2-layer MoE model with 6 physical experts and 4 logical experts on 3 EP ranks, the count could look like this:
``` [[2, 2, 1, 1], [3, 1, 1, 1]]
logical_to_physical_map
instance-attribute
¶
logical_to_physical_map: Tensor
Mapping from logical experts to physical experts.
This is a sparse matrix, where -1 indicates no mapping.
Shape: (num_moe_layers, num_logical_experts, num_redundant_experts + 1)
Example¶
For a 2-layer MoE model with 6 physical experts and 4 logical experts on 3 EP ranks, the mapping could look like this:
physical_to_logical_map
instance-attribute
¶
physical_to_logical_map: Tensor
Mapping from physical experts to logical experts.
Shape: (num_moe_layers, num_physical_experts)
Example¶
For a 2-layer MoE model with 6 physical experts and 4 logical experts on 3 EP ranks, the mapping could look like this:
__init__
¶
__init__(
physical_to_logical_map: Tensor,
logical_to_physical_map: Tensor,
logical_replica_count: Tensor,
expert_load_pass: Tensor,
expert_load_window: Tensor,
expert_load_window_step: int = 0,
expert_load_window_size: int = 0,
expert_rearrangement_step: int = 0,
expert_rearrangement_step_interval: int = 0,
) -> None
build
classmethod
¶
build(
model: MixtureOfExperts,
device: device,
parallel_config: ParallelConfig,
) -> EplbState
Build the initial EPLB state.
Source code in vllm/distributed/eplb/eplb_state.py
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 |
|
build_initial_global_physical_to_logical_map
staticmethod
¶
build_initial_global_physical_to_logical_map(
num_routed_experts: int, num_redundant_experts: int
) -> Sequence[int]
Build an initial expert arrangement using the following structure: [original routed experts, redundant experts]
Returns:
Name | Type | Description |
---|---|---|
physical_to_logical_map |
Sequence[int]
|
A list of integers, where each integer is the index of the logical expert that the corresponding physical expert maps to. |
Source code in vllm/distributed/eplb/eplb_state.py
rearrange
¶
rearrange(
model: MixtureOfExperts, is_profile: bool = False
) -> None
Rearrange the experts according to the current load.
Source code in vllm/distributed/eplb/eplb_state.py
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 |
|
step
¶
step(
model: MixtureOfExperts,
is_dummy: bool = False,
is_profile: bool = False,
log_stats: bool = False,
) -> None
Step the EPLB state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
MixtureOfExperts
|
The MoE model. |
required |
is_dummy
|
bool
|
If |
False
|
is_profile
|
bool
|
If |
False
|
log_stats
|
bool
|
If |
False
|
Stats¶
The metrics are all summed up across layers.
- `avg_tokens`: The average load across ranks.
- `max_tokens`: The maximum load across ranks.
- `balancedness`: The ratio of average load to maximum load.
Source code in vllm/distributed/eplb/eplb_state.py
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 |
|