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
9 changes: 8 additions & 1 deletion python/sglang/srt/eplb/expert_location_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ def topk_ids_logical_to_physical(
def _topk_ids_logical_to_physical_static(
topk_ids: torch.Tensor, info: Optional[ExpertLocationDispatchInfo]
) -> torch.Tensor:
return info.partial_logical_to_rank_dispatch_physical_map[topk_ids]
# Using torch.take is more efficient for advanced indexing on 1D tensors
# and can be up to 2x faster than standard indexing.
# Only applies if partial_logical_to_rank_dispatch_physical_map is 1D.
# Fallback to original if not 1D.
partial_map = info.partial_logical_to_rank_dispatch_physical_map
if partial_map.ndim == 1 and topk_ids.dtype == torch.long:
return torch.take(partial_map, topk_ids)
return partial_map[topk_ids]


def _topk_ids_logical_to_physical_dynamic(
Expand Down