Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
9bd02dc5b9
commit
1da7d3a50b
@@ -93,9 +93,7 @@ else:
|
||||
apply_shuffle_mul_sum,
|
||||
fp8_blockwise_scaled_grouped_mm,
|
||||
fused_qk_norm_rope,
|
||||
kimi_k2_moe_fused_gate,
|
||||
moe_align_block_size,
|
||||
moe_fused_gate,
|
||||
moe_sum,
|
||||
moe_sum_reduce,
|
||||
prepare_moe_input,
|
||||
@@ -181,10 +179,8 @@ else:
|
||||
"gptq_gemm",
|
||||
"gptq_shuffle",
|
||||
"int8_scaled_mm",
|
||||
"kimi_k2_moe_fused_gate",
|
||||
"merge_state_v2",
|
||||
"moe_align_block_size",
|
||||
"moe_fused_gate",
|
||||
"moe_sum",
|
||||
"moe_sum_reduce",
|
||||
"prepare_moe_input",
|
||||
|
||||
@@ -102,74 +102,9 @@ def moe_sum(
|
||||
)
|
||||
|
||||
|
||||
def moe_fused_gate(
|
||||
input_tensor,
|
||||
bias,
|
||||
num_expert_group,
|
||||
topk_group,
|
||||
topk,
|
||||
num_fused_shared_experts=0,
|
||||
routed_scaling_factor=0,
|
||||
apply_routed_scaling_factor_on_output=False,
|
||||
):
|
||||
# This fused kernel function is used to select topk expert in a hierarchical 2-layer fashion
|
||||
# it split group of expert into num_expert_group, and use top2 expert weight sum in each group
|
||||
# as the group weight to select expert groups and then select topk experts within the selected groups
|
||||
# the #experts is decided by the input tensor shape and we currently only support power of 2 #experts
|
||||
# and #experts should be divisible by num_expert_group. #expert/num_expert_group <= 32 is limited for now.
|
||||
# for non-supported case, we suggest to use the biased_grouped_topk func in sglang.srt.layers.moe.topk
|
||||
# num_fused_shared_experts: if > 0, the last several experts will be
|
||||
# replaced with shared experts. the shared experts will be divided by the
|
||||
# routed_scaling_factor - this is intended to cancel out later when routed+shared
|
||||
# output is scaled so that shared experts are not scaled.
|
||||
# routed_scaling_factor: if > 0, the experts will be scaled by this factor
|
||||
# apply_routed_scaling_factor_on_output: if true, output will be
|
||||
# scaled by the routed_scaling_factor
|
||||
return torch.ops.sgl_kernel.moe_fused_gate.default(
|
||||
input_tensor,
|
||||
bias,
|
||||
num_expert_group,
|
||||
topk_group,
|
||||
topk,
|
||||
num_fused_shared_experts,
|
||||
routed_scaling_factor,
|
||||
apply_routed_scaling_factor_on_output,
|
||||
)
|
||||
|
||||
|
||||
def kimi_k2_moe_fused_gate(
|
||||
input_tensor,
|
||||
bias,
|
||||
topk,
|
||||
renormalize=True,
|
||||
routed_scaling_factor=1.0,
|
||||
apply_routed_scaling_factor_on_output=False,
|
||||
):
|
||||
"""
|
||||
Simplified fused kernel for Kimi K2 model (num_expert_group=1).
|
||||
This kernel removes the grouped topk logic since all experts belong to a single group.
|
||||
|
||||
Args:
|
||||
input_tensor: Gating output tensor [num_tokens, num_experts]
|
||||
bias: Correction bias tensor [num_experts]
|
||||
topk: Number of experts to select per token
|
||||
renormalize: Whether to renormalize the topk weights
|
||||
routed_scaling_factor: Scaling factor for expert weights
|
||||
apply_routed_scaling_factor_on_output: If true, apply scaling factor to output
|
||||
|
||||
Returns:
|
||||
Tuple of (topk_weights, topk_ids)
|
||||
- topk_weights: [num_tokens, topk] float32 tensor
|
||||
- topk_ids: [num_tokens, topk] int32 tensor
|
||||
"""
|
||||
return torch.ops.sgl_kernel.kimi_k2_moe_fused_gate.default(
|
||||
input_tensor,
|
||||
bias,
|
||||
topk,
|
||||
renormalize,
|
||||
routed_scaling_factor,
|
||||
apply_routed_scaling_factor_on_output,
|
||||
)
|
||||
# moe_fused_gate / kimi_k2_moe_fused_gate (AOT gate kernels) retired — the gate/topk
|
||||
# path is consolidated onto the unified Triton router in
|
||||
# python/sglang/jit_kernel/moe_fused_gate.py (sglang issue #26771).
|
||||
|
||||
|
||||
def fp8_blockwise_scaled_grouped_mm(
|
||||
|
||||
Reference in New Issue
Block a user