[Kernel] Support Nvfp4 Cutedsl Moe Swiglu-oai and Relu2(non-gated) Activation (#47106)
Signed-off-by: Tiekai Bi <tiekaib@nvidia.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Yongye Zhu <zyy1102000@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5
Yongye Zhu
parent
b1e12d142d
commit
e08111211b
@@ -59,6 +59,9 @@ class FlashInferCuteDSLExperts(mk.FusedMoEExpertsModular):
|
||||
self.global_num_experts = moe_config.num_experts
|
||||
self.ep_rank = moe_config.moe_parallel_config.ep_rank
|
||||
self.local_expert_offset = self.ep_rank * self.local_num_experts
|
||||
self.gemm1_alpha = quant_config.gemm1_alpha
|
||||
self.gemm1_beta = quant_config.gemm1_beta
|
||||
self.gemm1_clamp_limit = quant_config.gemm1_clamp_limit
|
||||
|
||||
def process_weights_after_loading(self, layer: torch.nn.Module) -> None:
|
||||
layer.w13_weight_scale_2.data.mul_(layer.w13_input_scale)
|
||||
@@ -93,7 +96,12 @@ class FlashInferCuteDSLExperts(mk.FusedMoEExpertsModular):
|
||||
|
||||
@staticmethod
|
||||
def _supports_activation(activation: MoEActivation) -> bool:
|
||||
return activation in (MoEActivation.SILU, MoEActivation.RELU2_NO_MUL)
|
||||
return activation in (
|
||||
MoEActivation.SILU,
|
||||
MoEActivation.SWIGLUOAI,
|
||||
MoEActivation.SWIGLUOAI_UNINTERLEAVE,
|
||||
MoEActivation.RELU2_NO_MUL,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _supports_parallel_config(
|
||||
@@ -149,6 +157,22 @@ class FlashInferCuteDSLExperts(mk.FusedMoEExpertsModular):
|
||||
# The functional API expects x_sf with trailing dim: (M, K//16, 1).
|
||||
x_sf = a1q_scale.unsqueeze(-1)
|
||||
|
||||
# The kernel defaults swiglu_{alpha,beta,limit} to the plain-SwiGLU
|
||||
# values, so only forward the ones the model actually sets.
|
||||
swiglu_params: dict[str, float | None] = {}
|
||||
if activation == MoEActivation.SILU:
|
||||
swiglu_params = {"swiglu_limit": self.gemm1_clamp_limit}
|
||||
elif activation in (
|
||||
MoEActivation.SWIGLUOAI,
|
||||
MoEActivation.SWIGLUOAI_UNINTERLEAVE,
|
||||
):
|
||||
swiglu_params = {
|
||||
"swiglu_alpha": self.gemm1_alpha,
|
||||
"swiglu_beta": self.gemm1_beta,
|
||||
"swiglu_limit": self.gemm1_clamp_limit,
|
||||
}
|
||||
swiglu_kwargs = {k: v for k, v in swiglu_params.items() if v is not None}
|
||||
|
||||
flashinfer_cute_dsl_fused_moe_nvfp4(
|
||||
x=hidden_states,
|
||||
x_sf=x_sf,
|
||||
@@ -167,4 +191,5 @@ class FlashInferCuteDSLExperts(mk.FusedMoEExpertsModular):
|
||||
local_expert_offset=self.local_expert_offset,
|
||||
moe_output=output,
|
||||
activation_type=activation_to_flashinfer_int(activation),
|
||||
**swiglu_kwargs,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user