[MoE] Decouple Mega MoE from DeepEP backend (#25406)
This commit is contained in:
@@ -584,7 +584,7 @@ class Envs:
|
||||
SGLANG_OPT_USE_TILELANG_MHC_PRE = EnvBool(True)
|
||||
SGLANG_OPT_USE_TILELANG_MHC_POST = EnvBool(True)
|
||||
SGLANG_OPT_USE_TILELANG_INDEXER = EnvBool(False)
|
||||
SGLANG_OPT_USE_JIT_INDEXER_METADATA = EnvBool(False)
|
||||
SGLANG_OPT_USE_JIT_INDEXER_METADATA = EnvBool(True)
|
||||
SGLANG_OPT_USE_ONLINE_COMPRESS = EnvBool(False)
|
||||
SGLANG_OPT_USE_COMPRESSOR_V2 = EnvBool(True)
|
||||
SGLANG_FP8_PAGED_MQA_LOGITS_TORCH = EnvBool(False)
|
||||
@@ -617,13 +617,12 @@ class Envs:
|
||||
# TopK
|
||||
SGLANG_OPT_USE_FUSED_HASH_TOPK = EnvBool(True)
|
||||
SGLANG_OPT_USE_JIT_KERNEL_FUSED_TOPK = EnvBool(True)
|
||||
SGLANG_OPT_USE_TOPK_V2 = EnvBool(False)
|
||||
SGLANG_OPT_USE_TOPK_V2 = EnvBool(True)
|
||||
|
||||
# GEMM / kernel fusion
|
||||
SGLANG_OPT_FP8_WO_A_GEMM = EnvBool(True)
|
||||
SGLANG_OPT_BF16_FP32_GEMM_ALGO = EnvStr("cublas")
|
||||
SGLANG_OPT_USE_JIT_EP_ACTIVATION = EnvBool(True)
|
||||
SGLANG_OPT_USE_JIT_NORM = EnvBool(False)
|
||||
SGLANG_OPT_FUSE_WQA_WKV = EnvBool(True)
|
||||
SGLANG_OPT_SWIGLU_CLAMP_FUSION = EnvBool(True)
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ _use_aiter = get_bool_env_var("SGLANG_USE_AITER") and _is_hip
|
||||
|
||||
def create_moe_dispatcher(moe_runner_config: MoeRunnerConfig) -> BaseDispatcher:
|
||||
a2a_backend = get_moe_a2a_backend()
|
||||
if a2a_backend.is_none():
|
||||
if a2a_backend.is_none() or a2a_backend.is_megamoe():
|
||||
return StandardDispatcher(moe_runner_config)
|
||||
elif (
|
||||
a2a_backend.is_deepep()
|
||||
|
||||
@@ -25,6 +25,7 @@ from sglang.jit_kernel.deepseek_v4 import mega_moe_pre_dispatch
|
||||
from sglang.srt.environ import envs
|
||||
from sglang.srt.eplb.expert_location_dispatch import ExpertLocationDispatchInfo
|
||||
from sglang.srt.layers.dp_attention import get_dp_global_num_tokens
|
||||
from sglang.srt.layers.moe.utils import get_moe_a2a_backend
|
||||
from sglang.srt.model_executor.cuda_graph_runner import get_is_capture_mode
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -94,7 +95,7 @@ def _get_mega_moe_symm_buffer(
|
||||
|
||||
|
||||
def should_use_mega_moe(moe: "DeepseekV2MoE", hidden_states: torch.Tensor) -> bool:
|
||||
if not envs.SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE.get():
|
||||
if not get_moe_a2a_backend().is_megamoe():
|
||||
return False
|
||||
if not getattr(moe.experts, "_mega_moe_weights_built", False):
|
||||
return False
|
||||
|
||||
@@ -131,7 +131,6 @@ class DeepGemmRunnerCore(MoeRunnerCore):
|
||||
if envs.SGLANG_OPT_FIX_MEGA_MOE_MEMORY.get():
|
||||
assert envs.SGLANG_OPT_SWIGLU_CLAMP_FUSION.get()
|
||||
assert envs.SGLANG_OPT_USE_JIT_EP_ACTIVATION.get()
|
||||
assert envs.SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE.get()
|
||||
self.use_swizzle = True
|
||||
|
||||
def run(
|
||||
|
||||
@@ -29,6 +29,7 @@ class MoeA2ABackend(Enum):
|
||||
MORI = "mori"
|
||||
ASCEND_FUSEEP = "ascend_fuseep"
|
||||
FLASHINFER = "flashinfer"
|
||||
MEGAMOE = "megamoe"
|
||||
CUSTOMIZED = "customized"
|
||||
|
||||
@classmethod
|
||||
@@ -61,6 +62,9 @@ class MoeA2ABackend(Enum):
|
||||
def is_mori(self):
|
||||
return self == MoeA2ABackend.MORI
|
||||
|
||||
def is_megamoe(self):
|
||||
return self == MoeA2ABackend.MEGAMOE
|
||||
|
||||
def is_customized(self):
|
||||
return self == MoeA2ABackend.CUSTOMIZED
|
||||
|
||||
|
||||
@@ -1193,7 +1193,7 @@ class Fp8MoEMethod(FusedMoEMethodBase):
|
||||
layer.w13_weight.data = layer.w13_weight.data.view(torch.int8)
|
||||
layer.w2_weight.data = layer.w2_weight.data.view(torch.int8)
|
||||
|
||||
if envs.SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE.get():
|
||||
if get_moe_a2a_backend().is_megamoe():
|
||||
from sglang.srt.layers.moe.mega_moe import (
|
||||
build_mega_moe_experts_weights,
|
||||
)
|
||||
|
||||
@@ -601,6 +601,7 @@ class DeepseekV2MoE(nn.Module):
|
||||
or get_moe_a2a_backend().is_mori()
|
||||
or get_moe_a2a_backend().is_ascend_fuseep()
|
||||
or get_moe_a2a_backend().is_flashinfer()
|
||||
or get_moe_a2a_backend().is_megamoe()
|
||||
or should_use_flashinfer_cutlass_moe_fp4_allgather()
|
||||
or envs.SGLANG_SHARED_EXPERT_TP1.get()
|
||||
)
|
||||
|
||||
@@ -209,6 +209,7 @@ MOE_A2A_BACKEND_CHOICES = [
|
||||
"mori",
|
||||
"ascend_fuseep",
|
||||
"flashinfer",
|
||||
"megamoe",
|
||||
]
|
||||
|
||||
FP8_GEMM_RUNNER_BACKEND_CHOICES = [
|
||||
@@ -610,7 +611,14 @@ class ServerArgs:
|
||||
# Expert parallelism
|
||||
ep_size: int = 1
|
||||
moe_a2a_backend: Literal[
|
||||
"none", "deepep", "mooncake", "nixl", "mori", "ascend_fuseep", "flashinfer"
|
||||
"none",
|
||||
"deepep",
|
||||
"mooncake",
|
||||
"nixl",
|
||||
"mori",
|
||||
"ascend_fuseep",
|
||||
"flashinfer",
|
||||
"megamoe",
|
||||
] = "none"
|
||||
moe_runner_backend: str = "auto"
|
||||
flashinfer_mxfp4_moe_precision: Literal["default", "bf16"] = "default"
|
||||
@@ -3184,6 +3192,25 @@ class ServerArgs:
|
||||
)
|
||||
self.moe_a2a_backend = "deepep"
|
||||
|
||||
if (
|
||||
envs.SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE.get()
|
||||
and self.moe_a2a_backend != "megamoe"
|
||||
):
|
||||
self.moe_a2a_backend = "megamoe"
|
||||
logger.info(
|
||||
"SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE is set, "
|
||||
"auto-configuring --moe-a2a-backend megamoe."
|
||||
)
|
||||
|
||||
if self.moe_a2a_backend == "megamoe":
|
||||
self.ep_size = self.tp_size
|
||||
if not envs.SGLANG_OPT_FIX_MEGA_MOE_MEMORY.is_set():
|
||||
envs.SGLANG_OPT_FIX_MEGA_MOE_MEMORY.set(True)
|
||||
logger.info(
|
||||
f"Mega MoE is enabled. The expert parallel size is adjusted "
|
||||
f"to be the same as the tensor parallel size[{self.tp_size}]."
|
||||
)
|
||||
|
||||
if self.moe_a2a_backend == "deepep":
|
||||
if self.deepep_mode == "normal":
|
||||
logger.warning("Cuda graph is disabled because deepep_mode=`normal`")
|
||||
|
||||
Reference in New Issue
Block a user