[NPU] support the Enable return routed experts (#17025)
This commit is contained in:
@@ -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_distribution import get_global_expert_distribution_recorder
|
||||||
from sglang.srt.eplb.expert_location_dispatch import topk_ids_logical_to_physical
|
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
|
from sglang.srt.layers.moe.topk import StandardTopKOutput, select_experts
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -18,6 +19,7 @@ def fused_topk_npu(
|
|||||||
topk_config: "TopKConfig",
|
topk_config: "TopKConfig",
|
||||||
num_token_non_padded: Optional[torch.Tensor] = None,
|
num_token_non_padded: Optional[torch.Tensor] = None,
|
||||||
expert_location_dispatch_info: Optional["ExpertLocationDispatchInfo"] = None,
|
expert_location_dispatch_info: Optional["ExpertLocationDispatchInfo"] = None,
|
||||||
|
layer_id: Optional[int] = None,
|
||||||
) -> "TopKOutput":
|
) -> "TopKOutput":
|
||||||
|
|
||||||
use_grouped_topk = topk_config.use_grouped_topk
|
use_grouped_topk = topk_config.use_grouped_topk
|
||||||
@@ -59,6 +61,7 @@ def fused_topk_npu(
|
|||||||
topk_config.torch_native = True
|
topk_config.torch_native = True
|
||||||
return select_experts(
|
return select_experts(
|
||||||
hidden_states=hidden_states,
|
hidden_states=hidden_states,
|
||||||
|
layer_id=layer_id,
|
||||||
router_logits=router_logits,
|
router_logits=router_logits,
|
||||||
topk_config=topk_config,
|
topk_config=topk_config,
|
||||||
num_token_non_padded=num_token_non_padded,
|
num_token_non_padded=num_token_non_padded,
|
||||||
@@ -68,5 +71,9 @@ def fused_topk_npu(
|
|||||||
if expert_location_dispatch_info is not None:
|
if expert_location_dispatch_info is not None:
|
||||||
topk_ids = topk_ids_logical_to_physical(topk_ids, expert_location_dispatch_info)
|
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_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)
|
return StandardTopKOutput(topk_weights, topk_ids, router_logits)
|
||||||
|
|||||||
@@ -351,6 +351,7 @@ class TopK(MultiPlatformOp):
|
|||||||
topk_config=self.topk_config,
|
topk_config=self.topk_config,
|
||||||
num_token_non_padded=num_token_non_padded,
|
num_token_non_padded=num_token_non_padded,
|
||||||
expert_location_dispatch_info=expert_location_dispatch_info,
|
expert_location_dispatch_info=expert_location_dispatch_info,
|
||||||
|
layer_id=self.layer_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
def empty_topk_output(self, device: torch.device) -> TopKOutput:
|
def empty_topk_output(self, device: torch.device) -> TopKOutput:
|
||||||
|
|||||||
Reference in New Issue
Block a user