-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Move to moe-kernels package and switch to common MoE layer #2511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| from typing import Optional | ||
|
|
||
| import torch | ||
| import torch.nn as nn | ||
| from text_generation_server.layers.fp8 import HybridFP8UnquantLoader | ||
| from text_generation_server.layers.moe.unquantized import UnquantizedSparseMoELayer | ||
| from text_generation_server.utils.weights import ( | ||
| DefaultWeightsLoader, | ||
| UnquantizedWeight, | ||
| Weights, | ||
| ) | ||
|
|
||
|
|
||
| class SparseMoELayer(nn.Module): | ||
| """ | ||
| Layer for MoE that uses fused kernels to only apply the active experts | ||
| for each token (rather than applying all experts and selecting the | ||
| outputs of active experts). | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| n_expert_group: Optional[int], | ||
| n_experts: int, | ||
| prefix: str, | ||
| renormalize: bool, | ||
| topk: int, | ||
| topk_group: Optional[int], | ||
| weights: Weights, | ||
| gate_proj_name: str = "gate_proj", | ||
| up_proj_name: str = "up_proj", | ||
| down_proj_name: str = "down_proj", | ||
| ): | ||
| super().__init__() | ||
|
|
||
| if ( | ||
| isinstance(weights.loader, DefaultWeightsLoader) | ||
| and isinstance(weights.loader.weight_class, UnquantizedWeight) | ||
| ) or isinstance(weights.loader, HybridFP8UnquantLoader): | ||
| cls = UnquantizedSparseMoELayer | ||
| # Once we wire up GPTQ-Marlin MoE: | ||
| # elif isinstance(weights.loader, GPTQMarlinWeightsLoader) and weights.loader.sym: | ||
| # cls = GPTQMarlinSparseMoELayer | ||
| else: | ||
| raise ValueError( | ||
| f"Unsupported weights loader: {weights.loader}, sparse MoE is only supported for unquantized and GPTQ weights" | ||
| ) | ||
|
|
||
| self.moe = cls( | ||
| n_expert_group=n_expert_group, | ||
| n_experts=n_experts, | ||
| prefix=prefix, | ||
| renormalize=renormalize, | ||
| topk=topk, | ||
| topk_group=topk_group, | ||
| weights=weights, | ||
| gate_proj_name=gate_proj_name, | ||
| up_proj_name=up_proj_name, | ||
| down_proj_name=down_proj_name, | ||
| ) | ||
|
|
||
| def forward(self, x: torch.Tensor, *, gating_output: torch.Tensor) -> torch.Tensor: | ||
| return self.moe(x, gating_output=gating_output) | ||
|
|
||
| @staticmethod | ||
| def is_supported(weights: Weights) -> bool: | ||
| return ( | ||
| ( | ||
| isinstance(weights.loader, DefaultWeightsLoader) | ||
| and isinstance(weights.loader.weight_class, UnquantizedWeight) | ||
| ) | ||
| or isinstance(weights.loader, HybridFP8UnquantLoader) | ||
| # Once we wire up GPTQ-Marlin MoE: | ||
| # or isinstance(weights.loader, GPTQMarlinWeightsLoader) | ||
| ) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also see the
" me"above, and that was before the changes.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess that's what a temperature of 0.5 does. Happens a lot though: