Gemma 4 E4B (instruct) for Apple Core AI
This is an unofficial conversion of Google's Gemma 4 E4B instruction-tuned model. It is packaged as an Apple Core AI language bundle (.aimodel) for macOS 27 and runs with the CoreAILM engines from apple/coreai-models, both the pipelined engine and the sequential engine.
Files
gemma-4-e4b-it-coreai.zip is 5,904,532,479 bytes, sha256 7c947906c2db8860b9f21c76a9763ad7c74f5574f1b0935b37114faaaaad3eaa. It unpacks to a single folder, gemma-4-e4b-it/, containing:
- the
.aimodel; - the tokenizer files and the chat template;
metadata.json, which declares an 8,192-token context;LICENSEandMODEL-ATTRIBUTION.json.
How it was converted
Source checkpoint: google/gemma-4-E4B-it-qat-q4_0-unquantized at revision 476025a0. This is Google's quantization-aware-trained checkpoint.
Precision:
| Part | Precision |
|---|---|
| Attention and LM head | int4, block 32, symmetric |
| MLP | int8, block 32 |
| Per-layer embedding table | int8 per row, stored as 4 column chunks (see below) |
| Token embeddings | fp16 |
| Compute | fp16 |
The per-layer embedding table is split because the Core AI GPU runtime gathers rows incorrectly from a single constant with 2^31 or more elements; see apple/coreai-models#313. Splitting it keeps every chunk below that limit.
KV cache:
- The 4 full-attention producer slots grow with the context.
- The 20 sliding-window slots use a fixed 512-position ring, which keeps decode fast at long context and memory small.
- The KV-shared layers read their producer's slot.
Functions:
mainreturns logits.- A headless
prefillfunction serves recent CoreAILM pipelined engines, which use it for chunked prefill without allocating a full logits buffer.
Requirements
- macOS 27 on Apple silicon.
- apple/coreai-models at commit
3efa838eor later. - For JSON-schema (constrained) generation through the pipelined engine: the one-line fix described in apple/coreai-models#316. This bundle has additional KV states, which the constrained path does not bind without the fix. Plain text generation works without it.
Measurements
Measured on one M5 Mac with 24 GB of RAM, macOS 27.0 beta, temperature 0:
- Faithfulness: the compiled graph matches the quantized PyTorch reference to about 63 dB, with 99.8 % next-token agreement.
- Decode speed: about 25 tokens/s on short prompts, about 24 at 3K tokens of context and about 21 at 12.5K.
- Prefill speed: about 1,200 tokens/s, and about 1,900 tokens/s with the
prefillfunction on a recent engine. - Working memory: about 1.3β2.4 GB, plus the memory-mapped weights.
Known limits
- Tested on a single 24 GB Mac. Macs with 16 GB of RAM have not been tested.
- The first execution of a new prompt shape can resolve near-ties differently from later executions of the same shape. Both are equally accurate against the reference.
- Thinking mode is not tested. The chat template's default is non-thinking.
License
Apache-2.0; see LICENSE. Gemma 4 is a model by Google. This conversion is not affiliated with or endorsed by Google or Apple.
Model tree for iannedev/gemma-4-E4B-it-coreai
Base model
google/gemma-4-E4B