feat: add nomic-embed-text-v2-moe via Candle backend#228
Merged
Anush008 merged 3 commits intoAnush008:mainfrom Feb 19, 2026
Merged
feat: add nomic-embed-text-v2-moe via Candle backend#228Anush008 merged 3 commits intoAnush008:mainfrom
Anush008 merged 3 commits intoAnush008:mainfrom
Conversation
Add support for nomic-ai/nomic-embed-text-v2-moe, the first general-purpose Mixture-of-Experts embedding model (475M total / 305M active params, 8 experts top-2 routing). No ONNX export exists for this model due to MoE dynamic routing, so this implements the full NomicBert+MoE architecture using candle-nn, following the same standalone pattern as Qwen3. Architecture highlights: - Post-norm NomicBert encoder (12 layers) - Alternating dense/MoE FFN layers (megablocks convention) - Combined Wqkv projection with RoPE (non-interleaved) - Bidirectional attention (no causal mask) - Mean pooling + L2 normalization - XLMRoberta tokenizer (250k vocab, 100+ languages) Feature-gated behind `nomic-v2-moe`, same candle deps as `qwen3`. Closes Anush008#227
- Replace manual NomicLayerNorm with candle_nn::LayerNorm (-25 lines, battle-tested impl with proper F16/BF16 upcast handling) - Fix NaN panic in MoE router: partial_cmp().unwrap() → total_cmp() - Fix pad_token "[PAD]" → "<pad>" (XLMRoberta convention) - Pre-compute attention scale tensor (was allocating per forward call) - Fix rotary_dim: store full dim instead of halved-then-doubled - Fix misleading dropout comment (was citing wrong config value) - Add note about CPU-side MoE dispatch for GPU awareness - Fix clippy: manual modulo → is_multiple_of() Net -26 lines. Zero warnings, identical test scores.
- Run cargo fmt to pass upstream CI's format check - Add nomic-embed-text-v2-moe to supported models list in README - Add usage section with Cargo.toml feature flag and code example
Anush008
approved these changes
Feb 19, 2026
Owner
Anush008
left a comment
There was a problem hiding this comment.
Thanks for taking the time to contribute @samvallad33
LGTM!
|
🎉 This PR is included in version 5.11.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Summary
Adds support for nomic-embed-text-v2-moe, the first general-purpose Mixture-of-Experts embedding model (475M total / 305M active params, 8 experts top-2 routing). It outperforms nomic-embed-text-v1.5 on both BEIR and MIRACL with ~100 language support.
No ONNX export exists for this model because MoE dynamic routing cannot be cleanly traced/exported. This implements the full NomicBert+MoE architecture in candle-nn, following the same standalone pattern established by Qwen3.
Architecture
Integration
nomic-v2-moe = ["dep:candle-core", "dep:candle-nn", "hf-hub"]mkl,accelerate,cuda,cudnn,metalfeature setsNomicV2MoeTextEmbeddingwithfrom_hf()+embed()lib.rsbehind#[cfg(feature = "nomic-v2-moe")]Files changed
Cargo.toml— feature flag additionssrc/models/mod.rs— module registrationsrc/models/nomic_v2_moe.rs— full model implementation (~830 lines)src/lib.rs— re-exporttests/nomic_v2_moe.rs— embedding quality testTest results
Closes #227
Test plan
cargo check --features nomic-v2-moe— clean build, zero warningscargo test --features nomic-v2-moe— embedding quality assertions pass