Fix nan in global scaling factor for large scale nvfp4 EP (#13162)

This commit is contained in:
Shu Wang
2025-11-12 15:32:23 -08:00
committed by GitHub
parent 4eda9969e8
commit 7aa443903d
2 changed files with 17 additions and 10 deletions
+13 -9
View File
@@ -284,9 +284,17 @@ class ExpertLocationMetadata:
# -------------------------------- usage ------------------------------------
def logical_to_all_physical(
self, layer_id: int, logical_expert_id: int
self,
layer_id: int,
logical_expert_id: int,
require_global_experts: bool = False,
) -> List[int]:
# Use CPU copy to avoid GPU→CPU sync on every call, which is expensive in update weights scenario
if require_global_experts:
num_physical_experts = self.logical_to_all_physical_map_cpu[layer_id].shape[
-1
]
return list(torch.arange(0, num_physical_experts))
return [
physical_expert_id
for physical_expert_id in self.logical_to_all_physical_map_cpu[
@@ -355,14 +363,10 @@ def _compute_logical_to_all_physical_map(
)
# Replace by the nearest physical 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
if nearest_expert != -1:
logical_to_all_physical_map[layer_id][logical_expert_id] = [
nearest_expert
]
logical_to_all_physical_map = _pad_nested_array(
logical_to_all_physical_map, pad_value=-1