Skip to content

Add Gemma 3n support (E2B, macOS) - #198

Open
stikves wants to merge 1 commit into
apple:mainfrom
stikves:sukru/gemma3n
Open

Add Gemma 3n support (E2B, macOS)#198
stikves wants to merge 1 commit into
apple:mainfrom
stikves:sukru/gemma3n

Conversation

@stikves

@stikves stikves commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add Google Gemma 3n E2B — a novel on-device architecture with 7 features not found in other supported models
  • macOS only (FP16 / 4-bit quantized), Apache 2.0 license
  • AltUp (4-copy hidden state), LAUREL (low-rank residual), per-layer input embeddings, KV cache sharing (33% savings), Gaussian TopK sparsity (95%), dual RoPE, QKV norms

Evaluation

Compression WikiText PPL tinyMMLU acc
none (float16) 61.53 58.75%
4-bit quantized 72.13 59.27%

High WikiText PPL is expected for instruction-tuned models — tinyMMLU accuracy is the appropriate quality metric.

Test plan

  • 12 unit tests pass (parity, KV sharing, AltUp, sparsity, float16)
  • Export succeeds: uv run coreai.llm.export google/gemma-3n-E2B-it
  • Inference produces coherent text

@stikves
stikves force-pushed the sukru/gemma3n branch 3 times, most recently from c36cf23 to e389279 Compare August 26, 2026 01:54
@stikves stikves self-assigned this Aug 26, 2026
Add Google Gemma 3n E2B — a novel on-device architecture with 7 features
not found in other supported models:

- AltUp: 4-copy hidden state with learned predict/correct routing
- LAUREL: low-rank residual branch (rank 64) per layer
- Per-layer input embeddings with gated injection
- KV cache sharing: last 10/30 layers reuse K/V (33% cache savings)
- Gaussian TopK: 95% activation sparsity in first 10 MLP layers
- Dual RoPE: local (theta=10K, window 512) + global (theta=1M)
- QKV norms: RMSNorm on Q/K (with scale), V (without scale)

Evaluation: WikiText PPL 61.53 (float16), tinyMMLU 58.75%.
High wikitext PPL is expected for instruction-tuned models;
tinyMMLU accuracy is the appropriate quality metric.
Comment thread models/gemma3n/README.md
@@ -0,0 +1,49 @@
# Gemma 3n

Google's Gemma 3n for on-device inference via Core AI. Apache 2.0 license.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to describe license type here (also it's not Apache, but Gemma license)

Comment thread models/gemma3n/README.md
| --------------- | ------------------ | ------- | ----- | --- |
| gemma-3n-E2B-it | ~5B (E2B effective) | 32768 | Yes | No |

- **AltUp**: 4-copy hidden state with learned predict/correct routing per layer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these lines.

Comment thread models/gemma3n/README.md

## Evaluation

Perplexity on WikiText-2 and accuracy on tinyMMLU, computed with the Core AI PyTorch models (4K context).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align with other models on the Evaluation section.

Comment thread models/gemma3n/README.md
- **QKV norms**: RMSNorm on Q, K (with scale) and V (without scale).
- **Logit softcapping**: `tanh(logits/30) * 30`.

## Evaluation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section should go to the bottom

Comment thread models/gemma3n/README.md
uv run coreai.llm.export google/gemma-3n-E2B-it
```

## Run

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align with other LLMs in terms of README structure.

"float16",
131072,
),
ModelPreset(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing metadata?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants