Gemma 4 12B: model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: gemma
|
| 3 |
+
base_model: google/gemma-4-12B-it-qat-q4_0-unquantized
|
| 4 |
+
tags:
|
| 5 |
+
- core-ai
|
| 6 |
+
- coreai
|
| 7 |
+
- apple
|
| 8 |
+
- gemma
|
| 9 |
+
- gemma-4
|
| 10 |
+
- on-device
|
| 11 |
+
- metal
|
| 12 |
+
pipeline_tag: text-generation
|
| 13 |
+
library_name: coreai
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Gemma 4 12B (dense) — Core AI
|
| 17 |
+
|
| 18 |
+
Apple **Core AI** (`.aimodel`) conversion of Google's **Gemma 4 12B** dense text decoder,
|
| 19 |
+
ported directly from the QAT release
|
| 20 |
+
[`google/gemma-4-12B-it-qat-q4_0-unquantized`](https://huggingface.co/google/gemma-4-12B-it-qat-q4_0-unquantized).
|
| 21 |
+
Decode-only, runs on the **stock pipelined engine** on Apple Silicon (M-series Macs).
|
| 22 |
+
|
| 23 |
+
> **First Core AI runtime for a ≥16-head × head_dim-512 full-attention model.** Gemma 4 12B's
|
| 24 |
+
> full (global) attention layers have a 16-head × 512 Q tensor (16 KB fp16) that overflows
|
| 25 |
+
> MPSGraph's GPU decode scratch heap — the stock SDPA crashes at the first token
|
| 26 |
+
> ([apple/coreai-models#27](https://github.com/apple/coreai-models/issues/27)). These bundles
|
| 27 |
+
> ship a **custom Metal flash-decode kernel** on the full layers that removes the offending op,
|
| 28 |
+
> so the model runs. (The plain non-kernel bundles still crash — these `_msdpa` bundles are the
|
| 29 |
+
> runnable ones.)
|
| 30 |
+
|
| 31 |
+
## Bundles (`gpu-pipelined/`)
|
| 32 |
+
|
| 33 |
+
| bundle | quant | size | decode (M4 Max) | quality |
|
| 34 |
+
|---|---|---|---|---|
|
| 35 |
+
| `gemma4_12b_qat_decode_int8lin_msdpa` | int8 (per-block-32) | 14 GB | **22.2 tok/s** (prefill 27.5) | verified-clean: engine greedy == fp32 oracle |
|
| 36 |
+
| `gemma4_12b_qat_decode_int4linsym_msdpa` | int4 (q4_0-aligned absmax) | 8.2 GB | **33.0 tok/s** (prefill 43.4) | answers correctly, slightly 4-bit-lossy phrasing |
|
| 37 |
+
|
| 38 |
+
**int8 is the verified-clean default** (its teacher-forced greedy reproduces the fp32 oracle's
|
| 39 |
+
"The capital of France is Paris." exactly). **int4** is the faster / smaller option (16 GB-Mac
|
| 40 |
+
accessible) at a small quality cost — the same precision class as MLX 4-bit, *not* a conversion
|
| 41 |
+
bug (the int8 graph is exact).
|
| 42 |
+
|
| 43 |
+
## Architecture
|
| 44 |
+
|
| 45 |
+
Clean dense `gemma4_unified` text decoder — **no** PLE / AltUp / Laurel / MoE / KV-sharing
|
| 46 |
+
(unlike the on-device E2B/E4B siblings). 48 layers, hidden 3840, 16 heads, vocab 262144, final
|
| 47 |
+
logit softcap 30, tied embeddings. 5:1 sliding:full interleave; dual head_dim (sliding 256 / full
|
| 48 |
+
`global_head_dim` 512); full layers use a single global KV head with `attention_k_eq_v` (value =
|
| 49 |
+
raw k_proj). Both attention shapes ride **one** growing KV pair, so the bundle loads on the stock
|
| 50 |
+
`CoreAIPipelinedEngine` (2 states, no engine patch); the full layers' SDPA runs as a custom Metal
|
| 51 |
+
flash-decode kernel.
|
| 52 |
+
|
| 53 |
+
## Usage
|
| 54 |
+
|
| 55 |
+
Download a bundle and run with Apple's `llm-runner` / `llm-benchmark` (the pipelined engine; set
|
| 56 |
+
`COREAI_CHUNK_THRESHOLD=1`):
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
huggingface-cli download mlboydaisuke/Gemma-4-12B-CoreAI \
|
| 60 |
+
--include "gpu-pipelined/gemma4_12b_qat_decode_int8lin_msdpa/*" \
|
| 61 |
+
--local-dir ./gemma4-12b-coreai
|
| 62 |
+
|
| 63 |
+
COREAI_CHUNK_THRESHOLD=1 llm-runner \
|
| 64 |
+
--model ./gemma4-12b-coreai/gpu-pipelined/gemma4_12b_qat_decode_int8lin_msdpa \
|
| 65 |
+
--prompt "What is the capital of France?" --max-tokens 64 --chunk-size 1
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
Each bundle is self-contained: the `.aimodel`, `metadata.json`, and the Gemma tokenizer.
|
| 69 |
+
|
| 70 |
+
## Conversion
|
| 71 |
+
|
| 72 |
+
Community zoo (recipe, overlays, model card):
|
| 73 |
+
[github.com/john-rocky/coreai-model-zoo → `zoo/gemma4-12b.md`](https://github.com/john-rocky/coreai-model-zoo/blob/main/zoo/gemma4-12b.md).
|
| 74 |
+
|
| 75 |
+
## License
|
| 76 |
+
|
| 77 |
+
Gemma — governed by the [Gemma Terms of Use](https://ai.google.dev/gemma/terms). By using these
|
| 78 |
+
weights you agree to those terms. The conversion (Core AI bundles, custom Metal kernel) adds no
|
| 79 |
+
additional restrictions.
|