From c21f6f19cfe79848a6cd5474dceedffc3591c344 Mon Sep 17 00:00:00 2001 From: Cheng Wan <54331508+ch-wan@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:48:51 -0700 Subject: [PATCH] [MoE] Fix moe_fused_gate out-of-range expert id on all-NaN rows (fixes eagle_dp_attention crash) (#30079) --- python/sglang/jit_kernel/moe_fused_gate.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/sglang/jit_kernel/moe_fused_gate.py b/python/sglang/jit_kernel/moe_fused_gate.py index 50c9124d8..df203bc5e 100644 --- a/python/sglang/jit_kernel/moe_fused_gate.py +++ b/python/sglang/jit_kernel/moe_fused_gate.py @@ -167,6 +167,9 @@ def _router_triton_kernel( biased = tl.where(mask_n[None, :], biased, -float("inf")) # [BLOCK_M, BLOCK_N] + # Map NaN -> a finite floor + biased = tl.where(biased == biased, biased, -1e30) # [BLOCK_M, BLOCK_N] + # Grouped routing (DeepSeek-V3 noaux_tc): per-group score = sum of the top-2 # biased values; keep TOPK_GROUP groups (lowest group id wins ties); mask the # experts of dropped groups to -inf before the top-k below. Weight is still the