Ben Graville commited on
Commit
60bc67d
Β·
verified Β·
1 Parent(s): 03102f0

docs: descriptive model card

Browse files
Files changed (1) hide show
  1. README.md +244 -53
README.md CHANGED
@@ -1,64 +1,255 @@
1
  ---
 
 
 
2
  library_name: coreai
3
- tags: [core-ai, aimodel, on-device, apple]
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # gemma-4-E2B-CoreAI
7
 
8
- Core AI `.aimodel` bundles converted for [Visible](https://visible.cx) on-device
9
- inference. **Derivative artifacts** β€” converted from the upstream checkpoints listed
10
- below; all original model licences apply and travel with these weights.
 
11
 
12
- | Bundle | Source checkpoint | Context | Functions | Producer | Created |
13
- |---|---|---|---|---|---|
14
- | `gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl` | google/gemma-4-E2B-it-qat-q4_0-unquantized | 4096 | main | coreai-core 1.0.0b2 | 20260817T104931Z |
15
- | `gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64` | google/gemma-4-E2B-it-qat-q4_0-unquantized | 4096 | main+prefill | coreai-core 1.0.0b2 | 20260817T110657Z |
16
 
17
- ## Provenance
18
-
19
- - Converted with the [coreai-model-zoo](https://github.com/john-rocky/coreai-model-zoo)
20
- conversion recipes on the pinned `apple/coreai-models` base
21
- `b1cb71b8522d99408059fa0b98b8742171bcb0b8` + the zoo python overlay.
22
- - Toolchain: `coreai-torch 0.4.1`, `coreai-core 1.0.0b2`, `coreai-opt 0.2.1`, `torch 2.9.0`.
23
- - Every bundle's inner `<name>.aimodel/metadata.json` reports
24
- `producer: "coreai-core 1.0.0b2"`.
25
- - Gemma bundles: `eos_token` is set to `<turn|>` (Gemma 4 ends a *turn* with `<turn|>`;
26
- stopping on the source's `<eos>` overruns the reply).
27
- - Bundles carry `runtime_env COREAI_CHUNK_THRESHOLD=1`.
28
-
29
- Upstream sources: `google/gemma-4-E2B-it-qat-q4_0-unquantized`
30
-
31
-
32
- ## High-context bundles β€” ctx 8192
33
-
34
- Same weights, same graph, same recipe as the 4096 bundles above β€” the exporter's
35
- `--max-ctx` only widens the dynamic sequence bound and the manifest's
36
- `language.max_context_length`. KV cache stays fp16.
37
-
38
- | Bundle | Source checkpoint | Context | Functions | KV dtype | Producer | Created |
39
- |---|---|---|---|---|---|---|
40
- | `ctx8192/gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64` | google/gemma-4-E2B-it-qat-q4_0-unquantized | 8192 | main+prefill | fp16 | coreai-core 1.0.0b2 | 20260817T203916Z |
41
 
 
42
 
43
- ## High-context bundles β€” ctx 16384
44
-
45
- Same weights, same graph, same recipe as the 4096 bundles above β€” the exporter's
46
- `--max-ctx` only widens the dynamic sequence bound and the manifest's
47
- `language.max_context_length`. KV cache stays fp16.
48
-
49
- | Bundle | Source checkpoint | Context | Functions | KV dtype | Producer | Created |
50
- |---|---|---|---|---|---|---|
51
- | `ctx16384/gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64` | google/gemma-4-E2B-it-qat-q4_0-unquantized | 16384 | main+prefill | fp16 | coreai-core 1.0.0b2 | 20260817T204052Z |
52
-
53
-
54
- ## w4a8/ β€” int4 weights + INT8 activations (EXPERIMENTAL)
55
-
56
- > **EXPERIMENTAL β€” not qualified.** These bundles have not passed a Mac-side
57
- > oracle/parity gate or a device benchmark. Do not route production traffic to
58
- > them until they have.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
- Same QAT int4 per-block-32 weights and same graph as gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64; the only difference is an int8 quantize/dequantize pair on the inputs of every F.linear, calibrated on 128 synthetic social-media-style samples (calibration_corpus.jsonl ships in the bundle). Intended as a prefill/TTFT lever. READ THE CAVEAT: coreai-opt documents the runtime fast path as W_INT8-A_INT8, and states that a float weight path executes in floating point regardless of activation quantization. These weights use int4 scale-multiply dequant, not an int8 LUT, so the expected TTFT gain may be zero or negative. This bundle exists to be MEASURED, not because a win is predicted. ctx 16384. Unlike the 4096 folders, this one does include chat_template.jinja.
61
 
62
- | Bundle | Source checkpoint | Context | Functions | Bytes | Producer | Created |
63
- |---|---|---|---|---|---|---|
64
- | `w4a8/gemma4_e2b_qat_decode_int4lin_a8_tbl_pf64` | google/gemma-4-E2B-it-qat-q4_0-unquantized | 16384 | main+prefill | 2,122,679,604 | coreai-core 1.0.0b2 | 20260817T222458Z |
 
1
  ---
2
+ license: gemma
3
+ license_link: https://ai.google.dev/gemma/terms
4
+ base_model: google/gemma-4-E2B-it-qat-q4_0-unquantized
5
  library_name: coreai
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - core-ai
9
+ - aimodel
10
+ - apple-silicon
11
+ - on-device
12
+ - quantized
13
+ - int4
14
+ - qat
15
+ - gemma4
16
  ---
17
 
18
+ # Gemma 4 E2B β€” Core AI (.aimodel)
19
 
20
+ `google/gemma-4-E2B-it-qat-q4_0-unquantized` converted to Core AI `.aimodel` bundles for
21
+ Apple silicon by the [Visible](https://visible.cx) project. **Derivative artifacts**:
22
+ Google's QAT-trained weights rounded onto the int4 grid they were trained for and
23
+ re-expressed as a Core AI graph.
24
 
25
+ Gemma 4 E2B uses **Per-Layer Embeddings**, so these bundles take a large embedding gather
26
+ table as a *static graph input* rather than carrying it in the graph. That table ships here
27
+ in `ios-frontend/` and **the bundles do not load without it** β€” a missing table produces a
28
+ bare input-arity error that says nothing about tables.
29
 
30
+ Of the Gemma 4 bundles in this catalog, this is **the only one worth considering for
31
+ structured-output work**: 10/10 schema-clean at 29 tok/s on a 16 GB Mac. It is still 4Γ— the
32
+ cost per row of the LFM2.5 1.2B at 3Γ— the peak memory, so it earns a slot only where
33
+ Gemma's output specifically is wanted.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ ## Provenance
36
 
37
+ | | |
38
+ |---|---|
39
+ | Base checkpoint | `google/gemma-4-E2B-it-qat-q4_0-unquantized` (ungated) |
40
+ | Recipe (decode) | `export_gemma4_decode_pipelined.py int4lin --tbl` β€” zoo recipe `gemma-4-e2b`, `status = "verified"` |
41
+ | Recipe (pf64) | `export_gemma4_pf_pipelined.py --pf 64` with `--tbl` and `--raw-dir` pointed at the gather table below |
42
+ | Toolchain base | `apple/coreai-models` @ `b1cb71b8522d99408059fa0b98b8742171bcb0b8` + the [coreai-model-zoo](https://github.com/john-rocky/coreai-model-zoo) python overlay |
43
+ | Toolchain | `coreai-torch 0.4.1`, `coreai-core 1.0.0b2`, `coreai-opt 0.2.1`, `torch 2.9.0` |
44
+ | Producer fingerprint | `coreai-core 1.0.0b2` on every inner asset `metadata.json` |
45
+ | Weight format | **int4, per-block-32** (`int4lin`, symmetric-with-clipping) β€” the ggml q4_0 grid the QAT checkpoint was trained on |
46
+ | Vocab | 262,144 |
47
+ | Conversion | 180 s (decode) / 105 s, 26.8 GB peak RSS (pf64); Linux x86_64 |
48
+
49
+ "QAT-unquantized" means QAT-*trained*, stored at full width; the int4 rounding happens at
50
+ export, onto the grid training already targeted.
51
+
52
+ `_tbl` = the PLE gather table is bound as a static graph input. `_pf64` = a second
53
+ entrypoint, `prefill`, with a static query width of 64
54
+ (`function_map: {"main": ["main", "prefill"]}`).
55
+
56
+ ## Contents
57
+
58
+ ### Bundles
59
+
60
+ | Path | Bytes | Context | Functions | Status |
61
+ |---|---:|---|---|---|
62
+ | `gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64` | 2,122,089,973 | 4096 | main + prefill | the working bundle |
63
+ | `ctx8192/gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64` | 2,122,089,964 | 8192 | main + prefill | same weights, wider manifest |
64
+ | `ctx16384/gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64` | 2,122,089,964 | 16384 | main + prefill | same weights, wider manifest |
65
+ | `gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl` | 2,121,479,596 | 4096 | main | superseded β€” no `prefill`, see below |
66
+ | `w4a8/gemma4_e2b_qat_decode_int4lin_a8_tbl_pf64` | 2,122,679,604 | 16384 | main + prefill | **EXPERIMENTAL** |
67
+
68
+ Each bundle folder holds `<name>.aimodel/` (`main.mlirb` β‰ˆ 2.09 GB, `main.hash`, asset
69
+ `metadata.json`), a bundle-level `metadata.json`, and `tokenizer/` (`tokenizer.json`
70
+ 32,169,626 B, `tokenizer_config.json`, `generation_config.json`, `chat_template.jinja`
71
+ 18,569 B). The `w4a8` folder additionally ships its `calibration_corpus.jsonl`
72
+ (35,045 B).
73
+
74
+ **The three `_tbl_pf64` context folders are the same weights.** `--max-ctx` does not change
75
+ the exported graph β€” identical function signatures, identical state descriptors, identical
76
+ export peak RSS at every value. It changes exactly one thing:
77
+ `language.max_context_length` in the bundle manifest. This was proved with a same-config
78
+ control re-export whose `main.mlirb` differed from its twin by *more* bytes (22,053) than a
79
+ 4096β†’8192 pair does (22,344); the context delta is inside the conversion noise floor.
80
+ Corroborated by the upload itself: pushing a "new" ~2 GB ctx8192 bundle into a repo that
81
+ already held the 4096 bundle transferred a few hundred kB of new data. Pick the folder whose
82
+ manifest integer matches the window you intend to run; a context bump is a manifest edit,
83
+ not a conversion.
84
+
85
+ ### The PLE gather-table sidecar β€” required, not optional
86
+
87
+ | Path | Files | Bytes |
88
+ |---|---|---:|
89
+ | `ios-frontend/gemma4_qat_gather_raw/` | 7 | 2,808,612,071 |
90
+
91
+ | File | Bytes |
92
+ |---|---:|
93
+ | `embed_per_layer.i8` | 2,348,810,240 |
94
+ | `embed_tokens.i8` | 402,653,184 |
95
+ | `proj.f32` | 55,050,240 |
96
+ | `embed_per_layer.scale.f32` | 1,048,576 |
97
+ | `embed_tokens.scale.f32` | 1,048,576 |
98
+ | `proj_norm.f32` | 1,024 |
99
+ | `meta.json` | 231 |
100
+
101
+ `meta.json` records the shape and the dequant convention:
102
+ `V 262144, D 1536, PLD 8960, L 35, ld 256, embed_scale_pl 16.0` (= √256, which is what the
103
+ exporter assumes).
104
+
105
+ Every `_tbl` bundle binds `ple_table` (from `embed_per_layer.i8`, 2.35 GB) and `ple_scale`
106
+ (from `embed_per_layer.scale.f32`) as **static** graph inputs. Without them the bundle fails
107
+ to load with a bare arity error naming `ple_table`/`ple_scale` β€” a diagnosis this project
108
+ got wrong once already. The sidecar is published here so the repo is self-contained for
109
+ both loading and a pf64 rebuild.
110
+
111
+ ## Requirements
112
+
113
+ - **Apple silicon Mac**, Core AI runtime.
114
+ - **Engine contract: 4 inputs** β€” `input_ids`, `position_ids`, plus static `ple_table` and
115
+ `ple_scale`. Two engines can take that:
116
+ - **Pipelined engine** β€” binds the statics zero-copy over the caller's buffer, but
117
+ **does not support logits**, so no grammar-constrained decoding.
118
+ - **Sequential engine** β€” the only logits-capable engine, and therefore the only one
119
+ guided decoding can run on. It accepts `>= 2` inputs and binds everything beyond
120
+ `input_ids`/`position_ids` from `EngineOptions.staticInputBuffers`; an extra input with
121
+ no buffer is rejected by name. It pays a **one-time copy of every constant input at
122
+ load β€” 2.19 GB for E2B** β€” because its submission path otherwise materialises a foreign
123
+ buffer-backed view on *every* forward pass. That was measured: binding the table as a
124
+ raw view cost ~0.30 s per pass (3.4 tok/s, 64 s/row); copying once at load took the same
125
+ bundle to 8.6 s/row, a 7.5Γ— improvement.
126
+ - **States:** `keyCache` / `valueCache` `Float16, 15 Γ— 1 Γ— 1 Γ— ? Γ— 512`. Dynamic sequence
127
+ dim β†’ `GrowingKVCache` (initial 256, doubling), not a static allocation at the manifest
128
+ maximum.
129
+ - **KV cost: 30,720 bytes per token** (fp16) β€” 126 MB at 4096, 252 MB at 8192, 503 MB at
130
+ 16384.
131
+ - **Memory envelope, 16 GB Mac** (Metal `recommendedMaxWorkingSetSize` β‰ˆ 10.7 GB):
132
+
133
+ | | |
134
+ |---|---|
135
+ | Weights (`main.mlirb`) | 2.09 GB |
136
+ | PLE table bound as static input | 2.35 GB |
137
+ | Base | **4.44 GB** |
138
+ | Affordable context, fp16 KV | ~204k tokens β†’ **131,072, the model cap, binds first** |
139
+
140
+ KV is not the ceiling at this tier; **the PLE table is**, at 2.35 GB against a 503 MB KV
141
+ cost even at 16384. Measured peak footprint on a guided run: **8.9 GB**.
142
+ - Sliding-window note: E2B interleaves 12 sliding and 3 full attention layers across 35
143
+ layers collapsed to 15 KV slots. The export models the window in the *mask*, not in
144
+ memory β€” sliding layers occupy full-length slots and zero-pad head_dim 256β†’512, so 80% of
145
+ KV bytes sit in windowed slots and 40% is dead padding. A ring-buffered sliding cache
146
+ would be ~5Γ— cheaper per token; that is model authoring, not a flag, and it is not needed
147
+ at this tier.
148
+ - `runtime_env COREAI_CHUNK_THRESHOLD=1` travels with the recipe. (Both engines now read the
149
+ static query width off the graph, so the older host-side rules about warmup query length
150
+ and chunk threshold are retired.)
151
+
152
+ ## Measured performance
153
+
154
+ Measured on a **16 GB M2 Pro Mac (macOS 27 beta)** with the out-of-process `coreai-repro`
155
+ harness: 10 real enrichment rows (5 POST, 5 COMMENT), the app's live `app_litert` JSON
156
+ schema, greedy decoding through `respondJSON(to:schema:)`, `reset()` per row, **sequential
157
+ engine with the PLE tables bound as static inputs**, 128-token cap.
158
+
159
+ | | `_tbl_pf64` | `_tbl` (no `prefill` function) |
160
+ |---|---|---|
161
+ | Load | 14.6 s | 29.0 s |
162
+ | Guided JSON parse | **10/10** | 3/3 |
163
+ | Enum-clean | **10/10** | 3/3 |
164
+ | s/row (POST) | **7.06** | 44.69 |
165
+ | s/row (COMMENT) | **4.27** | β€” |
166
+ | Decode | 21.8–33.5 tok/s, mean **28.6** | 7.7–16.8 tok/s |
167
+ | TTFT | 0.6–4.7 s | 29–37 s |
168
+ | Peak footprint | 8.9 GB | β€” |
169
+ | Outcome | completed all ten rows | **died at row 4** |
170
+
171
+ **`pf64` is worth 7.7Γ— on time-to-first-token.** Head to head on the same 942-token prompt
172
+ and the same weights, differing only in whether the S=64 `prefill` function was exported:
173
+ TTFT 35.74 s β†’ 4.65 s, s/row 45.04 β†’ 8.83. Decode is untouched β€” the prefill function only
174
+ serves full-width chunks. The non-`pf64` bundle is also not durable: its footprint ballooned
175
+ past 37 GB across ~2,800 single-token passes and the campaign died partway through.
176
+
177
+ **Enum conformance is the grammar's doing, and it is decisive.** Unguided, Gemma 4 invents
178
+ an off-schema `motivation` value on essentially every row (`advocacy` for `advocate`,
179
+ `informative` β€” a valid *tone* β€” used as a *motivation*). Guided, all ten are correct, not
180
+ because the model improved but because an off-enum token is unsamplable. Decode throughput
181
+ is essentially unchanged by the constraint; the ~25% extra cost of a guided row is the
182
+ sequential engine's step-synchronous prefill, not the grammar.
183
+
184
+ **Context for the cost.** On the same harness and machine, LFM2.5-1.2B runs 1.77/1.30 s/row
185
+ at 3.06 GB peak, and Gemma 4 E4B runs 21.89/12.36 s/row at 10.7 GB peak. This bundle is
186
+ about **4Γ— the 1.2B's s/row for 3Γ— its peak memory**. For reference, upstream measured E2B
187
+ at 77.0/87.1 tok/s on an M4 Max, and an unguided pipelined run on this 16 GB Mac reached
188
+ 44.3 tok/s β€” the 28.6 tok/s above is the guided, sequential-engine figure.
189
+
190
+ Nothing was measured above 4096 tokens. Quality at depth is a genuine open question: beyond
191
+ ~4k the long-range signal rides on 3 full-attention layers, and widening the manifest does
192
+ not widen the sliding layers' 512-token window.
193
+
194
+ ## Qualification status
195
+
196
+ | Artifact | Status |
197
+ |---|---|
198
+ | `gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64` (ctx 4096) | **QUALIFIED β€” measured.** 10/10 parse, 10/10 enum-clean, 7.06/4.27 s/row, 28.6 tok/s, 8.9 GB peak. The best Gemma in this catalog for structured output, and still not a default over the LFM tier. |
199
+ | `ctx8192/…_tbl_pf64` | **QUALIFIED BY EQUIVALENCE, UNMEASURED AT DEPTH** β€” same weights, same graph, wider manifest integer; no run above 4096 tokens. |
200
+ | `ctx16384/…_tbl_pf64` | **QUALIFIED BY EQUIVALENCE, UNMEASURED AT DEPTH** β€” as above. |
201
+ | `gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl` | **DEPRECATED β€” superseded by its `_pf64` sibling.** Same weights, no `prefill` function: 8Γ— the TTFT and it did not survive a ten-row campaign. Kept published because it is an immutable artifact that earlier revisions pin; there is no reason to ship it. |
202
+ | `w4a8/gemma4_e2b_qat_decode_int4lin_a8_tbl_pf64` | **EXPERIMENTAL β€” built, unmeasured.** Gate: a Mac-side oracle/parity check plus a device benchmark, neither of which has been run. Do not route production traffic to it. |
203
+
204
+ ### About the `w4a8` bundle
205
+
206
+ Same QAT int4 per-block-32 weights and the same graph as
207
+ `gpu-pipelined/gemma4_e2b_qat_decode_int4lin_tbl_pf64`; the difference is an int8
208
+ quantize/dequantize pair on the inputs of every `F.linear`, calibrated on 128 synthetic
209
+ social-media-style samples (the corpus ships in the folder). It was built as a prefill/TTFT
210
+ lever.
211
+
212
+ The caveat is load-bearing and comes from the compression toolchain's own documentation:
213
+ the runtime fast path is `W_INT8 Γ— A_INT8`, and a float weight path executes in floating
214
+ point *regardless* of activation quantization. These weights use int4 scale-multiply
215
+ dequant, not an int8 LUT, so the expected TTFT gain may be **zero or negative**. This bundle
216
+ exists to be measured, not because a win is predicted.
217
+
218
+ ## Verification
219
+
220
+ - **Producer fingerprint:** every inner `<name>.aimodel/metadata.json` reads
221
+ `producer: "coreai-core 1.0.0b2"`. `coreai-torch 0.4.0` / `coreai-core 1.0.0b1` produce
222
+ ODIE-poisoned bundles that abort **in-process** at load, taking the host application down
223
+ uncatchably. The field lives in the **inner asset** metadata; the bundle manifest never
224
+ carries a `producer` field, for good and bad bundles alike, so a check against the
225
+ manifest condemns every good bundle.
226
+ - **Stop token, verified per folder:** every bundle here declares `eos_token = "<turn|>"`.
227
+ Gemma 4 ends a *turn* with `<turn|>` (id 106); the raw upstream `<eos>` ends the whole
228
+ sequence, and a host stopping on it overruns every reply. The exporter copies the upstream
229
+ tokenizer config verbatim and does **not** apply this correction β€” it is a post-export
230
+ patch, and it was checked on these bundles rather than assumed.
231
+ `generation_config.json` independently lists `eos_token_id: [1, 106, 50]`.
232
+ - **Determinism:** `.aimodel` conversion is not byte-reproducible. `main.mlirb` differs by
233
+ ~22 kB between two runs of an identical command on the same box β€” which is why the
234
+ context-folder comparison above needed a same-config control to be meaningful at all.
235
+ Integrity rests on per-file SHA-256 of the exact published artifact, never on rebuilding.
236
+ - **No oracle gate has been run on this model.** The 10/10 results are behavioural (parse
237
+ rate, enum conformance, clean stop) on Visible's own task. A decode oracle against an fp32
238
+ reference β€” the gate that would catch an int4 or kernel-level numerics error β€” has not been
239
+ run on any Gemma 4 bundle in this catalog.
240
+
241
+ ## License
242
+
243
+ The upstream QAT checkpoint carries Apache-2.0 metadata and is ungated, but it is a Gemma
244
+ model and **the Gemma terms apply downstream**, which is why this repo declares
245
+ `license: gemma`. Use is subject to the
246
+ [Gemma Terms of Use](https://ai.google.dev/gemma/terms), the
247
+ [Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy) and the
248
+ [Gemma 4 license](https://ai.google.dev/gemma/docs/gemma_4_license). Those obligations
249
+ travel with any redistribution of these bundles, including the gather-table sidecar, which
250
+ is derived from the same weights. Visible's contribution is the conversion, not the weights.
251
 
252
+ ---
253
 
254
+ *Additional variants may land in this repo after this card was written; the tables above
255
+ describe its contents as listed at the time of writing.*