[ROCm]Enable AITER MoE backend for MiniMax-M3-MXFP4 (#46419)

Signed-off-by: Qiang Li <qiang.li2@amd.com>
Co-authored-by: TJian <tunjian.tan@embeddedllm.com>
This commit is contained in:
qli88
2026-06-26 06:35:35 -07:00
committed by GitHub
co-authored by TJian
parent 302954e5f6
commit 8e394244a5
4 changed files with 27 additions and 8 deletions
@@ -1279,6 +1279,8 @@ class FusedMoEConfig:
hidden_dim_unpadded: int | None = None
# Defaults to intermediate_size_per_partition if not specified.
intermediate_size_per_partition_unpadded: int | None = None
# Model specific override
intermediate_pad: int | None = None
moe_backend: MoEBackend = "auto"
max_num_tokens: int = SchedulerConfig.DEFAULT_MAX_NUM_BATCHED_TOKENS_FOR_BATCHED_DP
@@ -251,12 +251,17 @@ def rocm_aiter_fused_experts(
if quant_config is None:
quant_config = FUSED_MOE_UNQUANTIZED_CONFIG
# Gate/up interleave hint; only the SWIGLUOAI activations override it.
activation_interleave = None
if activation == MoEActivation.SILU:
activation_method = ActivationMethod.SILU
elif activation == MoEActivation.GELU:
activation_method = ActivationMethod.GELU
elif activation == MoEActivation.SWIGLUOAI:
activation_method = rocm_aiter_ops.get_aiter_activation_type("swiglu")
elif activation == MoEActivation.SWIGLUOAI_UNINTERLEAVE:
activation_method = rocm_aiter_ops.get_aiter_activation_type("swiglu")
activation_interleave = False
else:
raise ValueError(f"Unsupported activation: {activation}")
@@ -337,9 +342,14 @@ def rocm_aiter_fused_experts(
assert moe_config.intermediate_size_per_partition_unpadded is not None
hidden_pad = hidden_states.shape[1] - moe_config.hidden_dim_unpadded
intermediate_pad = (
moe_config.intermediate_size_per_partition
- moe_config.intermediate_size_per_partition_unpadded
(
moe_config.intermediate_size_per_partition
- moe_config.intermediate_size_per_partition_unpadded
)
if moe_config.intermediate_pad is None
else moe_config.intermediate_pad
)
# Round hidden_pad/intermediate_pad to match AITER's CK/FlyDSL MoE
# dispatch (currently pinned to v0.1.13.post1):
# https://github.com/ROCm/aiter/blob/v0.1.13.post1/aiter/fused_moe.py#L1073
@@ -357,14 +367,17 @@ def rocm_aiter_fused_experts(
# `rocm_aiter_ops.shuffle_weight_a16w4` in `oracle/mxfp4.py`,
# which always sets `is_guinterleave=True`.
# Hence, we pass in GateMode.INTERLEAVE to match the weight shuffling.
from aiter.ops.flydsl.moe_common import GateMode
gate_mode = ""
if quant_config.use_mxfp4_w4a16:
try:
from aiter.ops.flydsl.moe_common import GateMode
gate_mode = GateMode.INTERLEAVE.value
except ImportError:
pass
gate_mode = GateMode.INTERLEAVE.value
elif activation_interleave is not None:
gate_mode = (
GateMode.INTERLEAVE.value
if activation_interleave
else GateMode.SEPARATED.value
)
return rocm_aiter_ops.fused_moe(
hidden_states,
@@ -458,6 +471,7 @@ class AiterExperts(mk.FusedMoEExpertsModular):
MoEActivation.SILU,
MoEActivation.GELU,
MoEActivation.SWIGLUOAI,
MoEActivation.SWIGLUOAI_UNINTERLEAVE,
]
@staticmethod
@@ -105,6 +105,7 @@ def FusedMoE(
top_k: int,
hidden_size: int,
intermediate_size: int,
intermediate_pad: int | None = None,
params_dtype: torch.dtype | None = None,
renormalize: bool = True,
use_grouped_topk: bool = False,
@@ -311,6 +312,7 @@ def FusedMoE(
experts_per_token=top_k,
hidden_dim=hidden_size,
intermediate_size=intermediate_size,
intermediate_pad=intermediate_pad,
num_local_experts=expert_map_manager.local_num_experts,
num_logical_experts=logical_num_experts,
moe_parallel_config=moe_parallel_config,
+1
View File
@@ -309,6 +309,7 @@ class MiniMaxM3MoE(nn.Module):
top_k=config.num_experts_per_tok,
hidden_size=config.hidden_size,
intermediate_size=config.intermediate_size,
intermediate_pad=0,
scoring_func=config.scoring_func,
e_score_correction_bias=self.e_score_correction_bias,
renormalize=True,