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
@@ -16,8 +16,7 @@ from vllm.model_executor.layers.fused_moe.router.fused_topk_router import (
class AiterSharedRoutedFusedMoERouter(BaseRouter):
"""
ROCm AITER router for models with fused shared experts (e.g. Qwen3-MoE).
"""ROCm AITER router for models with fused shared experts (e.g. Qwen3-MoE).
When the AITER topk_softmax kernel supports sigmoid fusion, the routing
softmax and shared-expert sigmoid are computed in a single kernel launch.
@@ -157,8 +157,7 @@ else:
class BaseRouter(FusedMoERouter):
"""
Base router class that provides common functionality for all router implementations.
"""Base class providing common functionality for all router implementations.
This class implements the template method pattern where select_experts() handles
common pre-processing and post-processing, delegating the actual routing logic
@@ -171,11 +170,11 @@ class BaseRouter(FusedMoERouter):
global_num_experts: int,
eplb_state: EplbLayerState | None = None,
):
"""
Args:
top_k: Number of experts to select per token
global_num_experts: Total number of experts
eplb_state: Optional EPLBLayerState for load balancing
"""Args:
top_k: Number of experts to select per token
global_num_experts: Total number of experts
eplb_state: Optional EPLBLayerState for load balancing
"""
super().__init__(eplb_state=eplb_state)
self.top_k = top_k
@@ -241,8 +240,7 @@ class BaseRouter(FusedMoERouter):
*,
input_ids: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""
Compute the actual routing logic.
"""Compute the actual routing logic.
This method must be implemented by subclasses to provide the specific
routing algorithm (e.g., grouped_topk, fused_topk, custom routing, etc.).
@@ -251,9 +249,11 @@ class BaseRouter(FusedMoERouter):
hidden_states: Input hidden states
router_logits: Router logits for expert selection
indices_type: Desired dtype for expert indices (may be None)
input_ids: Token ids, for routers that condition on them
Returns:
tuple of (topk_weights, topk_ids)
"""
raise NotImplementedError
@@ -265,8 +265,7 @@ class BaseRouter(FusedMoERouter):
*,
input_ids: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""
Route the input hidden states to the top-k experts based on the
"""Route the input hidden states to the top-k experts based on the
router logits.
This method implements the template method pattern:
@@ -283,6 +282,7 @@ class BaseRouter(FusedMoERouter):
**Compatibility**: When EPLB is not enabled, the returned ids are
equivalent to global logical ids, so should be compatible with
plain MoE implementations without redundant experts.
"""
# Step 1: Validate EPLB state
self._validate_eplb_state()
@@ -10,8 +10,7 @@ from vllm.model_executor.layers.fused_moe.config import RoutingMethodType
class FusedMoERouter(ABC):
"""
FusedMoERouter is an abstract class that provides a 'select_experts'
"""FusedMoERouter is an abstract class that provides a 'select_experts'
method that is used for routing hidden states based on router logits.
"""
@@ -54,8 +53,7 @@ class FusedMoERouter(ABC):
*,
input_ids: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""
Route the input hidden states to the top-k experts based on the
"""Route the input hidden states to the top-k experts based on the
router logits.
Returns:
@@ -66,8 +64,8 @@ class FusedMoERouter(ABC):
**Compatibility**: When EPLB is not enabled, the returned ids are
equivalent to global logical ids, so should be compatible with
plain MoE implementations without redundant experts.
"""
"""
topk_weights, topk_ids = self._select_experts(
hidden_states,
router_logits,
@@ -217,8 +217,7 @@ def fp32_router_gemm_dispatch_impl(
weight: torch.Tensor,
allow_bf16x3_router_gemm: bool,
) -> torch.Tensor:
"""
Dynamically run fp32 specialized gemm if num_tokens <= FP32_MAX_TOKENS,
"""Dynamically run fp32 specialized gemm if num_tokens <= FP32_MAX_TOKENS,
otherwise optionally run the experimental BF16x3 kernel for medium/large
SM100 router batches, then fall back to F.linear.
This must be wrapped in a custom op because our torch.compile integration
@@ -66,8 +66,7 @@ def create_fused_moe_router(
bias_vl: torch.Tensor | None = None,
image_sentinel_lo: int = 0,
) -> FusedMoERouter:
"""
Factory function to create the appropriate FusedMoERouter subclass based on
"""Factory function to create the appropriate FusedMoERouter subclass based on
the provided parameters.
The selection logic follows this priority order:
@@ -114,8 +113,8 @@ def create_fused_moe_router(
Returns:
An instance of the appropriate FusedMoERouter subclass
"""
"""
routing_strategy = envs.VLLM_MOE_ROUTING_SIMULATION_STRATEGY
if routing_strategy != "":
return RoutingSimulatorRouter(
@@ -25,8 +25,7 @@ class RoutingStrategy(ABC):
top_k: int,
indices_type: torch.dtype | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""
Route tokens to experts.
"""Route tokens to experts.
Args:
hidden_states: Input hidden states [num_tokens, hidden_size]
@@ -36,13 +35,13 @@ class RoutingStrategy(ABC):
Returns:
tuple of (topk_weights, topk_ids)
"""
pass
class DistributionBasedRouting(RoutingStrategy):
"""
Distribution-based random routing strategy with configurable distributions.
"""Distribution-based random routing strategy with configurable distributions.
This routing strategy randomly selects experts for each token based on
different probability distributions. Currently supports uniform and normal
@@ -50,8 +49,7 @@ class DistributionBasedRouting(RoutingStrategy):
"""
def __init__(self, distribution: str = "uniform", **distribution_params: Any):
"""
Initialize distribution-based routing.
"""Initialize distribution-based routing.
Args:
distribution: Type of distribution to use for sampling
@@ -61,6 +59,7 @@ class DistributionBasedRouting(RoutingStrategy):
chosen distribution
For "uniform": No additional parameters needed
For "normal": mean (default: 0.0), std (default: 1.0)
"""
self.distribution = distribution.lower()
self.distribution_params = distribution_params
@@ -90,8 +89,7 @@ class DistributionBasedRouting(RoutingStrategy):
top_k: int,
indices_type: torch.dtype | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""
Randomly select experts for each token using the specified distribution.
"""Randomly select experts for each token using the specified distribution.
Args:
hidden_states: Input hidden states [num_tokens, hidden_size]
@@ -103,6 +101,7 @@ class DistributionBasedRouting(RoutingStrategy):
tuple of (topk_weights, topk_ids) where:
- topk_weights: Weights based on distribution sampling
- topk_ids: Expert indices sampled from the distribution
"""
num_tokens = hidden_states.shape[0]
num_experts = router_logits.shape[-1]
@@ -129,7 +128,6 @@ class DistributionBasedRouting(RoutingStrategy):
indices_type: torch.dtype,
) -> torch.Tensor:
"""Sample expert IDs based on the specified distribution."""
if self.distribution == "uniform":
# Generate random scores, and take the top-k to avoid duplicate topk_ids
scores = torch.rand(num_tokens, num_experts, device=device)
@@ -218,8 +216,7 @@ class DistributionBasedRouting(RoutingStrategy):
class RoutingSimulator:
"""
Token-to-Expert Routing Simulator.
"""Token-to-Expert Routing Simulator.
This class provides a framework for testing and comparing different
routing strategies for MoE models. It can simulate routing behavior
@@ -239,22 +236,22 @@ class RoutingSimulator:
@classmethod
def register_strategy(cls, name: str, strategy: RoutingStrategy):
"""
Register a custom routing strategy.
"""Register a custom routing strategy.
Args:
name: Name of the strategy
strategy: RoutingStrategy instance
"""
cls._routing_strategies[name] = strategy
@classmethod
def get_available_strategies(cls) -> list[str]:
"""
Get list of available routing strategy names.
"""Get list of available routing strategy names.
Returns:
List of available strategy names
"""
return list(cls._routing_strategies.keys())
@@ -266,8 +263,7 @@ class RoutingSimulator:
top_k: int,
indices_type: torch.dtype | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""
Simulate token-to-expert routing using the specified strategy.
"""Simulate token-to-expert routing using the specified strategy.
Args:
hidden_states: Input hidden states [num_tokens, hidden_size]
@@ -278,6 +274,7 @@ class RoutingSimulator:
Returns:
tuple of (topk_weights, topk_ids)
"""
if strategy_name not in RoutingSimulator._routing_strategies:
raise ValueError(
@@ -71,7 +71,8 @@ class ZeroExpertRouter(BaseRouter):
input_ids: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Compute routing with full bias, compute zero expert output,
mask zero expert IDs."""
mask zero expert IDs.
"""
topk_weights, topk_ids = fused_topk_bias(
hidden_states=hidden_states,
gating_output=router_logits,