Gemma 4 E2B IT for Apple Core AI (4-bit palettized, text decoder)
This repository holds Gemma 4 E2B IT converted for Apple Core AI (the on-device model runtime of iOS, iPadOS and macOS 27), with 4-bit palettized weights and a 4-bit per-layer-embedding table. It is a text-only, instruction-tuned language model that runs entirely on an iPhone, iPad or Mac, in a download of 2.66 GB.
The model was created by Google DeepMind (Gemma; license: Apache 2.0, see
Google's license page and the original
model card). The converted files here are a derivative work released under the same
license (see LICENSE). Google DeepMind did not make, review or endorse this conversion.
It is used by the ClassScribe app to write lecture notes on the device. It is published so anyone can load the same files, and so the conversion can be reproduced.
Modifications
This is not the original model. Compared with google/gemma-4-E2B-it, these changes were made:
| Change | Detail |
|---|---|
| Format | Converted from PyTorch to a Core AI program (.aimodel) with apple/coreai-models, commit c8e00c01800ba6ad324707007f7af358efc980a4, using models/gemma4/export.py with its iOS recipe. |
| Weight compression | 4-bit palettized (k-means look-up tables), with the recipe's 4bit_palettized preset (models/gemma4/4bit_palettized.yaml). |
| Per-layer embeddings | The per-layer-embedding (PLE) table, which is stored outside the program, is quantized to 4 bits (symmetric, one fp16 scale per 64 values of a row), instead of the recipe's 8-bit table. This halves it (2.35 GB to 1.25 GB). Done with a patch to gemma4_text.py: see recipe/ple4-4bit-table.patch. |
| Scope | Text decoder only. The vision and audio encoders of Gemma 4 are not included. No image or audio input. |
| Context | A context ladder of 1024, 4096 and 8192 tokens (three static programs in one bundle), capped at 8192. The original model supports a much longer context; this bundle does not. |
| Weights not retrained | No fine-tuning, no change to the tokenizer or the chat template (copied from the original). |
Because of the quantization the outputs differ from the original model's. See "Quality" and "Limitations" below.
Files
The layout is exactly what CoreAILanguageModel(resourcesAt:) reads: the repository root is the bundle folder.
metadata.json bundle description (Core AI "llm" bundle, max context 8192)
gemma_4_e2b_it_4bit_palettized_static.aimodel/
main.mlirb the compiled program (1.38 GB, Git LFS)
main.hash, metadata.json
gemma_4_e2b_it_4bit_palettized_static_ple.safetensors the 4-bit per-layer-embedding table (1.25 GB, Git LFS)
tokenizer/ tokenizer.json, tokenizer_config.json, chat_template.jinja (from the original model)
recipe/ the export scripts and the patch (not needed to run the model)
LICENSE Apache License 2.0
Total of the eight model files: 2,659,361,705 bytes. SHA-256 of every file is listed at the end of this card.
Load it
You need Xcode 27 and the CoreAILM package product of apple/coreai-models (the module you import is CoreAILanguageModels). Download the repository (for example with
hf download) to a local folder and point CoreAILanguageModel at it. The first load compiles the program for the device
(about 100 s on an A16 iPad); later loads take about a second, until the OS or the app is updated.
import CoreAILanguageModels
import FoundationModels
let bundle = URL(filePath: "/path/to/gemma-4-e2b-it-coreai") // the folder that holds metadata.json
let model = try await CoreAILanguageModel(resourcesAt: bundle, mode: .eager)
let session = LanguageModelSession(model: model, instructions: "You write clear study notes.")
let options = GenerationOptions(temperature: 0.3, maximumResponseTokens: 2000) // the default stops at 512 tokens
for try await snapshot in session.streamResponse(to: "Summarize: ...", options: options) {
print(snapshot.content)
}
An app that downloads the files itself should fetch them from one pinned commit
(https://huggingface.co/<repo>/resolve/<commit>/<path>) and check each file's size and SHA-256 before loading.
Measured performance
Greedy or low-temperature decoding of lecture-transcript prompts (3,500 tokens in, up to 2,000 out), no draft model.
| Device | Prefill | Decode | Notes |
|---|---|---|---|
| iPad (A16, 6 GB), optimized (Release) build | about 2,600 tokens/s | about 28 tokens/s | One lecture summary (4 sections plus a final pass) in about 2 minutes. A Debug build is about 2.5x slower. |
Mac (M5), llm-benchmark |
about 4,500 tokens/s | about 43 tokens/s | First token after about 0.8 s. One 3,500-in / 400-out section in about 10 s. Peak run memory about 3.1 GB. Cold first load about 40 s. |
The Mac numbers were measured on an earlier export of the same weights with a single 8192 context program; the shipped bundle only adds the 1024 and 4096 programs (the same weights, a smaller cache for short prompts). Numbers vary with the device, the OS build, thermal state and prompt length.
Quality
Compared with the same export with the recipe's 8-bit per-layer table, the 4-bit table gave a teacher-forced top-1 agreement of 97.3% to 98.8% and a perplexity change under 1% on two lecture transcripts. Greedy text diverges early from the 8-bit export but stays coherent. This is a spot check, not a benchmark: the conversion was not evaluated against the original on standard test sets, and the effect of the 4-bit palettization of the main weights, against the original model, was not measured separately.
Limitations
- Not the original model. Quantization changes outputs and can reduce accuracy, especially on arithmetic, code, rare words and non-English text. Check results you rely on.
- Text only. No image, audio or video input.
- Context is capped at 8,192 tokens (input and output together).
- Needs Core AI: iOS, iPadOS or macOS 27 or later. A device with at least 6 GB of memory is recommended (the 6 GB A16 iPad runs it; peak run memory measured on the Mac was about 3.1 GB).
- The first load takes time: Core AI compiles the program for the device on the first load after an install or an OS update.
- Like other language models it can invent facts, repeat itself and follow instructions in the text it is given. Do not use it without review for anything where an error matters. Follow Google's terms of use for Gemma.
- The
recipe/files are provided as they were used. They need the model's original files and a patched checkout of the exporter; they are not a polished tool.
How it was made
- Check out apple/coreai-models at
c8e00c01800ba6ad324707007f7af358efc980a4(unmodified) and set up itsmodels/gemma4environment (uv, Python 3.11, access togoogle/gemma-4-E2B-iton Hugging Face). - Copy the checkout's
python/src/coreai_models/models/ios/gemma4_text.pytogemma4_text_ple4.pyin a folder that also holdsrecipe/run_ple4.pyandrecipe/run_ladder.py, and patch that copy:patch gemma4_text_ple4.py < recipe/ple4-4bit-table.patch. The checkout itself stays unmodified. The patch makes the PLE table a native-quantized 4-bit sidecar and its graph input float16. - From
models/gemma4, runRECIPE_DIR=<that folder> OUT_DIR=<output folder> recipe/export_gemma_ple4_ship.sh 1024,4096,8192 8192 <name>. The script setsPAL_WORKERS=4(a cap on the palettizer's workers, for memory),PLE_BLOCK=64(values per fp16 scale) andLADDER=1024,4096,8192, then runsexport.py --model google/gemma-4-E2B-it --max-context-length 8192throughrecipe/run_ladder.py.run_ple4.pyswaps in the patched module and applies the worker cap;run_ladder.pyreplaces the exporter's default context ladder (1024, 8192, 32768, 131072) by 1024, 4096, 8192 (the larger buckets stay out because of the 8192 cap).export.pyitself is not edited. - The result is the folder in this repository. The Core AI toolchain (
coreai-core1.0.0b3) wrote the.aimodel.
The export used about 10 GB of memory at peak and a few minutes on an Apple-silicon Mac.
Used by ClassScribe
ClassScribe, an iPhone and iPad app that records lectures and writes notes about them on the device, downloads these files when a person chooses on-device notes with Gemma 4. ClassScribe is not affiliated with Google. The app pins this repository to one commit and checks every file against a compiled-in SHA-256 list.
Attribution
Gemma 4 was created by Google DeepMind. Original model: google/gemma-4-E2B-it. License: Apache License 2.0. Technical report: Gemma 4 Technical Report, Gemma Team, Google DeepMind, 2026 (see the original model card for the citation). Conversion tooling: apple/coreai-models.
SHA-256
35c841c2bea93eb548d170dd80cbbf55538c96fdb1c803e09ae5479ee74bef18 gemma_4_e2b_it_4bit_palettized_static.aimodel/main.hash
e4f136996e2e002872e195dee86faa2a8913ca1bf5b19bad6182919173058a4c gemma_4_e2b_it_4bit_palettized_static.aimodel/main.mlirb
6583e6f2d4ad59b89d35d54aaf809d5a61534c41ed8b0a3538a9b2dfbacb739f gemma_4_e2b_it_4bit_palettized_static.aimodel/metadata.json
39cbf9d2a2ed1f651a0dc48f6263da3d0545a4680d0d2002984a24825e194847 gemma_4_e2b_it_4bit_palettized_static_ple.safetensors
f30b36b9520fc4009289067be7c68e30e6bfccac8256428beac374461e1f716f metadata.json
0a2c8073c878ab1da004bee933a998606537bbb62016310352c7285c3f01c5b5 tokenizer/chat_template.jinja
ab26b2add729e6f645bd869f228f14190a06615538f3be6f7786f33d13d78ad2 tokenizer/tokenizer.json
3ab5c7b94dc97d65ca7064496fa69b88ff875378e1cb7ee3e43070c3a8170999 tokenizer/tokenizer_config.json
- Downloads last month
- -