Add Gemma 3N (text-only) model support#493
Merged
HenryNdubuaku merged 23 commits intomainfrom Mar 7, 2026
Merged
Conversation
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds runtime + conversion support for a new gemma3n model type, including Gemma 3N-specific config parsing, weight export patterns, and a new C++ model implementation integrated into the engine/tooling paths.
Changes:
- Add Gemma 3N config extraction + model-type detection in the Python conversion pipeline.
- Export Gemma 3N-specific weights (AltUp/Laurel/PLI and tower-prefixed tensors) during conversion.
- Introduce
GemmaModel3nin the C++ runtime and wireGEMMA3Ninto engine + tool-calling code paths.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| python/src/weight_patterns.py | Adds Gemma 3N global weight mappings and new per-layer patterns. |
| python/src/tensor_io.py | Tweaks precision override rules for embed-related tensors (incl. embed_tokens_per_layer). |
| python/src/converter.py | Adds gemma3n config extraction and Gemma 3N-specific weight export (global + tower prefixes). |
| python/src/config_utils.py | Adds gemma3n detection and Gemma 3N-specific config extraction (AltUp/Laurel/rope/etc.). |
| python/requirements.txt | Adds new Python dependencies (timm, sentencepiece). |
| cactus/models/model_gemma3n.cpp | New Gemma 3N model implementation (AltUp/Laurel/PLI + hybrid attention). |
| cactus/models/model.h | Declares GemmaModel3n and its weight-node layout. |
| cactus/ffi/cactus_complete.cpp | Treats GEMMA3N like GEMMA for tool formatting + stop sequences. |
| cactus/engine/engine_model.cpp | Adds GEMMA3N attention scaling, config parsing fields, logit softcapping, and model factory wiring. |
| cactus/engine/engine_constraints.cpp | Enables Gemma-style tool-call constraints for GEMMA3N. |
| cactus/engine/engine.h | Extends config/model-type enums and adds Gemma 3N config fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
This reverts commit 3416df3. Signed-off-by: Noah Cylich <[email protected]>
This reverts commit 941c2f8. Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
This reverts commit 2edf384. Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Collaborator
|
@ncylich we need to resolve the conflicts, also you need to add gemma 3n to the readme |
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Karen Mosoyan <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: Noah Cylich <[email protected]>
Signed-off-by: HenryNdubuaku <[email protected]>
Signed-off-by: HenryNdubuaku <[email protected]>
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
gemma3nmodel type