Repository navigation
Add v2 shared experts - #724
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
4fe872d to
0fba859
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7c835ca06
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
d7c835c to
e8d91a8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13da5b8082
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Adds `nn/moe/v2/shared_experts.py`: `SharedExperts` and `SharedExpertsConfig`. Shared experts act like a feed-forward applied to every token, but support more than one expert by column-packing the up/gate projections into a single GEMM and running the per-expert down projection as a grouped (batched) GEMM, with a SwiGLU nonlinearity. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Guard the optional `nvtx` import with the `olmo_core._nvtx` no-op fallback. - Use the builtin `tuple` annotation instead of `typing.Tuple`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Cover config num_params, the forward output shape (E, B, S, D), the single-expert case, and that the split forward1/forward2 (used for EP overlap) matches the fused forward. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
SharedExperts hardcodes SiLU; the standard FeedForward exposes a configurable ActivationFunction, and the v1 MoE MLP / routed_experts each roll their own. Flag the duplication for a future unification. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
w_up_gate and w_down were left as raw torch.empty storage with no reset_parameters, so SharedExpertsConfig.build() produced uninitialized weights -> NaNs/nondeterministic output in production (the tests masked it by calling normal_() manually). Add reset_parameters() with kaiming_uniform_(a=sqrt(5)) and call it from __init__, matching the v1 MoE expert MLPs. Drop the manual test init and add a regression test asserting build() yields finite weights/output. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Align SharedExperts.reset_parameters with the v2 router's reset_parameters and the default std the model-level init (init_moe_v2) applies, instead of the kaiming_uniform default. init_moe_v2 still overrides these at model construction; this is just the standalone-build default. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…th-scaled std Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
num_params() listed a :param d_model: it doesn't take (copy-paste), and build() had no docstring. Correct both to match the codebase convention. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…docstring Mirror the note added to MoERouterConfigV2: the v2 configs store dimension fields directly, unlike the rest of the codebase which passes them only to build(); flag for future unification. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Existing tests only checked output shape and forward1/forward2 split consistency (both could be wrong identically). Add a per-expert SwiGLU + down-projection reference and assert the vectorized forward matches it. Also drop a stale init comment. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Document that forward1/forward2 are numerically-equivalent halves of forward, split so the EP path can run shared experts on a separate stream and overlap each half with the routed experts' dispatch/combine all-to-all. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace the "unify the SwiGLU implementations" TODO with a note that the SiLU gating is intentional (matching forward1/forward2 and the routed kernels), and that unifying the codebase's SwiGLU sites is a general cross-module refactor tracked separately rather than done in this precursor. Also simplify _swiglu to a one-liner. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
f4aa997 to
a68fc88
Compare
Adds
nn/moe/v2/shared_experts.py:SharedExpertsandSharedExpertsConfig.Shared experts act like a feed-forward applied to every token, but support more than one expert. The up/gate projections of all experts are column-packed into one weight so the first projection is a single GEMM
(BS, D) @ (D, E*2H); the result is split per-expert into up/gate, run through a SwiGLU nonlinearity, and the per-expert down projection is a grouped (batched) GEMM(E, BS, H) x (E, H, D) -> (E, BS, D). A splitforward1/forward2variant is provided so the projection and the down-GEMM can overlap with expert-parallel communication.Depends only on
olmo_core.config;nvtxis an optional import with theolmo_core._nvtxno-op fallback. Includes CPU unit tests covering num_params, the forward output shape, the single-expert case, and that the split forward matches the fused one.🤖 Generated with Claude Code