Skip to content
Merged
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
4 changes: 0 additions & 4 deletions python/sglang/srt/managers/expert_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,6 @@ def __init__(self, *args, **kwargs):
def on_select_experts(self, layer_idx: int, topk_ids: torch.Tensor):
topk_ids = topk_ids.flatten()
mask = topk_ids != -1
assert self._data[layer_idx, :].shape == topk_ids.shape, (
"Shape mismatch between data and topk_ids."
"Selecting expert is not supported for multiple token prediction at the moment."
)
self._data[layer_idx, :].scatter_add_(
dim=0, index=topk_ids.masked_fill(~mask, 0).long(), src=mask.int()
)
Comment on lines 482 to 484
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding an assertion to validate that the expert IDs in topk_ids are within the valid range. This can prevent potential out-of-bounds errors in the scatter_add_ operation.

Suggested change
self._data[layer_idx, :].scatter_add_(
dim=0, index=topk_ids.masked_fill(~mask, 0).long(), src=mask.int()
)
mask = topk_ids != -1
if topk_ids.numel() > 0:
assert topk_ids.max() < self._data.shape[1]

Expand Down
Loading