[CPU] Support gelu act in cpu_fused_moe (#38770)

Signed-off-by: jiang1.li <jiang1.li@intel.com>
This commit is contained in:
Li, Jiang
2026-04-02 14:14:32 +08:00
committed by GitHub
parent 9bd7231106
commit c6f722b93e
5 changed files with 59 additions and 3 deletions
@@ -34,12 +34,20 @@ def _swigluoai_forward_native(
return gated_output
def _gelu_and_mul(
x: torch.Tensor,
) -> torch.Tensor:
d = x.shape[-1] // 2
return F.gelu(x[..., :d], approximate="none") * x[..., d:]
# Map activation names to their native forward functions.
# Uses static methods or standalone functions to avoid instantiating CustomOp
# classes, which would call get_current_vllm_config() before config is set.
_CPU_MOE_ACT_FN: dict[MoEActivation, Callable[[torch.Tensor], torch.Tensor]] = {
MoEActivation.SILU: SiluAndMul.forward_native,
MoEActivation.SWIGLUOAI: _swigluoai_forward_native,
MoEActivation.GELU: _gelu_and_mul,
}