[AMD] Use Triton softmax routing for Qwen3.5 on gfx950 (#39986)

This commit is contained in:
jacky.cheng
2026-09-21 12:02:29 -07:00
committed by GitHub
parent f702a0be29
commit 90b3f8544c
2 changed files with 163 additions and 2 deletions
+36 -2
View File
@@ -110,6 +110,7 @@ from sglang.srt.utils import (
get_compiler_backend,
is_cpu,
is_cuda,
is_gfx95_supported,
is_hip,
is_musa,
is_npu,
@@ -125,6 +126,7 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__)
_is_cuda = is_cuda()
_is_hip = is_hip()
_is_gfx95 = is_gfx95_supported()
_is_cpu = is_cpu()
_is_cpu_amx_available = cpu_has_amx_support()
_is_xpu = is_xpu()
@@ -151,6 +153,30 @@ _RENORMALIZE_SUM_EPSILON = 1e-20
_skip_hip_pad_mask = get_bool_env_var("SGLANG_MORI_NO_PAD_MASK", "False")
def _use_rocm_triton_softmax_topk(
hidden_states: torch.Tensor,
gating_output: torch.Tensor,
topk: int,
correction_bias: Optional[torch.Tensor],
num_fused_shared_experts: int,
packed_out: Optional[torch.Tensor],
) -> bool:
"""Use the lower-latency Triton router for Qwen3.5 decode-sized rows."""
return (
_use_aiter
and _is_gfx95
and hidden_states.shape[1] == 4096
and hidden_states.dtype == torch.bfloat16
and gating_output.shape[0] <= 128
and gating_output.shape[1] == 512
and gating_output.dtype == torch.bfloat16
and topk == 10
and correction_bias is None
and num_fused_shared_experts == 0
and packed_out is None
)
if _is_cuda:
try:
from flashinfer.fused_moe import fused_topk_deepseek as _fused_topk_deepseek
@@ -991,7 +1017,15 @@ def fused_topk(
topk_ids = torch.empty(M, topk, dtype=torch.int32, device=hidden_states.device)
if scoring_func == "softmax":
if _use_aiter:
use_rocm_triton = _use_rocm_triton_softmax_topk(
hidden_states,
gating_output,
topk,
correction_bias,
num_fused_shared_experts,
packed_out,
)
if _use_aiter and not use_rocm_triton:
# Use fused_topk instead of topk_softmax to auto dispatch to the correct kernel
topk_weights, topk_ids = aiter_fused_topk(
hidden_states,
@@ -1018,7 +1052,7 @@ def fused_topk(
num_token_non_padded=num_token_non_padded,
)
# ===== END TO BE REFACTORED ====
elif _is_cuda:
elif _is_cuda or use_rocm_triton:
# Unified Triton router (subsumes the AOT topk_softmax CUDA kernel).
from sglang.kernels.ops.moe.moe_fused_gate import (
moe_fused_gate as _jit_moe_fused_gate,