[MXFP8][ROCm] Fix MXFP8 MoE backend selection (#49747)
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
This commit is contained in:
@@ -6,10 +6,13 @@
|
||||
``convert_to_fp8_moe_kernel_format``.
|
||||
"""
|
||||
|
||||
import math
|
||||
|
||||
import torch
|
||||
|
||||
import vllm.model_executor.layers.fused_moe.modular_kernel as mk
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.fused_moe.activation import MoEActivation
|
||||
from vllm.model_executor.layers.fused_moe.experts.mxfp8_emulation_moe import (
|
||||
Mxfp8TritonExpertsBase,
|
||||
)
|
||||
@@ -17,6 +20,9 @@ from vllm.platforms import current_platform
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
_AITER_SWIGLU_ALPHA = 1.702
|
||||
_AITER_SWIGLU_BETA = 1.0
|
||||
|
||||
|
||||
def is_aiter_mxfp8_moe_available() -> bool:
|
||||
"""True when the FlyDSL MXFP8 MoE can run here: gfx950, the ``flydsl``
|
||||
@@ -93,6 +99,27 @@ class AiterMxfp8Experts(Mxfp8TritonExpertsBase):
|
||||
return False, (
|
||||
"kernel requires the aiter flydsl package, which is not installed"
|
||||
)
|
||||
if (
|
||||
is_supported
|
||||
and moe_config.activation != MoEActivation.SWIGLUOAI_UNINTERLEAVE
|
||||
):
|
||||
return False, (
|
||||
"kernel hardcodes SwiGLU-OAI activation and requires "
|
||||
f"activation={MoEActivation.SWIGLUOAI_UNINTERLEAVE.value}; "
|
||||
f"got activation={moe_config.activation.value}"
|
||||
)
|
||||
if is_supported and (
|
||||
moe_config.swiglu_alpha is None
|
||||
or not math.isclose(float(moe_config.swiglu_alpha), _AITER_SWIGLU_ALPHA)
|
||||
or moe_config.swiglu_beta is None
|
||||
or not math.isclose(float(moe_config.swiglu_beta), _AITER_SWIGLU_BETA)
|
||||
):
|
||||
return False, (
|
||||
"kernel hardcodes SwiGLU-OAI with "
|
||||
f"alpha={_AITER_SWIGLU_ALPHA} and beta={_AITER_SWIGLU_BETA}; "
|
||||
f"got swiglu_alpha={moe_config.swiglu_alpha} and "
|
||||
f"swiglu_beta={moe_config.swiglu_beta}"
|
||||
)
|
||||
return is_supported, reason
|
||||
|
||||
def apply(
|
||||
|
||||
@@ -107,17 +107,13 @@ class Mxfp8EmulationTritonExperts(Mxfp8TritonExpertsBase):
|
||||
limit = self.quant_config.gemm1_clamp_limit
|
||||
if limit is None:
|
||||
raise ValueError("SWIGLUOAI_UNINTERLEAVE requires gemm1_clamp_limit")
|
||||
alpha = self.quant_config.gemm1_alpha
|
||||
alpha = 1.702 if alpha is None else float(alpha)
|
||||
beta = self.quant_config.gemm1_beta
|
||||
beta = 1.0 if beta is None else float(beta)
|
||||
apply_moe_activation(
|
||||
activation,
|
||||
output,
|
||||
input,
|
||||
clamp_limit=float(limit),
|
||||
alpha=alpha,
|
||||
beta=beta,
|
||||
alpha=self.gemm1_alpha,
|
||||
beta=self.gemm1_beta,
|
||||
)
|
||||
return
|
||||
super().activation(activation, output, input)
|
||||
|
||||
@@ -362,10 +362,7 @@ class Mxfp8NativeTritonExperts(Mxfp8TritonExpertsBase):
|
||||
expert_tokens_meta: mk.ExpertTokensMetadata | None,
|
||||
apply_router_weight_on_input: bool,
|
||||
):
|
||||
alpha = self.quant_config.gemm1_alpha
|
||||
alpha = 1.702 if alpha is None else float(alpha)
|
||||
beta = self.quant_config.gemm1_beta
|
||||
beta = 1.0 if beta is None else float(beta)
|
||||
# `self.gemm1_alpha` and `self.gemm1_beta`` are set by `TritonExperts.__init__`.
|
||||
limit = self.quant_config.gemm1_clamp_limit
|
||||
limit = None if limit is None else float(limit)
|
||||
out = fused_moe_mxfp8_native(
|
||||
@@ -376,8 +373,8 @@ class Mxfp8NativeTritonExperts(Mxfp8TritonExpertsBase):
|
||||
self.w2_scale_val,
|
||||
topk_weights,
|
||||
topk_ids,
|
||||
alpha=alpha,
|
||||
beta=beta,
|
||||
alpha=self.gemm1_alpha,
|
||||
beta=self.gemm1_beta,
|
||||
limit=limit,
|
||||
global_num_experts=global_num_experts,
|
||||
expert_map=expert_map,
|
||||
|
||||
Reference in New Issue
Block a user