Repository navigation
LatentMoE implementation - #799
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c82c0cc525
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7d8c4fe33
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35524df607
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50ea3068f7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f221bf1201
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return routed_output | ||
| if self.latent_up_proj_input_norm is not None: | ||
| routed_output = self.latent_up_proj_input_norm(routed_output) | ||
| return self.latent_up_proj(routed_output) |
There was a problem hiding this comment.
Cast DDP latent outputs before up-projection
When a LatentMoE OLMoDDPTransformerBlock is built with float32 routed experts/projections but a routed backend returns BF16 expert output, this call feeds a BF16 activation directly into an FP32 nn.Linear, which raises a matmul dtype mismatch before the routed branch can be merged. The non-DDP MoE path already casts the routed output to latent_up_proj.weight.dtype; this helper needs the same cast before applying the up projection.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
my codex independently agreed with this, so this seems reasonable to me!
jacob-morrison
left a comment
There was a problem hiding this comment.
LGTM! One comment just for type safety, but otherwise seems good
| return routed_output | ||
| if self.latent_up_proj_input_norm is not None: | ||
| routed_output = self.latent_up_proj_input_norm(routed_output) | ||
| return self.latent_up_proj(routed_output) |
There was a problem hiding this comment.
my codex independently agreed with this, so this seems reasonable to me!
Summary
This PR adds LatentMoE support to the original MoE and MoE v2 implementations.
Instead of running routed experts on the model’s hidden representation, LatentMoE wraps the routed expert path with two shared linear projections:
The router continues to compute gating decisions from the original model-space representation. Only the routed payload and routed expert computation use
the latent dimension.
Shared experts, transformer norms, and residual operations remain in model space.
Configuration
Original MoE
For the original MoE implementation, add latent_moe to MoEConfig:
The router remains model-width, while the routed experts are built automatically with latent_dim.
MoE v2
For MoE v2, configure the router with the model dimension and the routed experts with the latent dimension:
The following dimensional constraints are enforced:
Leave latent_moe=None to use the standard MoE architecture.
Optional pre-up-projection normalization
Normalization before the ℓ → d projection is disabled by default.
Enable it with:
When enabled without an explicit configuration, a bias-free RMSNorm is used.
A different normalization can be configured explicitly:
Projection biases are disabled by default and can be enabled with bias=True.
Supported execution paths
LatentMoE is integrated with:
Routing remains model-width in every path, while routed communication and expert computation use latent_dim.