[NPU] support the Enable return routed experts (#17025)

This commit is contained in:
jiashaokun-1
2026-02-01 18:31:39 +08:00
committed by GitHub
parent 27bec34203
commit 0fe282543f
2 changed files with 8 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ from sgl_kernel_npu.norm.l1_norm import l1_norm
from sglang.srt.eplb.expert_distribution import get_global_expert_distribution_recorder
from sglang.srt.eplb.expert_location_dispatch import topk_ids_logical_to_physical
from sglang.srt.layers.moe.routed_experts_capturer import get_global_experts_capturer
from sglang.srt.layers.moe.topk import StandardTopKOutput, select_experts
if TYPE_CHECKING:
@@ -18,6 +19,7 @@ def fused_topk_npu(
topk_config: "TopKConfig",
num_token_non_padded: Optional[torch.Tensor] = None,
expert_location_dispatch_info: Optional["ExpertLocationDispatchInfo"] = None,
layer_id: Optional[int] = None,
) -> "TopKOutput":
use_grouped_topk = topk_config.use_grouped_topk
@@ -59,6 +61,7 @@ def fused_topk_npu(
topk_config.torch_native = True
return select_experts(
hidden_states=hidden_states,
layer_id=layer_id,
router_logits=router_logits,
topk_config=topk_config,
num_token_non_padded=num_token_non_padded,
@@ -68,5 +71,9 @@ def fused_topk_npu(
if expert_location_dispatch_info is not None:
topk_ids = topk_ids_logical_to_physical(topk_ids, expert_location_dispatch_info)
get_global_expert_distribution_recorder().on_select_experts(topk_ids=topk_ids)
get_global_experts_capturer().capture(
layer_id=layer_id,
topk_ids=topk_ids,
)
return StandardTopKOutput(topk_weights, topk_ids, router_logits)

View File

@@ -351,6 +351,7 @@ class TopK(MultiPlatformOp):
topk_config=self.topk_config,
num_token_non_padded=num_token_non_padded,
expert_location_dispatch_info=expert_location_dispatch_info,
layer_id=self.layer_id,
)
def empty_topk_output(self, device: torch.device) -> TopKOutput: