Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
+18 -33
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Expert parallelism load balancer (EPLB) metrics and states.
"""Expert parallelism load balancer (EPLB) metrics and states.
# Glossary
@@ -74,9 +73,7 @@ def _compute_eplb_load_stats(
@dataclass
class EplbStats:
"""
Model stats used in EPLB rebalancing algorithm.
"""
"""Model stats used in EPLB rebalancing algorithm."""
global_expert_load_window: torch.Tensor
"""
@@ -233,9 +230,7 @@ class EplbModelState:
class EplbState:
"""
EplbState of each expert parallel model. Key is the model config hash.
"""
"""EplbState of each expert parallel model. Key is the model config hash."""
def __init__(self, parallel_config: ParallelConfig, device: torch.device):
self.parallel_config = parallel_config
@@ -305,14 +300,14 @@ class EplbState:
num_routed_experts: int,
num_redundant_experts: int,
) -> Sequence[int]:
"""
Build an initial expert arrangement using the following structure:
"""Build an initial expert arrangement using the following structure:
[original routed experts, redundant experts]
Returns:
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.
"""
global_physical_to_logical_map = list(range(num_routed_experts))
global_physical_to_logical_map += [
@@ -321,8 +316,7 @@ class EplbState:
return global_physical_to_logical_map
def validate_ep_configuration(self, new_model: MixtureOfExperts):
"""
Validate that the expert parallel configuration of
"""Validate that the expert parallel configuration of
the new model is the same as the existing models.
"""
if len(self.model_states) > 0:
@@ -361,9 +355,7 @@ class EplbState:
model: MixtureOfExperts,
model_config: ModelConfig,
):
"""
Build the initial EPLB state.
"""
"""Build the initial EPLB state."""
self.validate_ep_configuration(model)
self.is_async = self.parallel_config.eplb_config.use_async
@@ -534,6 +526,7 @@ class EplbState:
ubatch_slices: When DBO is active, a list of
``UBatchSlice`` objects describing each micro-batch's
token range. When ``None``, only ``tensors[0]`` is filled.
"""
model_state = self.model_states.get(compute_hash_cached(model_config))
if model_state is None or model_state.num_unpadded_tokens_tensors is None:
@@ -556,8 +549,7 @@ class EplbState:
is_profile: bool = False,
log_stats: bool = False,
) -> None:
"""
Step the EPLB state.
"""Step the EPLB state.
Args:
is_dummy (bool): If `True`, this is a dummy step and the load
@@ -574,6 +566,7 @@ class EplbState:
- `avg_tokens`: The average load across ranks.
- `max_tokens`: The maximum load across ranks.
- `balancedness`: The ratio of average load to maximum load.
"""
ep_group = get_ep_group().device_group
if is_profile:
@@ -752,8 +745,7 @@ class EplbState:
is_profile: bool = False,
rank_mapping: dict[int, int] | None = None,
) -> torch.Tensor | None:
"""
Rearrange the experts according to the current load.
"""Rearrange the experts according to the current load.
Args:
is_profile (bool): If `True`, perform a dummy rearrangement.
@@ -761,8 +753,8 @@ class EplbState:
no memory movement will be performed. Default is False.
rank_mapping (dict[int, int] | None): The rank mapping
when scaling is done in EEP.
"""
"""
ep_group = get_ep_group().device_group
ep_rank = ep_group.rank()
@@ -1033,9 +1025,7 @@ class EplbState:
return int(flag.item()) == device_group.size()
def _allreduce_list(self, tensor_list: list[torch.Tensor]) -> list[torch.Tensor]:
"""
All-reduce a list of tensors.
"""
"""All-reduce a list of tensors."""
ep_group = get_ep_group().device_group
if len(tensor_list) == 1:
all_reduce(tensor_list[0], group=ep_group)
@@ -1060,8 +1050,7 @@ class EplbState:
return all_reduce_list
def _sync_load_pass(self) -> list[torch.Tensor]:
"""
Sync the expert load pass across all ranks for log stats.
"""Sync the expert load pass across all ranks for log stats.
Doesn't update the expert load pass in eplb_model_state.
"""
load_pass_list = []
@@ -1250,8 +1239,7 @@ def compute_logical_maps(
physical_to_logical_map: torch.Tensor,
num_logical_experts: int,
) -> tuple[torch.Tensor, torch.Tensor]:
"""
Derive logical_to_physical_map and logical_replica_count from
"""Derive logical_to_physical_map and logical_replica_count from
physical_to_logical_map.
Args:
@@ -1264,6 +1252,7 @@ def compute_logical_maps(
physical slots per logical expert; -1 where unused
logical_replica_count: [num_layers, num_logical_experts], number of
physical replicas per logical expert
"""
device = physical_to_logical_map.device
assert physical_to_logical_map.device.type == "cpu"
@@ -1339,13 +1328,11 @@ def _commit_eplb_maps_for_layer(
new_physical_to_logical_map: torch.Tensor,
layer: int,
) -> None:
"""
Per-layer version of _commit_eplb_maps that's used by the sync portion of EPLB
"""Per-layer version of _commit_eplb_maps that's used by the sync portion of EPLB
when running async EPLB. Copies all of the new_* maps into model_state. After this
function completes, the new mappings will become the current mappings and will be
visible to the model.
"""
# Commit physical_to_logical_map
src = new_physical_to_logical_map
dst = model_state.physical_to_logical_map[layer]
@@ -1376,12 +1363,10 @@ def _commit_eplb_maps(
model_state: EplbModelState,
new_physical_to_logical_map: torch.Tensor,
) -> None:
"""
Copies all of the new_* maps into model_state. After this function completes,
"""Copies all of the new_* maps into model_state. After this function completes,
the new mappings will become the current mappings and will be visible to the
model.
"""
# Commit physical_to_logical_map
src = new_physical_to_logical_map
dst = model_state.physical_to_logical_map