[Bugfix][NPU] Fix/Refactor routed scaling factor application in MoE routing (#31449)
This commit is contained in:
@@ -74,7 +74,8 @@ def fused_topk_npu(
|
|||||||
topk_weights = scores.gather(1, topk_ids)
|
topk_weights = scores.gather(1, topk_ids)
|
||||||
if renormalize:
|
if renormalize:
|
||||||
topk_weights = topk_weights / topk_weights.sum(dim=-1, keepdim=True)
|
topk_weights = topk_weights / topk_weights.sum(dim=-1, keepdim=True)
|
||||||
topk_weights = _apply_routed_scaling_after_renorm(topk_weights, topk_config)
|
else:
|
||||||
|
topk_weights = topk_weights * topk_config.routed_scaling_factor
|
||||||
topk_weights = topk_weights.to(torch.float32)
|
topk_weights = topk_weights.to(torch.float32)
|
||||||
|
|
||||||
# Support grouped top-k or correction bias or sigmoid or routed_scaling_factor
|
# Support grouped top-k or correction bias or sigmoid or routed_scaling_factor
|
||||||
|
|||||||
@@ -265,6 +265,7 @@ class LLaDA2MoeSparseMoeBlock(nn.Module):
|
|||||||
correction_bias=self.correction_bias,
|
correction_bias=self.correction_bias,
|
||||||
scoring_func=self.score_function,
|
scoring_func=self.score_function,
|
||||||
routed_scaling_factor=self.routed_scaling_factor,
|
routed_scaling_factor=self.routed_scaling_factor,
|
||||||
|
apply_routed_scaling_factor_on_output=_is_npu,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.experts = get_moe_impl_class(quant_config)(
|
self.experts = get_moe_impl_class(quant_config)(
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class TestLLaDA2Mini(GSM8KAscendMixin, CustomTestCase):
|
|||||||
"ascend",
|
"ascend",
|
||||||
"--dllm-algorithm",
|
"--dllm-algorithm",
|
||||||
"LowConfidence", # TODO: Add dLLM configurations
|
"LowConfidence", # TODO: Add dLLM configurations
|
||||||
|
"--no-dllm-fdfo", # FDFO (PR #27551) halves single-batch speed on NPU; use sync mode
|
||||||
]
|
]
|
||||||
env = {
|
env = {
|
||||||
**os.environ,
|
**os.environ,
|
||||||
|
|||||||
Reference in New Issue
Block a user