[Bugfix] Fix topk_ids indices_type for CUTLASS w8a8 FP8 MoE (#20166)

Signed-off-by: Ming Yang <yming@meta.com>
This commit is contained in:
Ming Yang
2025-07-08 23:10:57 +00:00
committed by GitHub
parent baba0389f7
commit c438183e99
3 changed files with 17 additions and 11 deletions
@@ -78,7 +78,7 @@ class PplxPrepareAndFinalize(mk.FusedMoEPrepareAndFinalize):
return self.max_num_tokens
def topk_indices_dtype(self) -> Optional[torch.dtype]:
return torch.uint32
return torch.int32
def num_dispatchers(self) -> int:
return self.num_dispatchers_
@@ -100,7 +100,9 @@ class PplxPrepareAndFinalize(mk.FusedMoEPrepareAndFinalize):
hidden_dim = a1.size(-1) # K
assert topk_ids.size(0) == num_tokens
# assert expert_map is None, "NYI"
assert expert_map is None, """with expert map, -1 id is used for
non-local token; this causes error when casting ids to the
topk_indices_dtype() uint32"""
# Is this always going to be a1.device?
device = a1.device
@@ -929,9 +929,12 @@ class CompressedTensorsW8A8Fp8MoECutlassMethod(CompressedTensorsMoEMethod):
num_expert_group=num_expert_group,
custom_routing_function=custom_routing_function,
scoring_func=scoring_func,
e_score_correction_bias=e_score_correction_bias,
indices_type=self.topk_indices_dtype,
)
e_score_correction_bias=e_score_correction_bias)
a1_scale = layer.w13_input_scale
a2_scale = layer.w2_input_scale
per_act_token = a1_scale.numel() != 1 if a1_scale is not None else (
a2_scale.numel() != 1 if a2_scale is not None else False)
return self.fused_experts(
x,
@@ -939,13 +942,14 @@ class CompressedTensorsW8A8Fp8MoECutlassMethod(CompressedTensorsMoEMethod):
layer.w2_weight,
topk_weights,
topk_ids,
per_act_token=per_act_token,
activation=activation,
global_num_experts=global_num_experts,
expert_map=None if self.disable_expert_map else expert_map,
w1_scale=layer.w13_weight_scale,
w2_scale=layer.w2_weight_scale,
a1_scale=layer.w13_input_scale,
a2_scale=layer.w2_input_scale,
a1_scale=a1_scale,
a2_scale=a2_scale,
)