Open
Conversation
merveenoyan
reviewed
Aug 28, 2025
|
|
||
| # Three MoEs | ||
|
|
||
| Three Ways to Compute Mixture of Experts (MoE) in PyTorch |
Contributor
There was a problem hiding this comment.
might be nice to put this on the title
|
|
||
| Three Ways to Compute Mixture of Experts (MoE) in PyTorch | ||
|
|
||
| Mixture of Experts (MoE) looks complex, but under the hood it’s just: |
Contributor
There was a problem hiding this comment.
perhaps link to this blog so people have more initial context https://huggingface.co/blog/moe
|
|
||
| ## Step 1: Routing | ||
|
|
||
| Every token chooses its top-k experts with softmaxed scores. |
Contributor
There was a problem hiding this comment.
would be nice to give just a little bit more context
| 2. Apply MLPs (one per expert). | ||
| 3. Recombine outputs with routing weights. | ||
|
|
||
| Below are **three ways** to compute MoE in PyTorch — from simple to complex. |
Contributor
There was a problem hiding this comment.
Suggested change
| Below are **three ways** to compute MoE in PyTorch — from simple to complex. | |
| Below are **three ways** to build MoEs in PyTorch — from simple to complex. |
| Quick test: | ||
|
|
||
| ```python | ||
| hs = torch.randn(B, S, H) |
Contributor
There was a problem hiding this comment.
very nice to have simple reproducible snippets, would be nice to put these into a notebook and link at the end so people don't have to copy paste to try
Contributor
There was a problem hiding this comment.
in general let's avoid single letter variable names and find meaningful ones!
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.
This article explores three different ways to compute MoE and focuses on the "how" of MoE