-
Notifications
You must be signed in to change notification settings - Fork 31.2k
Add afmoe model #42168
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
Open
alyosha-swamy
wants to merge
3
commits into
huggingface:main
Choose a base branch
from
alyosha-swamy:add_afmoe_model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add afmoe model #42168
+3,604
−0
Conversation
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
6b08d17 to
e3ad5e9
Compare
e3ad5e9 to
3a4280c
Compare
Collaborator
ArthurZucker
left a comment
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.
nice work!
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: afmoe, auto |
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.
Summary
This PR adds support for the AFMoE (Arcee Foundational Mixture of Experts) model architecture for the upcoming Trinity-Mini and Trinity-Nano releases. AFMoE is a decoder-only transformer model featuring a sparse Mixture of Experts (MoE) approach, combining token-choice routing with shared experts and several architectural innovations for efficient inference and improved performance.
Model Description
AFMoE features the following key architectural components:
Mixture of Experts with Shared Experts: Combines routed experts (activated per-token via learned routing) with always-active shared experts for stable base computation
Token-Choice Routing: Uses sigmoid or softmax-based routing with normalization and scaling for expert selection
Q/K Normalization and Gating: Applies RMSNorm to query and key projections and uses sigmoid gating on attention outputs for improved training stability
Hybrid Attention Patterns: Alternates between sliding window attention and full attention across layers for efficiency with long contexts
Dual Normalization: Uses pre- and post-normalization around both attention and MLP blocks for training stability
Configurable Dense Layers: Allows initial layers to use dense MLPs before transitioning to sparse MoE layers (
num_dense_layers)Implementation Details
Modular implementation leveraging transformers' modular architecture:
Efficient
AfmoeRMSNormfor layer normalizationAfmoeRotaryEmbeddingfor positional encodingAfmoeAttentionclass implementing Q/K normalization and output gatingAfmoeTokenChoiceRouterfor expert selectionAfmoeMoEclass implementing shared + routed experts architectureAfmoeDecoderLayerintegrating attention and MoE blocks with dual normalizationTesting
arcee-ai/Trinity-MiniDocumentation
docs/source/en/model_doc/afmoe.md