[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:
@@ -1279,6 +1279,8 @@ class FusedMoEConfig:
|
|||||||
hidden_dim_unpadded: int | None = None
|
hidden_dim_unpadded: int | None = None
|
||||||
# Defaults to intermediate_size_per_partition if not specified.
|
# Defaults to intermediate_size_per_partition if not specified.
|
||||||
intermediate_size_per_partition_unpadded: int | None = None
|
intermediate_size_per_partition_unpadded: int | None = None
|
||||||
|
# Model specific override
|
||||||
|
intermediate_pad: int | None = None
|
||||||
|
|
||||||
moe_backend: MoEBackend = "auto"
|
moe_backend: MoEBackend = "auto"
|
||||||
max_num_tokens: int = SchedulerConfig.DEFAULT_MAX_NUM_BATCHED_TOKENS_FOR_BATCHED_DP
|
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:
|
if quant_config is None:
|
||||||
quant_config = FUSED_MOE_UNQUANTIZED_CONFIG
|
quant_config = FUSED_MOE_UNQUANTIZED_CONFIG
|
||||||
|
|
||||||
|
# Gate/up interleave hint; only the SWIGLUOAI activations override it.
|
||||||
|
activation_interleave = None
|
||||||
if activation == MoEActivation.SILU:
|
if activation == MoEActivation.SILU:
|
||||||
activation_method = ActivationMethod.SILU
|
activation_method = ActivationMethod.SILU
|
||||||
elif activation == MoEActivation.GELU:
|
elif activation == MoEActivation.GELU:
|
||||||
activation_method = ActivationMethod.GELU
|
activation_method = ActivationMethod.GELU
|
||||||
elif activation == MoEActivation.SWIGLUOAI:
|
elif activation == MoEActivation.SWIGLUOAI:
|
||||||
activation_method = rocm_aiter_ops.get_aiter_activation_type("swiglu")
|
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:
|
else:
|
||||||
raise ValueError(f"Unsupported activation: {activation}")
|
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
|
assert moe_config.intermediate_size_per_partition_unpadded is not None
|
||||||
hidden_pad = hidden_states.shape[1] - moe_config.hidden_dim_unpadded
|
hidden_pad = hidden_states.shape[1] - moe_config.hidden_dim_unpadded
|
||||||
intermediate_pad = (
|
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
|
# Round hidden_pad/intermediate_pad to match AITER's CK/FlyDSL MoE
|
||||||
# dispatch (currently pinned to v0.1.13.post1):
|
# dispatch (currently pinned to v0.1.13.post1):
|
||||||
# https://github.com/ROCm/aiter/blob/v0.1.13.post1/aiter/fused_moe.py#L1073
|
# 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`,
|
# `rocm_aiter_ops.shuffle_weight_a16w4` in `oracle/mxfp4.py`,
|
||||||
# which always sets `is_guinterleave=True`.
|
# which always sets `is_guinterleave=True`.
|
||||||
# Hence, we pass in GateMode.INTERLEAVE to match the weight shuffling.
|
# Hence, we pass in GateMode.INTERLEAVE to match the weight shuffling.
|
||||||
|
from aiter.ops.flydsl.moe_common import GateMode
|
||||||
|
|
||||||
gate_mode = ""
|
gate_mode = ""
|
||||||
if quant_config.use_mxfp4_w4a16:
|
if quant_config.use_mxfp4_w4a16:
|
||||||
try:
|
gate_mode = GateMode.INTERLEAVE.value
|
||||||
from aiter.ops.flydsl.moe_common import GateMode
|
elif activation_interleave is not None:
|
||||||
|
gate_mode = (
|
||||||
gate_mode = GateMode.INTERLEAVE.value
|
GateMode.INTERLEAVE.value
|
||||||
except ImportError:
|
if activation_interleave
|
||||||
pass
|
else GateMode.SEPARATED.value
|
||||||
|
)
|
||||||
|
|
||||||
return rocm_aiter_ops.fused_moe(
|
return rocm_aiter_ops.fused_moe(
|
||||||
hidden_states,
|
hidden_states,
|
||||||
@@ -458,6 +471,7 @@ class AiterExperts(mk.FusedMoEExpertsModular):
|
|||||||
MoEActivation.SILU,
|
MoEActivation.SILU,
|
||||||
MoEActivation.GELU,
|
MoEActivation.GELU,
|
||||||
MoEActivation.SWIGLUOAI,
|
MoEActivation.SWIGLUOAI,
|
||||||
|
MoEActivation.SWIGLUOAI_UNINTERLEAVE,
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ def FusedMoE(
|
|||||||
top_k: int,
|
top_k: int,
|
||||||
hidden_size: int,
|
hidden_size: int,
|
||||||
intermediate_size: int,
|
intermediate_size: int,
|
||||||
|
intermediate_pad: int | None = None,
|
||||||
params_dtype: torch.dtype | None = None,
|
params_dtype: torch.dtype | None = None,
|
||||||
renormalize: bool = True,
|
renormalize: bool = True,
|
||||||
use_grouped_topk: bool = False,
|
use_grouped_topk: bool = False,
|
||||||
@@ -311,6 +312,7 @@ def FusedMoE(
|
|||||||
experts_per_token=top_k,
|
experts_per_token=top_k,
|
||||||
hidden_dim=hidden_size,
|
hidden_dim=hidden_size,
|
||||||
intermediate_size=intermediate_size,
|
intermediate_size=intermediate_size,
|
||||||
|
intermediate_pad=intermediate_pad,
|
||||||
num_local_experts=expert_map_manager.local_num_experts,
|
num_local_experts=expert_map_manager.local_num_experts,
|
||||||
num_logical_experts=logical_num_experts,
|
num_logical_experts=logical_num_experts,
|
||||||
moe_parallel_config=moe_parallel_config,
|
moe_parallel_config=moe_parallel_config,
|
||||||
|
|||||||
@@ -309,6 +309,7 @@ class MiniMaxM3MoE(nn.Module):
|
|||||||
top_k=config.num_experts_per_tok,
|
top_k=config.num_experts_per_tok,
|
||||||
hidden_size=config.hidden_size,
|
hidden_size=config.hidden_size,
|
||||||
intermediate_size=config.intermediate_size,
|
intermediate_size=config.intermediate_size,
|
||||||
|
intermediate_pad=0,
|
||||||
scoring_func=config.scoring_func,
|
scoring_func=config.scoring_func,
|
||||||
e_score_correction_bias=self.e_score_correction_bias,
|
e_score_correction_bias=self.e_score_correction_bias,
|
||||||
renormalize=True,
|
renormalize=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user