Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions python/sglang/srt/layers/moe/topk.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def routing(
_is_npu = is_npu()
_use_aiter = get_bool_env_var("SGLANG_USE_AITER") and _is_hip
_is_musa = is_musa()
_fused_topk_deepseek = None

# Epsilon added to the top-k weight sum before renormalization, matching the
# DeepSeek reference gate (modeling_deepseek.py: `topk_weight.sum(...) + 1e-20`)
Expand All @@ -145,6 +146,18 @@ def routing(
_skip_hip_pad_mask = get_bool_env_var("SGLANG_MORI_NO_PAD_MASK", "False")


def _flashinfer_fused_topk_supports_device(device: torch.device) -> bool:
"""Return whether FlashInfer's DeepSeek top-k kernel supports ``device``."""
support_check = getattr(
_fused_topk_deepseek, "is_compute_capability_supported", None
)
if support_check is None:
return True

major, minor = torch.cuda.get_device_capability(device)
return support_check(major * 10 + minor)


if _is_cuda:
try:
from flashinfer.fused_moe import fused_topk_deepseek as _fused_topk_deepseek
Expand Down Expand Up @@ -1532,6 +1545,7 @@ def biased_grouped_topk_gpu(
if (
_is_cuda
and fused_topk_deepseek is not None
and _flashinfer_fused_topk_supports_device(gating_output.device)
and is_power_of_two(num_experts)
# flashinfer constraints (applied to routed experts only)
and topk_routed <= 8
Expand Down
Loading