Skip to content

Commit 6521ee2

Browse files
ilmlclaude
andcommitted
fix: add missing dense_output parameter to topk_routing_with_score_function
The router.py passes dense_output=True for inference mode but the merge took dev's version of moe_utils.py which lacks this parameter. Added from main to fix TypeError in InferenceTopKRouter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fc2d334 commit 6521ee2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

megatron/core/transformer/moe/moe_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ def topk_routing_with_score_function(
662662
expert_bias: Optional[torch.Tensor] = None,
663663
fused: bool = False,
664664
router_replay: Optional['RouterReplay'] = None,
665+
dense_output: bool = False,
665666
) -> Tuple[torch.Tensor, torch.Tensor]:
666667
"""Compute the routing probabilities and map for top-k selection with score function.
667668
@@ -774,6 +775,9 @@ def compute_topk(scores, topk, num_groups=None, group_topk=None):
774775
if scaling_factor:
775776
probs = probs * scaling_factor
776777

778+
if dense_output:
779+
return probs, top_indices
780+
777781
if torch.are_deterministic_algorithms_enabled():
778782
# build [num_tokens, num_experts] from [num_tokens, topk]
779783
routing_probs = torch.zeros_like(logits)

0 commit comments

Comments
 (0)