diff --git a/vllm/model_executor/layers/fused_moe/router/fused_topk_bias_router.py b/vllm/model_executor/layers/fused_moe/router/fused_topk_bias_router.py index 84eaad7f65e..4e540826052 100644 --- a/vllm/model_executor/layers/fused_moe/router/fused_topk_bias_router.py +++ b/vllm/model_executor/layers/fused_moe/router/fused_topk_bias_router.py @@ -278,6 +278,20 @@ class FusedTopKBiasRouter(BaseRouter): input_ids: torch.Tensor | None = None, ) -> tuple[torch.Tensor, torch.Tensor]: """Compute routing using fused top-k with bias.""" + # The topk kernel dispatches dtype based on topk_ids (set by + # indices_type) and assumes input_tokens/hash_indices_table match. + # Cast them here so backends like DeepEP that require int64 indices + # don't hit a dtype mismatch against the model's int32 buffers. + hash_table = self._hash_indices_table + if indices_type is not None: + if input_ids is not None: + input_ids = input_ids.to(dtype=indices_type) + if (hash_table is not None + and hash_table.dtype != indices_type): + self._hash_indices_table = hash_table.to( + dtype=indices_type) + hash_table = self._hash_indices_table + topk_weights, topk_ids = fused_topk_bias( hidden_states=hidden_states, gating_output=router_logits, @@ -289,7 +303,7 @@ class FusedTopKBiasRouter(BaseRouter): renormalize=self.renormalize, indices_type=indices_type, input_tokens=input_ids, - hash_indices_table=self._hash_indices_table, + hash_indices_table=hash_table, routed_scaling_factor=self.routed_scaling_factor, )