Repository navigation
[MoE] Add overridable hooks for TokenChoiceTopKRouter - #4609
Merged
Merged
Conversation
jinsooihm
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
September 11, 2026 18:55
tianyu-l
requested changes
Sep 11, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
Without context, hard to evaluate this PR.
E.g. for deepseek v4, we added https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe.py#L290
jinsooihm
force-pushed
the
generalize-topkrouter
branch
from
September 14, 2026 19:35
5f7de40 to
1671e3d
Compare
Contributor
Author
|
@tianyu-l Updated after offline discussion. |
tianyu-l
approved these changes
Sep 14, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
please address remaining comments
Contributor
There was a problem hiding this comment.
maybe
Suggested change
| class BinaryActivationFn(Function[torch.Tensor], ABC): |
| gate_param_init: dict[str, Callable], | ||
| top_k: int = 1, | ||
| score_func: Literal["sigmoid", "softmax", "sqrtsoftplus"] = "sigmoid", | ||
| score_func: UnaryActivationFn.Config | None = None, |
Contributor
Author
There was a problem hiding this comment.
All models specify the function, only the tests call it without specifying which defaults to sigmoid. We can remove it.
| gate: RouterGateLinear.Config | ||
| top_k: int = 1 | ||
| score_func: Literal["softmax", "sigmoid", "sqrtsoftplus"] = "sigmoid" | ||
| score_func: UnaryActivationFn.Config = field(default_factory=Sigmoid.Config) |
Contributor
There was a problem hiding this comment.
can it not have a default?
acisseJZhong
added a commit
that referenced
this pull request
Sep 15, 2026
## Summary - pass an explicit Sigmoid score function to the padding-mask router tests - align the tests added by #4594 with the required score_func API introduced by #4609 - fix the two CPU test failures observed in the PR #2769 CI job ## Test plan - pytest -q tests/unit_tests/cpu/test_moe.py - pre-commit hooks for ufmt, flake8, pydoclint, and codespell on tests/unit_tests/cpu/test_moe.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TokenChoiceTopKRouteris a module with a largeforward.Some models may want to override how the score is computed or how the normalization is done.
Extracting and exposing them as overridable functions
_compute_scoresand_normalize_topk_scoreswould make it easier.Test Plan
pytest -q tests/unit_tests/cpu/test_moe.py tests/unit_tests/cpu/test_router_gate_linear.pyTargeted pre-commit checks for
moe.pyandtest_moe.pypyrefly check torchtitan/models/common/moe.pyCompared upstream/main (773e16e) against 5f7de40 using scripts/loss_compare.py, --debug.seed=42, --debug.deterministic, and 10 training steps.