[MoE Refactor] EPLB refactoring for FusedMoE (#41055)

Signed-off-by: Bill Nell <bnell@redhat.com>
Co-authored-by: Robert Shaw <114415538+robertgshaw2-redhat@users.noreply.github.com>
This commit is contained in:
bnellnm
2026-05-12 14:16:31 -04:00
committed by GitHub
co-authored by Robert Shaw
parent 4d591db470
commit d9b4990783
17 changed files with 83 additions and 98 deletions
@@ -10,6 +10,7 @@ import torch
from tests.kernels.moe.utils import make_test_quant_config from tests.kernels.moe.utils import make_test_quant_config
from vllm.config import VllmConfig, set_current_vllm_config from vllm.config import VllmConfig, set_current_vllm_config
from vllm.distributed.eplb.eplb_state import EplbLayerState
from vllm.distributed.eplb.rebalance_execute import rearrange_expert_weights_inplace from vllm.distributed.eplb.rebalance_execute import rearrange_expert_weights_inplace
from vllm.distributed.parallel_state import ( from vllm.distributed.parallel_state import (
ensure_model_parallel_initialized, ensure_model_parallel_initialized,
@@ -201,7 +202,7 @@ def _test_eplb_fml(env, world_size: int, test_config: TestConfig):
dtype=torch.int32, dtype=torch.int32,
device=device, device=device,
) )
fml.enable_eplb = True fml.eplb_state = EplbLayerState()
fml.set_eplb_state( fml.set_eplb_state(
lidx, lidx,
torch.zeros( torch.zeros(
-3
View File
@@ -1004,7 +1004,6 @@ def make_fake_moe_layer(
activation: str = "silu", activation: str = "silu",
indices_type: torch.dtype | None = None, indices_type: torch.dtype | None = None,
expert_map: torch.Tensor | None = None, expert_map: torch.Tensor | None = None,
enable_eplb: bool = False,
expert_load_view: torch.Tensor | None = None, expert_load_view: torch.Tensor | None = None,
logical_to_physical_map: torch.Tensor | None = None, logical_to_physical_map: torch.Tensor | None = None,
logical_replica_count: torch.Tensor | None = None, logical_replica_count: torch.Tensor | None = None,
@@ -1022,7 +1021,6 @@ def make_fake_moe_layer(
router = create_fused_moe_router( router = create_fused_moe_router(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
# eplb_state=None, # TODO
renormalize=renormalize, renormalize=renormalize,
use_grouped_topk=use_grouped_topk, use_grouped_topk=use_grouped_topk,
num_expert_group=num_expert_group, num_expert_group=num_expert_group,
@@ -1032,7 +1030,6 @@ def make_fake_moe_layer(
routed_scaling_factor=routed_scaling_factor, routed_scaling_factor=routed_scaling_factor,
e_score_correction_bias=e_score_correction_bias, e_score_correction_bias=e_score_correction_bias,
num_fused_shared_experts=0, # TODO num_fused_shared_experts=0, # TODO
enable_eplb=enable_eplb,
# TODO(bnell): once we can construct the MK at init time, we # TODO(bnell): once we can construct the MK at init time, we
# can make this a value. # can make this a value.
indices_type_getter=lambda: indices_type, indices_type_getter=lambda: indices_type,
+4 -7
View File
@@ -36,9 +36,11 @@ TOP_KS = [2, 4, 6]
NUM_EXPERTS = [8, 16, 64] NUM_EXPERTS = [8, 16, 64]
def setup_eplb_state(enable_eplb: bool, global_num_experts: int) -> EplbLayerState: def setup_eplb_state(
enable_eplb: bool, global_num_experts: int
) -> EplbLayerState | None:
if not enable_eplb: if not enable_eplb:
return EplbLayerState() return None
# Initialize EPLB state with proper tensors for testing # Initialize EPLB state with proper tensors for testing
# For testing purposes, we use a simple 1:1 mapping (no redundant experts) # For testing purposes, we use a simple 1:1 mapping (no redundant experts)
@@ -349,7 +351,6 @@ def test_fused_topk(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
renormalize=renormalize, renormalize=renormalize,
enable_eplb=enable_eplb,
eplb_state=eplb_state, eplb_state=eplb_state,
) )
@@ -400,7 +401,6 @@ def test_fused_topk_bias(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
renormalize=renormalize, renormalize=renormalize,
enable_eplb=enable_eplb,
eplb_state=eplb_state, eplb_state=eplb_state,
) )
@@ -469,7 +469,6 @@ def test_grouped_topk(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
renormalize=renormalize, renormalize=renormalize,
enable_eplb=enable_eplb,
eplb_state=eplb_state, eplb_state=eplb_state,
) )
@@ -540,7 +539,6 @@ def test_custom(
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
custom_routing_function=custom_routing_function, custom_routing_function=custom_routing_function,
renormalize=renormalize, renormalize=renormalize,
enable_eplb=enable_eplb,
eplb_state=eplb_state, eplb_state=eplb_state,
) )
@@ -580,7 +578,6 @@ def test_custom(
# router = create_fused_moe_router( # router = create_fused_moe_router(
# top_k=top_k, # top_k=top_k,
# global_num_experts=global_num_experts, # global_num_experts=global_num_experts,
# enable_eplb=enable_eplb,
# eplb_state=eplb_state, # eplb_state=eplb_state,
# ) # )
+11
View File
@@ -940,6 +940,17 @@ class EplbLayerState:
GPU work. GPU work.
""" """
def set_layer_state(
self,
moe_layer_idx: int,
expert_load_view: torch.Tensor,
logical_to_physical_map: torch.Tensor,
logical_replica_count: torch.Tensor,
) -> None:
self.expert_load_view = expert_load_view[moe_layer_idx]
self.logical_to_physical_map = logical_to_physical_map[moe_layer_idx]
self.logical_replica_count = logical_replica_count[moe_layer_idx]
def _node_count_with_rank_mapping( def _node_count_with_rank_mapping(
pg: ProcessGroup | StatelessProcessGroup, pg: ProcessGroup | StatelessProcessGroup,
+29 -20
View File
@@ -203,13 +203,24 @@ class FusedMoE(PluggableLayer):
compilation_config.static_all_moe_layers.append(prefix) compilation_config.static_all_moe_layers.append(prefix)
self.layer_name = prefix self.layer_name = prefix
self.enable_eplb = enable_eplb
# TODO(bnell): should this be owned by router?
self.eplb_state = EplbLayerState()
self.expert_placement_strategy: ExpertPlacementStrategy = ( self.expert_placement_strategy: ExpertPlacementStrategy = (
vllm_config.parallel_config.expert_placement_strategy vllm_config.parallel_config.expert_placement_strategy
) )
self.eplb_state: EplbLayerState | None = None
if enable_eplb:
if self.use_ep and self.global_num_experts % self.ep_size != 0:
raise ValueError(
f"EPLB currently only supports even distribution of "
f"experts across ranks. Got {self.global_num_experts} experts "
f"and {self.ep_size} EP ranks."
)
self.eplb_state = EplbLayerState()
else:
assert not self.use_ep or num_redundant_experts == 0, (
"Redundant experts are only supported with EPLB."
)
# ROCm aiter shared experts fusion # ROCm aiter shared experts fusion
# AITER only supports gated activations (silu/gelu), so disable it # AITER only supports gated activations (silu/gelu), so disable it
# for non-gated MoE (is_act_and_mul=False) # for non-gated MoE (is_act_and_mul=False)
@@ -237,17 +248,6 @@ class FusedMoE(PluggableLayer):
) )
# Determine expert maps # Determine expert maps
if self.use_ep:
if self.enable_eplb:
assert self.global_num_experts % self.ep_size == 0, (
"EPLB currently only supports even distribution of "
"experts across ranks."
)
else:
assert num_redundant_experts == 0, (
"Redundant experts are only supported with EPLB."
)
max_num_batched_tokens = vllm_config.scheduler_config.max_num_batched_tokens max_num_batched_tokens = vllm_config.scheduler_config.max_num_batched_tokens
# Create ExpertMapManager to handle expert mapping and placement for EP. # Create ExpertMapManager to handle expert mapping and placement for EP.
@@ -261,7 +261,7 @@ class FusedMoE(PluggableLayer):
num_expert_group=num_expert_group, num_expert_group=num_expert_group,
moe_parallel_config=self.moe_parallel_config, moe_parallel_config=self.moe_parallel_config,
placement_strategy=self.expert_placement_strategy, placement_strategy=self.expert_placement_strategy,
enable_eplb=self.enable_eplb, enable_eplb=enable_eplb,
num_fused_shared_experts=self.num_fused_shared_experts, num_fused_shared_experts=self.num_fused_shared_experts,
rocm_aiter_enabled=self.rocm_aiter_fmoe_enabled, rocm_aiter_enabled=self.rocm_aiter_fmoe_enabled,
) )
@@ -313,7 +313,6 @@ class FusedMoE(PluggableLayer):
routed_scaling_factor=self.routed_scaling_factor, routed_scaling_factor=self.routed_scaling_factor,
e_score_correction_bias=e_score_correction_bias, e_score_correction_bias=e_score_correction_bias,
num_fused_shared_experts=self.num_fused_shared_experts, num_fused_shared_experts=self.num_fused_shared_experts,
enable_eplb=enable_eplb,
# TODO(bnell): once we can construct the MK at init time, we # TODO(bnell): once we can construct the MK at init time, we
# can make this a value. # can make this a value.
indices_type_getter=lambda: self.quant_method.topk_indices_dtype, indices_type_getter=lambda: self.quant_method.topk_indices_dtype,
@@ -381,7 +380,7 @@ class FusedMoE(PluggableLayer):
"is_act_and_mul=False is supported only for CUDA and XPU for now" "is_act_and_mul=False is supported only for CUDA and XPU for now"
) )
if self.enable_eplb and not self.quant_method.supports_eplb: if enable_eplb and not self.quant_method.supports_eplb:
# TODO: Add support for additional quantization methods. # TODO: Add support for additional quantization methods.
# The implementation for other quantization methods does not # The implementation for other quantization methods does not
# contain essential differences, but the current quant API # contain essential differences, but the current quant API
@@ -1282,10 +1281,20 @@ class FusedMoE(PluggableLayer):
This is used later in forward pass, where we get the expert mapping This is used later in forward pass, where we get the expert mapping
and record the load metrics in `expert_load_view`. and record the load metrics in `expert_load_view`.
Args:
moe_layer_idx: Index of this MoE layer
expert_load_view: View into global expert load tracking tensor
logical_to_physical_map: Mapping from logical to physical expert IDs
logical_replica_count: Number of replicas for each logical expert
""" """
self.eplb_state.expert_load_view = expert_load_view[moe_layer_idx] if self.eplb_state is not None:
self.eplb_state.logical_to_physical_map = logical_to_physical_map[moe_layer_idx] self.eplb_state.set_layer_state(
self.eplb_state.logical_replica_count = logical_replica_count[moe_layer_idx] moe_layer_idx,
expert_load_view,
logical_to_physical_map,
logical_replica_count,
)
def ensure_moe_quant_config_init(self): def ensure_moe_quant_config_init(self):
if self.quant_method.moe_quant_config is None: if self.quant_method.moe_quant_config is None:
@@ -33,18 +33,16 @@ class AiterSharedRoutedFusedMoERouter(BaseRouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState,
num_fused_shared_experts: int, num_fused_shared_experts: int,
eplb_state: EplbLayerState | None = None,
scoring_func: str = "softmax", scoring_func: str = "softmax",
renormalize: bool = True, renormalize: bool = True,
enable_eplb: bool = False,
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
): ):
super().__init__( super().__init__(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
self.renormalize = renormalize self.renormalize = renormalize
@@ -148,8 +148,7 @@ class BaseRouter(FusedMoERouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState, eplb_state: EplbLayerState | None = None,
enable_eplb: bool = False,
# TODO(bnell): Once the MK is constructed at layer init time, we # TODO(bnell): Once the MK is constructed at layer init time, we
# can make this a plain value instead of a callback. # can make this a plain value instead of a callback.
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
@@ -159,12 +158,17 @@ class BaseRouter(FusedMoERouter):
time, so we need to supply a callback to get it at runtime. This is time, so we need to supply a callback to get it at runtime. This is
because the indices type is supplied by modular kernels which are because the indices type is supplied by modular kernels which are
created after MoE layer/router construction. created after MoE layer/router construction.
Args:
top_k: Number of experts to select per token
global_num_experts: Total number of experts
eplb_state: Optional EPLBLayerState for load balancing
indices_type_getter: Optional callback to get indices dtype
""" """
super().__init__() super().__init__()
self.top_k = top_k self.top_k = top_k
self.global_num_experts = global_num_experts self.global_num_experts = global_num_experts
self.eplb_state = eplb_state self.eplb_state = eplb_state
self.enable_eplb = enable_eplb
self.indices_type_getter = indices_type_getter self.indices_type_getter = indices_type_getter
self.capture_fn: Callable[[torch.Tensor], None] | None = None self.capture_fn: Callable[[torch.Tensor], None] | None = None
@@ -174,21 +178,16 @@ class BaseRouter(FusedMoERouter):
def _validate_eplb_state(self) -> None: def _validate_eplb_state(self) -> None:
"""Validate that EPLB state is properly initialized if EPLB is enabled.""" """Validate that EPLB state is properly initialized if EPLB is enabled."""
if self.enable_eplb: if self.eplb_state is not None:
if self.eplb_state.expert_load_view is None: eplb_state = self.eplb_state
raise ValueError("enable_eplb=True requires expert_load_view != None") if eplb_state.expert_load_view is None:
if self.eplb_state.logical_to_physical_map is None: raise ValueError("EPLB requires expert_load_view != None")
raise ValueError( if eplb_state.logical_to_physical_map is None:
"enable_eplb=True requires logical_to_physical_map != None" raise ValueError("EPLB requires logical_to_physical_map != None")
) if eplb_state.logical_replica_count is None:
if self.eplb_state.logical_replica_count is None: raise ValueError("EPLB requires logical_replica_count != None")
raise ValueError( if eplb_state.should_record_tensor is None:
"enable_eplb=True requires logical_replica_count != None" raise ValueError("EPLB requires should_record_tensor != None")
)
if self.eplb_state.should_record_tensor is None:
raise ValueError(
"enable_eplb=True requires should_record_tensor != None"
)
def _get_indices_type(self) -> torch.dtype | None: def _get_indices_type(self) -> torch.dtype | None:
"""Get the desired indices dtype from the getter function.""" """Get the desired indices dtype from the getter function."""
@@ -198,17 +197,18 @@ class BaseRouter(FusedMoERouter):
def _apply_eplb_mapping(self, topk_ids: torch.Tensor) -> torch.Tensor: def _apply_eplb_mapping(self, topk_ids: torch.Tensor) -> torch.Tensor:
"""Apply EPLB mapping to convert logical expert IDs to physical expert IDs.""" """Apply EPLB mapping to convert logical expert IDs to physical expert IDs."""
if self.enable_eplb: if self.eplb_state is not None:
assert self.eplb_state.expert_load_view is not None eplb_state = self.eplb_state
assert self.eplb_state.logical_to_physical_map is not None assert eplb_state.expert_load_view is not None
assert self.eplb_state.logical_replica_count is not None assert eplb_state.logical_to_physical_map is not None
assert self.eplb_state.should_record_tensor is not None assert eplb_state.logical_replica_count is not None
assert eplb_state.should_record_tensor is not None
return eplb_map_to_physical_and_record( return eplb_map_to_physical_and_record(
topk_ids=topk_ids, topk_ids=topk_ids,
logical_to_physical_map=self.eplb_state.logical_to_physical_map, logical_to_physical_map=eplb_state.logical_to_physical_map,
logical_replica_count=self.eplb_state.logical_replica_count, logical_replica_count=eplb_state.logical_replica_count,
expert_load_view=self.eplb_state.expert_load_view, expert_load_view=eplb_state.expert_load_view,
record_enabled=self.eplb_state.should_record_tensor, record_enabled=eplb_state.should_record_tensor,
) )
return topk_ids return topk_ids
@@ -16,17 +16,15 @@ class CustomRoutingRouter(BaseRouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState,
custom_routing_function: Callable, custom_routing_function: Callable,
eplb_state: EplbLayerState | None = None,
renormalize: bool = True, renormalize: bool = True,
enable_eplb: bool = False,
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
): ):
super().__init__( super().__init__(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
self.custom_routing_function = custom_routing_function self.custom_routing_function = custom_routing_function
@@ -235,11 +235,10 @@ class FusedTopKBiasRouter(BaseRouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState,
e_score_correction_bias: torch.Tensor | None = None, e_score_correction_bias: torch.Tensor | None = None,
renormalize: bool = True, renormalize: bool = True,
routed_scaling_factor: float = 1.0, routed_scaling_factor: float = 1.0,
enable_eplb: bool = False, eplb_state: EplbLayerState | None = None,
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
*, *,
scoring_func: str = "sigmoid", scoring_func: str = "sigmoid",
@@ -249,7 +248,6 @@ class FusedTopKBiasRouter(BaseRouter):
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
self.e_score_correction_bias = e_score_correction_bias self.e_score_correction_bias = e_score_correction_bias
@@ -120,17 +120,15 @@ class FusedTopKRouter(BaseRouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState,
scoring_func: str = "softmax", scoring_func: str = "softmax",
renormalize: bool = True, renormalize: bool = True,
enable_eplb: bool = False, eplb_state: EplbLayerState | None = None,
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
): ):
super().__init__( super().__init__(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
self.renormalize = renormalize self.renormalize = renormalize
@@ -251,7 +251,6 @@ class GroupedTopKRouter(BaseRouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState,
num_expert_group: int, num_expert_group: int,
topk_group: int, topk_group: int,
renormalize: bool = True, renormalize: bool = True,
@@ -259,14 +258,13 @@ class GroupedTopKRouter(BaseRouter):
routed_scaling_factor: float = 1.0, routed_scaling_factor: float = 1.0,
e_score_correction_bias: torch.Tensor | None = None, e_score_correction_bias: torch.Tensor | None = None,
num_fused_shared_experts: int = 0, num_fused_shared_experts: int = 0,
enable_eplb: bool = False, eplb_state: EplbLayerState | None = None,
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
): ):
super().__init__( super().__init__(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
self.num_expert_group = num_expert_group self.num_expert_group = num_expert_group
@@ -35,8 +35,6 @@ from vllm.model_executor.layers.fused_moe.router.zero_expert_router import (
ZeroExpertRouter, ZeroExpertRouter,
) )
EMPTY_EPLB_STATE: EplbLayerState = EplbLayerState()
def create_fused_moe_router( def create_fused_moe_router(
# common parameters # common parameters
@@ -56,8 +54,7 @@ def create_fused_moe_router(
# custom routing parameters # custom routing parameters
custom_routing_function: Callable | None = None, custom_routing_function: Callable | None = None,
# eplb parameters # eplb parameters
enable_eplb: bool = False, eplb_state: EplbLayerState | None = None,
eplb_state: EplbLayerState = EMPTY_EPLB_STATE,
# zero expert parameters # zero expert parameters
zero_expert_type: str | None = None, zero_expert_type: str | None = None,
num_logical_experts: int | None = None, num_logical_experts: int | None = None,
@@ -98,8 +95,7 @@ def create_fused_moe_router(
custom_routing_function: Optional custom routing function custom_routing_function: Optional custom routing function
EPLB arguments: EPLB arguments:
enable_eplb: Whether EPLB is enabled eplb_state: Optional EplbLayerState, None when EPLB is disabled.
eplb_state: EPLB (Expert Parallelism Load Balancing) state
Zero expert arguments: Zero expert arguments:
zero_expert_type: Type of zero expert (e.g. identity). If not None, zero_expert_type: Type of zero expert (e.g. identity). If not None,
@@ -120,7 +116,6 @@ def create_fused_moe_router(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
@@ -141,7 +136,6 @@ def create_fused_moe_router(
scoring_func=scoring_func, scoring_func=scoring_func,
renormalize=renormalize, renormalize=renormalize,
routed_scaling_factor=routed_scaling_factor, routed_scaling_factor=routed_scaling_factor,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
@@ -163,7 +157,6 @@ def create_fused_moe_router(
routed_scaling_factor=routed_scaling_factor, routed_scaling_factor=routed_scaling_factor,
e_score_correction_bias=e_score_correction_bias, e_score_correction_bias=e_score_correction_bias,
num_fused_shared_experts=num_fused_shared_experts, num_fused_shared_experts=num_fused_shared_experts,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
if ( if (
@@ -186,7 +179,6 @@ def create_fused_moe_router(
eplb_state=eplb_state, eplb_state=eplb_state,
custom_routing_function=custom_routing_function, custom_routing_function=custom_routing_function,
renormalize=renormalize, renormalize=renormalize,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
@@ -200,7 +192,6 @@ def create_fused_moe_router(
e_score_correction_bias=e_score_correction_bias, e_score_correction_bias=e_score_correction_bias,
renormalize=renormalize, renormalize=renormalize,
routed_scaling_factor=routed_scaling_factor, routed_scaling_factor=routed_scaling_factor,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
scoring_func=scoring_func, scoring_func=scoring_func,
hash_indices_table=hash_indices_table, hash_indices_table=hash_indices_table,
@@ -218,7 +209,6 @@ def create_fused_moe_router(
num_fused_shared_experts=num_fused_shared_experts, num_fused_shared_experts=num_fused_shared_experts,
renormalize=renormalize, renormalize=renormalize,
scoring_func=scoring_func, scoring_func=scoring_func,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
@@ -228,6 +218,5 @@ def create_fused_moe_router(
eplb_state=eplb_state, eplb_state=eplb_state,
renormalize=renormalize, renormalize=renormalize,
scoring_func=scoring_func, scoring_func=scoring_func,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
@@ -313,15 +313,13 @@ class RoutingSimulatorRouter(BaseRouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState, eplb_state: EplbLayerState | None = None,
enable_eplb: bool = False,
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
): ):
super().__init__( super().__init__(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
@@ -32,21 +32,19 @@ class ZeroExpertRouter(BaseRouter):
self, self,
top_k: int, top_k: int,
global_num_experts: int, global_num_experts: int,
eplb_state: EplbLayerState,
e_score_correction_bias: torch.Tensor, e_score_correction_bias: torch.Tensor,
num_logical_experts: int, num_logical_experts: int,
zero_expert_type: str, zero_expert_type: str,
scoring_func: str = "softmax", scoring_func: str = "softmax",
renormalize: bool = False, renormalize: bool = False,
routed_scaling_factor: float = 1.0, routed_scaling_factor: float = 1.0,
enable_eplb: bool = False, eplb_state: EplbLayerState | None = None,
indices_type_getter: Callable[[], torch.dtype | None] | None = None, indices_type_getter: Callable[[], torch.dtype | None] | None = None,
): ):
super().__init__( super().__init__(
top_k=top_k, top_k=top_k,
global_num_experts=global_num_experts, global_num_experts=global_num_experts,
eplb_state=eplb_state, eplb_state=eplb_state,
enable_eplb=enable_eplb,
indices_type_getter=indices_type_getter, indices_type_getter=indices_type_getter,
) )
self.e_score_correction_bias = e_score_correction_bias self.e_score_correction_bias = e_score_correction_bias
@@ -311,10 +311,6 @@ class CompressedTensorsW4A8Fp8MoEMethod(CompressedTensorsMoEMethod):
shared_experts: SharedExperts | None, shared_experts: SharedExperts | None,
shared_experts_input: torch.Tensor | None, shared_experts_input: torch.Tensor | None,
) -> torch.Tensor: ) -> torch.Tensor:
if layer.enable_eplb:
raise NotImplementedError(
"EPLB not supported for `CompressedTensorsW4A8Fp8MoEMethod` yet."
)
assert self.moe_quant_config is not None assert self.moe_quant_config is not None
from vllm.model_executor.layers.fused_moe.experts.cutlass_moe import ( from vllm.model_executor.layers.fused_moe.experts.cutlass_moe import (
@@ -307,7 +307,6 @@ class CompressedTensorsW4A8Int8MoEMethod(CompressedTensorsMoEMethod):
router_logits: torch.Tensor, router_logits: torch.Tensor,
input_ids: torch.Tensor | None = None, input_ids: torch.Tensor | None = None,
) -> torch.Tensor: ) -> torch.Tensor:
assert not layer.enable_eplb, "EPLB not supported for W4A8-int MoE yet."
assert layer.activation in ( assert layer.activation in (
MoEActivation.SILU, MoEActivation.SILU,
MoEActivation.SWIGLUOAI, MoEActivation.SWIGLUOAI,
@@ -2101,7 +2101,7 @@ class ModelOptMxFp8FusedMoE(FusedMoEMethodBase):
assert self.mxfp8_backend == Fp8MoeBackend.FLASHINFER_TRTLLM assert self.mxfp8_backend == Fp8MoeBackend.FLASHINFER_TRTLLM
if layer.enable_eplb: if layer.eplb_state is not None:
raise NotImplementedError( raise NotImplementedError(
"EPLB is not supported for FlashInfer TRTLLM MXFP8 MoE backend." "EPLB is not supported for FlashInfer TRTLLM MXFP8 MoE backend."
) )