From 99e25805f54ef5ccc49ce6c32ddd8c7b067a6d6a Mon Sep 17 00:00:00 2001 From: Baizhou Zhang Date: Tue, 11 Nov 2025 14:44:57 -0800 Subject: [PATCH] [Fix] Fix nan error for large scale ep (#12866) --- python/sglang/srt/eplb/expert_location.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/python/sglang/srt/eplb/expert_location.py b/python/sglang/srt/eplb/expert_location.py index 4dff84152..0fdff48fe 100644 --- a/python/sglang/srt/eplb/expert_location.py +++ b/python/sglang/srt/eplb/expert_location.py @@ -355,10 +355,14 @@ def _compute_logical_to_all_physical_map( ) # Replace by the nearest physical expert - if nearest_expert != -1: - logical_to_all_physical_map[layer_id][logical_expert_id] = [ - nearest_expert - ] + mapped_physical_experts = logical_to_all_physical_map[layer_id][ + logical_expert_id + ] + if ( + nearest_expert != -1 + and nearest_expert not in mapped_physical_experts + ): + mapped_physical_experts[0] = nearest_expert logical_to_all_physical_map = _pad_nested_array( logical_to_all_physical_map, pad_value=-1