vllm.distributed.eplb
Expert parallelism load balancer (EPLB).
Modules:
| Name | Description |
|---|---|
eplb_state |
Expert parallelism load balancer (EPLB) metrics and states. |
rebalance_algo |
Expert parallelism load balancer (EPLB) for vLLM. |
rebalance_execute |
The actual execution of the rearrangement. |
EplbState
dataclass
¶
EPLB metrics.
Source code in vllm/distributed/eplb/eplb_state.py
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 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 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 | |
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,
global_expert_load: Optional[Tensor] = None,
old_global_expert_indices: Optional[Tensor] = None,
rank_mapping: Optional[dict[int, int]] = None,
) -> EplbState
Build the initial EPLB state.
Source code in vllm/distributed/eplb/eplb_state.py
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 | |
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,
execute_shuffle: bool = True,
global_expert_load: Optional[Tensor] = None,
rank_mapping: Optional[dict[int, int]] = None,
) -> None
Rearrange the experts according to the current load.
Source code in vllm/distributed/eplb/eplb_state.py
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 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 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 | |
recv_state
staticmethod
¶
Receive the expert load and old placement from the master rank.
Source code in vllm/distributed/eplb/eplb_state.py
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
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 | |
MixtureOfExperts
¶
Bases: Protocol
Check if the model is a mixture of experts (MoE) model.
Source code in vllm/model_executor/models/interfaces.py
expert_weights
instance-attribute
¶
expert_weights: MutableSequence[Iterable[Tensor]]
Expert weights saved in this rank.
The first dimension is the layer, and the second dimension is different parameters in the layer, e.g. up/down projection weights.
num_expert_groups
instance-attribute
¶
num_expert_groups: int
Number of expert groups in this model.
num_local_physical_experts
instance-attribute
¶
num_local_physical_experts: int
Number of local physical experts in this model.
num_logical_experts
instance-attribute
¶
num_logical_experts: int
Number of logical experts in this model.
num_physical_experts
instance-attribute
¶
num_physical_experts: int
Number of physical experts in this model.
num_redundant_experts
instance-attribute
¶
num_redundant_experts: int
Number of redundant experts in this model.
num_routed_experts
instance-attribute
¶
num_routed_experts: int
Number of routed experts in this model.
num_shared_experts
instance-attribute
¶
num_shared_experts: int
Number of shared experts in this model.
set_eplb_state
¶
set_eplb_state(
expert_load_view: Tensor,
logical_to_physical_map: Tensor,
logical_replica_count: Tensor,
) -> None
Register the EPLB state in the MoE model.
Since these are views of the actual EPLB state, any changes made by the EPLB algorithm are automatically reflected in the model's behavior without requiring additional method calls to set new states.
You should also collect model's expert_weights here instead of in
the weight loader, since after initial weight loading, further
processing like quantization may be applied to the weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expert_load_view
|
Tensor
|
A view of the expert load metrics tensor. |
required |
logical_to_physical_map
|
Tensor
|
Mapping from logical to physical experts. |
required |
logical_replica_count
|
Tensor
|
Count of replicas for each logical expert. |
required |
Source code in vllm/model_executor/models/interfaces.py
ParallelConfig
¶
Configuration for the distributed execution.
Source code in vllm/config.py
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 | |
data_parallel_backend
class-attribute
instance-attribute
¶
data_parallel_backend: str = 'mp'
Backend to use for data parallel, either "mp" or "ray".
data_parallel_external_lb
class-attribute
instance-attribute
¶
data_parallel_external_lb: bool = False
Whether to use "external" DP LB mode. Applies only to online serving and when data_parallel_size > 0. This is useful for a "one-pod-per-rank" wide-EP setup in Kuberentes. Set implicitly when --data-parallel-rank is provided explicitly to vllm serve.
data_parallel_hybrid_lb
class-attribute
instance-attribute
¶
data_parallel_hybrid_lb: bool = False
Whether to use "hybrid" DP LB mode. Applies only to online serving and when data_parallel_size > 0. Enables running an AsyncLLM and API server on a "per-node" basis where vLLM load balances between local data parallel ranks, but an external LB balances between vLLM nodes/replicas. Set explicitly in conjunction with --data-parallel-start-rank.
data_parallel_master_ip
class-attribute
instance-attribute
¶
data_parallel_master_ip: str = '127.0.0.1'
IP of the data parallel master.
data_parallel_master_port
class-attribute
instance-attribute
¶
data_parallel_master_port: int = 29500
Port of the data parallel master.
data_parallel_rank
class-attribute
instance-attribute
¶
data_parallel_rank: int = 0
Rank of the data parallel group.
data_parallel_rank_local
class-attribute
instance-attribute
¶
Local rank of the data parallel group, set only in SPMD mode.
data_parallel_rpc_port
class-attribute
instance-attribute
¶
data_parallel_rpc_port: int = 29550
Port for data parallel messaging.
data_parallel_size
class-attribute
instance-attribute
¶
data_parallel_size: int = 1
Number of data parallel groups. MoE layers will be sharded according to the product of the tensor parallel size and data parallel size.
data_parallel_size_local
class-attribute
instance-attribute
¶
data_parallel_size_local: int = 1
Number of local data parallel groups.
disable_custom_all_reduce
class-attribute
instance-attribute
¶
disable_custom_all_reduce: bool = False
Disable the custom all-reduce kernel and fall back to NCCL.
distributed_executor_backend
class-attribute
instance-attribute
¶
distributed_executor_backend: Optional[
Union[DistributedExecutorBackend, type[ExecutorBase]]
] = None
Backend to use for distributed model workers, either "ray" or "mp" (multiprocessing). If the product of pipeline_parallel_size and tensor_parallel_size is less than or equal to the number of GPUs available, "mp" will be used to keep processing on a single host. Otherwise, this will default to "ray" if Ray is installed and fail otherwise. Note that tpu only support Ray for distributed inference.
enable_eplb
class-attribute
instance-attribute
¶
enable_eplb: bool = False
Enable expert parallelism load balancing for MoE layers.
enable_expert_parallel
class-attribute
instance-attribute
¶
enable_expert_parallel: bool = False
Use expert parallelism instead of tensor parallelism for MoE layers.
enable_multimodal_encoder_data_parallel
class-attribute
instance-attribute
¶
enable_multimodal_encoder_data_parallel: bool = False
Use data parallelism instead of tensor parallelism for vision encoder. Only support LLama4 for now
eplb_log_balancedness
class-attribute
instance-attribute
¶
eplb_log_balancedness: bool = False
Log the balancedness each step of expert parallelism. This is turned off by default since it will cause communication overhead.
eplb_step_interval
class-attribute
instance-attribute
¶
eplb_step_interval: int = 3000
Interval for rearranging experts in expert parallelism.
Note that if this is greater than the EPLB window size, only the metrics
of the last eplb_window_size steps will be used for rearranging experts.
eplb_window_size
class-attribute
instance-attribute
¶
eplb_window_size: int = 1000
Window size for expert load recording.
max_parallel_loading_workers
class-attribute
instance-attribute
¶
Maximum number of parallel loading workers when loading model sequentially in multiple batches. To avoid RAM OOM when using tensor parallel and large models.
num_redundant_experts
class-attribute
instance-attribute
¶
num_redundant_experts: int = 0
Number of redundant experts to use for expert parallelism.
pipeline_parallel_size
class-attribute
instance-attribute
¶
pipeline_parallel_size: int = 1
Number of pipeline parallel groups.
placement_group
class-attribute
instance-attribute
¶
placement_group: Optional[PlacementGroup] = None
ray distributed model workers placement group.
ray_workers_use_nsight
class-attribute
instance-attribute
¶
ray_workers_use_nsight: bool = False
Whether to profile Ray workers with nsight, see https://docs.ray.io/en/latest/ray-observability/user-guides/profiling.html#profiling-nsight-profiler.
sd_worker_cls
class-attribute
instance-attribute
¶
sd_worker_cls: str = 'auto'
The full name of the worker class to use for speculative decoding. If "auto", the worker class will be determined based on the platform.
tensor_parallel_size
class-attribute
instance-attribute
¶
tensor_parallel_size: int = 1
Number of tensor parallel groups.
worker_cls
class-attribute
instance-attribute
¶
worker_cls: str = 'auto'
The full name of the worker class to use. If "auto", the worker class will be determined based on the platform.
worker_extension_cls
class-attribute
instance-attribute
¶
worker_extension_cls: str = ''
The full name of the worker extension class to use. The worker extension class is dynamically inherited by the worker class. This is used to inject new attributes and methods to the worker class for use in collective_rpc calls.
world_size
class-attribute
instance-attribute
¶
world_size is TPxPP, it affects the number of workers we create.
world_size_across_dp
property
¶
world_size_across_dp: int
world_size_across_dp is TPxPPxDP, it is the size of the world including data parallelism.
__post_init__
¶
Source code in vllm/config.py
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 | |
_verify_args
¶
_verify_args() -> Self
Source code in vllm/config.py
compute_hash
¶
Provide a hash that uniquely identifies all the configs that affect the structure of the computation graph from input ids/embeddings to the final hidden states, excluding anything before input ids/embeddings and after the final hidden states.
Source code in vllm/config.py
get_next_dp_init_port
¶
get_next_dp_init_port() -> int
We might need to initialize process groups in multiple processes that is related to data parallelism, e.g. both in the worker and in the engine, which can live in different processes. To avoid port conflicts, we increment the port number each time we need to initialize a new process group related to data parallelism.
Source code in vllm/config.py
has_unfinished_dp
staticmethod
¶
Source code in vllm/config.py
stateless_init_dp_group
¶
Source code in vllm/config.py
sync_kv_cache_memory_size
staticmethod
¶
Source code in vllm/config.py
StatelessProcessGroup
dataclass
¶
A dataclass to hold a metadata store, and the rank, world_size of the group. Only use it to communicate metadata between processes. For data-plane communication, create NCCL-related objects.
Source code in vllm/distributed/utils.py
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 | |
broadcast_recv_src_counter
class-attribute
instance-attribute
¶
entries
class-attribute
instance-attribute
¶
recv_src_counter
class-attribute
instance-attribute
¶
send_dst_counter
class-attribute
instance-attribute
¶
__init__
¶
__init__(
rank: int,
world_size: int,
store: Store,
socket: Optional[socket],
data_expiration_seconds: int = 3600,
send_dst_counter: dict[int, int] = dict(),
recv_src_counter: dict[int, int] = dict(),
broadcast_send_counter: int = 0,
broadcast_recv_src_counter: dict[int, int] = dict(),
entries: deque[tuple[str, float]] = deque(),
) -> None
__post_init__
¶
Source code in vllm/distributed/utils.py
all_gather_obj
¶
All gather an object from all ranks.
Source code in vllm/distributed/utils.py
barrier
¶
barrier(timeout: float = 30.0)
A robust barrier to synchronize all ranks.
Uses a multi-phase approach to ensure all processes reach the barrier before proceeding:
-
Each process signals it has reached the barrier
-
Each process signals that it has confirmed the arrival of all other ranks.
-
Rank 0 waits for all other ranks to signal their departure to ensure that all ranks have departed the barrier first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Maximum time in seconds to wait for each phase (in seconds) |
30.0
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If coordination fails or times out |
Source code in vllm/distributed/utils.py
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 | |
broadcast_obj
¶
Broadcast an object from a source rank to all other ranks. It does not clean up after all ranks have received the object. Use it for limited times, e.g., for initialization.
Source code in vllm/distributed/utils.py
create
staticmethod
¶
create(
host: str,
port: int,
rank: int,
world_size: int,
data_expiration_seconds: int = 3600,
store_timeout: int = 300,
) -> StatelessProcessGroup
A replacement for torch.distributed.init_process_group that does not
pollute the global state.
If we have process A and process B called torch.distributed.init_process_group
to form a group, and then we want to form another group with process A, B, C,
D, it is not possible in PyTorch, because process A and process B have already
formed a group, and process C and process D cannot join that group. This
function is a workaround for this issue.
torch.distributed.init_process_group is a global call, while this function
is a stateless call. It will return a StatelessProcessGroup object that can be
used for exchanging metadata. With this function, process A and process B
can call StatelessProcessGroup.create to form a group, and then process A, B,
C, and D can call StatelessProcessGroup.create to form another group.
Source code in vllm/distributed/utils.py
expire_data
¶
Expire data that is older than data_expiration_seconds seconds.
Source code in vllm/distributed/utils.py
recv_obj
¶
Receive an object from a source rank.
send_obj
¶
Send an object to a destination rank.
Source code in vllm/distributed/utils.py
get_ep_group
¶
get_ep_group() -> GroupCoordinator
get_node_count
¶
get_node_count() -> int
Return the total number of nodes in the distributed environment.
in_the_same_node_as
¶
in_the_same_node_as(
pg: Union[ProcessGroup, StatelessProcessGroup],
source_rank: int = 0,
) -> list[bool]
This is a collective operation that returns if each rank is in the same node as the source rank. It tests if processes are attached to the same memory system (shared access to shared memory).
Source code in vllm/distributed/parallel_state.py
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 | |
init_logger
¶
init_logger(name: str) -> _VllmLogger
The main purpose of this function is to ensure that loggers are retrieved in such a way that we can be sure the root vllm logger has already been configured.
Source code in vllm/logger.py
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 | |
rebalance_experts
¶
rebalance_experts(
weight: Tensor,
num_replicas: int,
num_groups: int,
num_nodes: int,
num_gpus: int,
) -> tuple[Tensor, Tensor, Tensor]
Entry point for expert-parallelism load balancer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
Tensor
|
[layers, num_logical_experts], the load statistics for all logical experts |
required |
num_replicas
|
int
|
number of physical experts, must be a multiple of
|
required |
num_groups
|
int
|
number of expert groups |
required |
num_nodes
|
int
|
number of server nodes, where the intra-node network (e.g, NVLink) is faster |
required |
num_gpus
|
int
|
number of GPUs, must be a multiple of |
required |
Returns:
| Name | Type | Description |
|---|---|---|
physical_to_logical_map |
Tensor
|
[layers, num_replicas], the expert index of each replica |
logical_to_physical_map |
Tensor
|
[layers, num_logical_experts, X], the replica indices for each expert |
expert_count |
Tensor
|
[layers, num_logical_experts], number of physical replicas for each logical expert |