[MOE] Standardize and abstract fused shared expert optimization selection (#51695)
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
This commit is contained in:
@@ -6,7 +6,6 @@ from typing import Any
|
||||
|
||||
import torch
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
from vllm.config import ParallelConfig, get_current_vllm_config
|
||||
from vllm.distributed import (
|
||||
@@ -74,23 +73,13 @@ def determine_expert_counts(
|
||||
num_experts: int,
|
||||
num_redundant_experts: int,
|
||||
n_shared_experts: int | None,
|
||||
is_act_and_mul: bool,
|
||||
fuse_shared_experts: bool,
|
||||
) -> tuple[int, int, int]:
|
||||
global_num_experts = num_experts + num_redundant_experts
|
||||
logical_num_experts = num_experts
|
||||
# Shared-expert fusion: append the shared expert(s) as routed-expert slots
|
||||
# so they run in the same grouped GEMM. Gated by
|
||||
# VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS: either the native aiter fused-MoE
|
||||
# path (env + master switch, via is_fusion_moe_shared_experts_enabled) or the
|
||||
# backend-neutral router-append path (env alone, independent of the master
|
||||
# switch; e.g. the MM3 triton/flydsl mxfp8 MoE). Gated activations only.
|
||||
fuse_shared_enabled = (
|
||||
rocm_aiter_ops.is_fusion_moe_shared_experts_enabled()
|
||||
or envs.VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS
|
||||
) and is_act_and_mul
|
||||
|
||||
num_fused_shared_experts = (
|
||||
n_shared_experts if n_shared_experts is not None and fuse_shared_enabled else 0
|
||||
n_shared_experts if n_shared_experts is not None and fuse_shared_experts else 0
|
||||
)
|
||||
|
||||
return global_num_experts, logical_num_experts, num_fused_shared_experts
|
||||
@@ -132,6 +121,7 @@ def FusedMoEFactory(
|
||||
ckpt_names: tuple[str, str, str] = ("gate_proj", "down_proj", "up_proj"),
|
||||
is_fused_checkpoint_transposed: bool = False,
|
||||
n_shared_experts: int | None = None,
|
||||
fuse_shared_experts: bool = False,
|
||||
router_logits_dtype: torch.dtype | None = None,
|
||||
gate: torch.nn.Module | None = None,
|
||||
shared_experts: torch.nn.Module | None = None,
|
||||
@@ -198,6 +188,7 @@ def FusedMoEFactory(
|
||||
block scales use transposed storage.
|
||||
n_shared_experts: Number of shared experts to fuse into the routed
|
||||
grouped GEMM (ROCm; requires aiter FSE or the router-append path)
|
||||
fuse_shared_experts: Whether to enable shared-expert fusion.
|
||||
router_logits_dtype: Data type for router logits buffers
|
||||
gate: Pre-configured gate module
|
||||
shared_experts: Pre-configured shared experts module
|
||||
@@ -244,7 +235,7 @@ def FusedMoEFactory(
|
||||
num_experts,
|
||||
num_redundant_experts,
|
||||
n_shared_experts,
|
||||
is_act_and_mul,
|
||||
fuse_shared_experts,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user