|
28 | 28 | from sglang.srt.managers.schedule_batch import global_server_args_dict |
29 | 29 | from sglang.srt.model_executor.forward_batch_info import ForwardBatch |
30 | 30 | from sglang.srt.server_args import ServerArgs |
31 | | -from sglang.srt.utils import Withable, get_bool_env_var |
| 31 | +from sglang.srt.utils import Withable, get_bool_env_var, get_compiler_backend |
32 | 32 |
|
33 | 33 | logger = logging.getLogger(__name__) |
34 | 34 |
|
@@ -446,9 +446,16 @@ def collect(self) -> Dict: |
446 | 446 | class _SelectExpertsSinglePassGatherer(_LayerBasedGpuSinglePassGatherer): |
447 | 447 | # can optimize (e.g. fuse) |
448 | 448 | def on_select_experts(self, layer_idx: int, topk_ids: torch.Tensor): |
| 449 | + self._on_select_experts_impl(self.data, layer_idx, topk_ids) |
| 450 | + |
| 451 | + @staticmethod |
| 452 | + @torch.compile(dynamic=True, backend=get_compiler_backend()) |
| 453 | + def _on_select_experts_impl( |
| 454 | + self_data: torch.Tensor, layer_idx: int, topk_ids: torch.Tensor |
| 455 | + ): |
449 | 456 | topk_ids = topk_ids.flatten() |
450 | 457 | mask = topk_ids != -1 |
451 | | - self._data[layer_idx, :].scatter_add_( |
| 458 | + self_data[layer_idx, :].scatter_add_( |
452 | 459 | dim=0, index=topk_ids.masked_fill(~mask, 0).long(), src=mask.int() |
453 | 460 | ) |
454 | 461 |
|
|
0 commit comments