Fix nan in global scaling factor for large scale nvfp4 EP (#13162)
This commit is contained in:
@@ -284,9 +284,17 @@ class ExpertLocationMetadata:
|
|||||||
# -------------------------------- usage ------------------------------------
|
# -------------------------------- usage ------------------------------------
|
||||||
|
|
||||||
def logical_to_all_physical(
|
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]:
|
) -> List[int]:
|
||||||
# Use CPU copy to avoid GPU→CPU sync on every call, which is expensive in update weights scenario
|
# 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 [
|
return [
|
||||||
physical_expert_id
|
physical_expert_id
|
||||||
for physical_expert_id in self.logical_to_all_physical_map_cpu[
|
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
|
# Replace by the nearest physical expert
|
||||||
mapped_physical_experts = logical_to_all_physical_map[layer_id][
|
if nearest_expert != -1:
|
||||||
logical_expert_id
|
logical_to_all_physical_map[layer_id][logical_expert_id] = [
|
||||||
]
|
nearest_expert
|
||||||
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_nested_array(
|
||||||
logical_to_all_physical_map, pad_value=-1
|
logical_to_all_physical_map, pad_value=-1
|
||||||
|
|||||||
@@ -517,9 +517,12 @@ class FusedMoE(torch.nn.Module):
|
|||||||
# This is a shared expert.
|
# This is a shared expert.
|
||||||
physical_expert_ids = [expert_id]
|
physical_expert_ids = [expert_id]
|
||||||
else:
|
else:
|
||||||
|
require_global_experts = getattr(
|
||||||
|
param, "_sglang_require_global_experts", False
|
||||||
|
)
|
||||||
physical_expert_ids = (
|
physical_expert_ids = (
|
||||||
global_expert_location_metadata.logical_to_all_physical(
|
global_expert_location_metadata.logical_to_all_physical(
|
||||||
self.layer_id, expert_id
|
self.layer_id, expert_id, require_global_experts
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user