[MoE Refactor] Rename FusedMoE to FusedMoEFactory (#44941)

Signed-off-by: Bill Nell <bnell@redhat.com>
Signed-off-by: bnellnm <49004751+bnellnm@users.noreply.github.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
bnellnm
2026-07-31 11:28:18 +01:00
committed by GitHub
co-authored by Harry Mellor
parent c911120a6f
commit 6e311c6e20
80 changed files with 243 additions and 234 deletions
@@ -19,7 +19,7 @@ from vllm.model_executor.layers.fused_moe.fused_moe_method_base import (
FusedMoEMethodBase,
)
from vllm.model_executor.layers.fused_moe.layer import (
FusedMoE,
FusedMoEFactory,
fused_moe_make_expert_params_mapping,
)
from vllm.model_executor.layers.fused_moe.modular_kernel import (
@@ -63,7 +63,7 @@ def get_config() -> dict[str, Any] | None:
__all__ = [
"FusedMoE",
"FusedMoEFactory",
"FusedMoERouter",
"FusedMoEConfig",
"FusedMoEQuantConfig",
@@ -1134,9 +1134,9 @@ class FusedMoEParallelConfig:
level's of parallelism to use in the fused moe layer.
Args:
tp_size_ (int): `tp_size` passed into the FusedMoE constructor.
pcp_size_ (int): `pcp_size` passed into the FusedMoE constructor.
dp_size_ (int): `dp_size` passed into the FusedMoE constructor.
tp_size_ (int): `tp_size` passed into the FusedMoEFactory constructor.
pcp_size_ (int): `pcp_size` passed into the FusedMoEFactory constructor.
dp_size_ (int): `dp_size` passed into the FusedMoEFactory constructor.
vllm_parallel_config (ParallelConfig): vLLM's parallel config
object which contains the `enable_expert_parallel` flag.
@@ -96,8 +96,7 @@ def determine_expert_counts(
return global_num_experts, logical_num_experts, num_fused_shared_experts
# TODO: rename this
def FusedMoE(
def FusedMoEFactory(
num_experts: int, # Global number of experts
top_k: int,
hidden_size: int,
@@ -1016,7 +1016,7 @@ def _process_weights_xpu(
w2: [E, K, N] int4 (uint8 storage [E, K, N // 2])
w2_scales: [E, K, N // group_size] params_dtype
Input GPTQ layout from FusedMoE.weight_loader:
Input GPTQ layout from MoERunner.weight_loader:
w13: [E, K // 8, 2*N] int32 (8 nibbles per int32 along the input dim)
w13_scales: [E, K // group_size, 2*N] params_dtype
w2: [E, N // 8, K] int32
@@ -1419,7 +1419,7 @@ def convert_to_wna16_moe_kernel_format(
Args:
backend: the selected ``WNA16MoEBackend``.
layer: the ``FusedMoE`` layer whose parameters are being prepared.
layer: the ``MoERunner`` layer whose parameters are being prepared.
quant_config: the ``QuantizationConfig`` for this layer.
input_dtype: optional activation dtype, usually should be 16 bit.
"""
@@ -180,7 +180,7 @@ class RoutedExpertsCapturer:
# (trailing rows are SP ceil-div padding). The TP group
# is always initialized on real rollout workers, and
# every rank in the group reaches this branch in
# lockstep (bind is per-FusedMoE layer, SP is a global
# lockstep (bind is per-FusedMoEFactory layer, SP is a global
# condition), so a bare all_gather here will not
# deadlock -- let it raise if the precondition is
# violated rather than skip silently.
@@ -353,7 +353,7 @@ class MoERunner(MoERunnerInterface):
) -> tuple[torch.Tensor, torch.Tensor | None]:
"""Apply transform for routed experts (e.g., latent projection).
This is called by FusedMoE.forward_native. The original hidden_states
This is called by MoERunner.forward_native. The original hidden_states
is saved separately so shared experts get [S, hidden_size] while
routed experts get the transformed [S, moe_latent_size].
@@ -646,7 +646,7 @@ class MoERunner(MoERunnerInterface):
):
# If router/gate provided, then apply it here.
# (Note: This code runs only when "overlapped mode" is on to allow
# parallel execution of shared experts with the FusedMoE via
# parallel execution of shared experts with the RoutedExperts via
# separate cuda stream)
if self._shared_experts is not None:
assert shared_experts_input is not None
@@ -62,7 +62,7 @@ class MoERunnerInterface(PluggableLayer, ABC):
########################################################################
#
# FusedMoE layer methods
# FusedMoEFactory layer methods
#
########################################################################
@@ -215,7 +215,7 @@ class CompressedTensorsConfig(QuantizationConfig):
def _add_fused_moe_to_target_scheme_map(self): # XXXXXXXXXXXXXXXXXXXXXX
"""
Helper function to update target_scheme_map
since linear layers get fused into FusedMoE
since linear layers get fused into RoutedExperts
targeting 'Linear' needs to also match
RoutedExperts modules.
"""
@@ -2363,7 +2363,7 @@ class ModelOptMixedPrecisionConfig(ModelOptQuantConfigBase):
if key.startswith(prefix_dot):
return info["quant_algo"].upper()
# FusedMoE expert prefix is e.g. "...moe.experts", while ModelOpt's
# RoutedExperts expert prefix is e.g. "...moe.experts", while ModelOpt's
# quantized_layers entries use "...moe.gate_proj" / "...moe.up_proj".
if prefix.endswith(".experts"):
parent_dot = prefix.rsplit(".experts", 1)[0] + "."