[Module] Modularize MoE components #2571
Open
acisseJZhong wants to merge 6 commits intogh/acisseJZhong/3/basefrom
Open
[Module] Modularize MoE components #2571acisseJZhong wants to merge 6 commits intogh/acisseJZhong/3/basefrom
acisseJZhong wants to merge 6 commits intogh/acisseJZhong/3/basefrom
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
tianyu-l
reviewed
Mar 15, 2026
| score_func: Literal["softmax", "sigmoid"] = "sigmoid" | ||
| route_norm: bool = False | ||
| route_scale: float = 1.0 | ||
| gate: Linear.Config = field(default_factory=Linear.Config) |
Contributor
There was a problem hiding this comment.
Maybe better if it doesn't come with a default, so that model config constructor have to specify.
| _debug_force_load_balance: bool = False, | ||
| ): | ||
| @dataclass(kw_only=True, slots=True) | ||
| class Config(Module.Config): |
Contributor
There was a problem hiding this comment.
makes sense. I wonder if we should put the following to router as well
tokens_per_expertandexpert_biasbuffer to router moduleload_balance_coeffto router config
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.
Stack from ghstack (oldest at bottom):
Motivation
Continues the modularization effort from #2428 (Embedding), #2434 (RMSNorm), and
#2527 (Linear). This PR makes MoE components (GroupedExperts,
TokenChoiceTopKRouter, TokenReorderer) inherit from Module and use the
Config/build() pattern, enabling per-component configurability and consistent
weight initialization.
Summary
hidden_dim, and num_experts use field(init=False) so they are set at build() time
by the parent MoE.
Replaces the flat gate_bias: bool field with gate: Linear.Config, enabling full
gate configuration (e.g., Linear.Config(bias=True)). dim and num_experts use
field(init=False).
module). num_experts and top_k use field(init=False).
route_scale, gate_bias, use_grouped_mm, num_expert_groups, num_limited_groups,
_debug_force_load_balance) with nested experts: GroupedExperts.Config and router:
TokenChoiceTopKRouter.Config.
router/expert configs.
nested config propagation for all modularized components.
cc @fegin #2540 may needs to rebase on this.