Sundaydream commited on
Commit
4a99ef1
·
verified ·
1 Parent(s): ff65faf

EmbeddingGemma 2 Core ML int8 (text + image), compiled

Browse files
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ text/embeddings.int8 filter=lfs diff=lfs merge=lfs -text
37
+ text/embeddings.int8.scale.f16 filter=lfs diff=lfs merge=lfs -text
38
+ text/tokenizer.json filter=lfs diff=lfs merge=lfs -text
39
+ vision/position_embeddings.f16 filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,426 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: google/embeddinggemma-2
4
+ base_model_relation: quantized
5
+ library_name: coreml
6
+ pipeline_tag: feature-extraction
7
+ language:
8
+ - multilingual
9
+ - en
10
+ - zh
11
+ tags:
12
+ - coreml
13
+ - apple-neural-engine
14
+ - ane
15
+ - int8
16
+ - on-device
17
+ - embeddings
18
+ - sentence-similarity
19
+ - image-text-retrieval
20
+ - gemma
21
+ ---
22
+
23
+ # EmbeddingGemma 2 — Core ML int8 (text + image, compiled)
24
+
25
+ [English](#english) · [中文](#中文)
26
+
27
+ <a id="english"></a>
28
+
29
+ ## English
30
+
31
+ The text and image encoders of [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2), based on
32
+ [FluidInference/embeddinggemma-2-coreml](https://huggingface.co/FluidInference/embeddinggemma-2-coreml). We changed
33
+ three things:
34
+
35
+ - **int8 weights.** Both models have int8 weights, which halves their size. Activations stay fp16.
36
+ - **int8 token table.** The token embedding table is int8 with one fp16 scale per row, which also halves it.
37
+ - **Precompiled.** Both models are compiled to `.mlmodelc`, so an app can load them without calling `MLModel.compileModel`.
38
+
39
+ On our tests the retrieval quality is the same as the fp32 reference (see Validation). The text model runs entirely
40
+ on the Apple Neural Engine. The audio encoder is not included.
41
+
42
+ The output is the same 768-d, L2-normalized embedding as `SentenceTransformer("google/embeddinggemma-2").encode(...)`.
43
+ Matryoshka truncation to 512, 256 or 128 dimensions works as in the original: keep the first N values and
44
+ re-normalize.
45
+
46
+ ### Files
47
+
48
+ | File | What | Size |
49
+ |---|---|---|
50
+ | `text/EmbeddingGemma2Text.mlmodelc` | Text model, int8 weights. 7 functions share one set of weights. | 147 MB |
51
+ | `text/embeddings.int8` | Token table, 262,144 × 512 int8, raw, row-major | 134 MB |
52
+ | `text/embeddings.int8.scale.f16` | One fp16 scale per table row (262,144 values) | 0.5 MB |
53
+ | `text/tokenizer.json` | The original Gemma tokenizer, unchanged | 32 MB |
54
+ | `vision/EmbeddingGemma2Vision.mlmodelc` | Image encoder, int8 weights. Functions: `vision_70`, `vision_140`, `vision_280`. | 155 MB |
55
+ | `vision/position_embeddings.f16` | The patch embedder's x and y position tables, fp16 | 3 MB |
56
+ | `config.json` | Shapes, functions, token ids, task prefixes, image patch layout | |
57
+ | `SHA256SUMS` | Checksums of every file | |
58
+
59
+ Text-only use needs `config.json` and `text/` (about 313 MB). Image search also needs `vision/` (about 158 MB).
60
+ Sizes on this page are in MB = 10⁶ bytes (FluidInference's README uses MiB).
61
+
62
+ ### What changed compared to FluidInference's package
63
+
64
+ | | FluidInference | This repo |
65
+ |---|---|---|
66
+ | Model weights | fp16 | **int8**: linear symmetric, per output channel, for every weight with more than 2048 elements |
67
+ | Token table | `embeddings.bf16`, 268 MB | **`embeddings.int8` + per-row fp16 scale**, 134 MB: `scale = max(abs(row)) / 127` |
68
+ | Format | `.mlpackage` | **`.mlmodelc`**, compiled with coremltools 9 |
69
+ | Text / image size | 284 / 306 MB | **147 / 155 MB** |
70
+ | Audio encoder | yes, on the GPU, fp16 | not included |
71
+
72
+ Functions, inputs and outputs are unchanged, so FluidInference's README and its Swift code
73
+ ([FluidUse](https://github.com/FluidInference/FluidUse), `EmbeddingGemma2Manager`) describe how to call these
74
+ models. The only difference in calling them is the table lookup (step 3 below). The file layout, `config.json` and the
75
+ table format do differ, so FluidUse cannot load this repo without changes.
76
+
77
+ **How the int8 models were made.** The coremltools int8 API (`linear_quantize_weights`) rejects multifunction
78
+ packages, so we:
79
+
80
+ 1. split each package into one single-function model per function (via the MIL program);
81
+ 2. quantized each model to int8;
82
+ 3. merged them back with `ct.utils.save_multifunction`, which stores identical weights only once;
83
+ 4. compiled the result with `ct.utils.compile_model`.
84
+
85
+ The compiled models give the same output as the `.mlpackage` they came from: cosine 1.000000, max difference 0.
86
+
87
+ ### Use (text)
88
+
89
+ 1. **Prefix.** Add the task prefix, e.g. `title: none | text: ` for documents and `task: search result | query: `
90
+ for queries. All prefixes are in `config.json`.
91
+ 2. **Tokenize.** Use `text/tokenizer.json`. The sequence must start with `<bos>` (2) and end with `<eos>` (1); the
92
+ tokenizer adds both. If it is longer than 512 tokens, keep the first 511 and end with `<eos>`.
93
+ 3. **Look up rows.** For each token id, read its row from `embeddings.int8` and multiply by `scale[id] × √512`
94
+ (√512 ≈ 22.627417). Pass the result as fp16.
95
+ 4. **Run.** Call the smallest `embed_S` that fits, S ∈ {32, 48, 64, 128, 256, 512}. Inputs: `inputs_embeds`
96
+ [1, S, 512] and `attention_mask` [1, S], 1 for tokens, right padding. Output: `embedding` [1, 768].
97
+ To embed up to eight short texts in one call, use `pack_256`; see FluidInference's README.
98
+
99
+ ```swift
100
+ import CoreML
101
+
102
+ // Load one function of the compiled model (macOS 15 / iOS 18 or later).
103
+ let config = MLModelConfiguration()
104
+ config.computeUnits = .cpuAndNeuralEngine
105
+ config.functionName = "embed_128"
106
+ let model = try MLModel(contentsOf: textURL, configuration: config) // text/EmbeddingGemma2Text.mlmodelc
107
+
108
+ // Row lookup for one token: int8 row × per-row scale × √512.
109
+ func row(_ id: Int, table: UnsafePointer<Int8>, scales: UnsafePointer<Float16>, into out: UnsafeMutablePointer<Float16>) {
110
+ let s = Float(scales[id]) * 22.627417
111
+ for j in 0..<512 { out[j] = Float16(Float(table[id * 512 + j]) * s) }
112
+ }
113
+ ```
114
+
115
+ ```python
116
+ import numpy as np, coremltools as ct
117
+ from tokenizers import Tokenizer
118
+
119
+ tok = Tokenizer.from_file("text/tokenizer.json")
120
+ table = np.memmap("text/embeddings.int8", dtype=np.int8, mode="r").reshape(262144, 512)
121
+ scale = np.fromfile("text/embeddings.int8.scale.f16", dtype=np.float16).astype(np.float32)
122
+
123
+ ids = tok.encode("task: search result | query: 周末去哪里爬山").ids # the tokenizer adds <bos> (2) and <eos> (1)
124
+ x = np.zeros((1, 64, 512), np.float16); m = np.zeros((1, 64), np.float16)
125
+ x[0, :len(ids)] = table[ids] * scale[ids, None] * 22.627417; m[0, :len(ids)] = 1
126
+ model = ct.models.CompiledMLModel("text/EmbeddingGemma2Text.mlmodelc",
127
+ compute_units=ct.ComputeUnit.CPU_AND_NE, function_name="embed_64")
128
+ v = model.predict({"inputs_embeds": x, "attention_mask": m})["embedding"][0]
129
+ v /= np.linalg.norm(v)
130
+ ```
131
+
132
+ ### Use (images)
133
+
134
+ The steps are the same as in FluidInference's README:
135
+
136
+ 1. Resize the image, keeping its aspect ratio.
137
+ 2. Cut it into 16 px patches.
138
+ 3. Run `vision_70`, `vision_140` or `vision_280`.
139
+ 4. Put the resulting tokens into `<bos> <|image> … <image|> <eos>` and embed that sequence with the text model.
140
+
141
+ The table rows for the special tokens come from `embeddings.int8`, as in step 3 above.
142
+
143
+ ### Validation
144
+
145
+ Tests ran on one MacBook Pro (M3 Max, macOS 26.7). Quality was measured with the Neural Engine (`cpuAndNeuralEngine`)
146
+ for both text and images. "int8" means int8 models and the int8 token table, which is what this repo ships.
147
+
148
+ **Similarity to the fp32 reference** (sentence-transformers, PyTorch fp32):
149
+
150
+ | | Cosine, min / mean |
151
+ |---|---|
152
+ | 64 texts from the simulated knowledge base (48 chunks, 16 queries) | 0.9995 / 0.9998 |
153
+ | 100 screenshots, 140 image tokens | 0.998 / 0.9994 |
154
+
155
+ **Retrieval quality:**
156
+
157
+ | Test set | fp32 reference | FluidInference fp16 | **This repo (int8)** |
158
+ |---|---|---|---|
159
+ | Simulated personal knowledge base, nDCG@10 | 93.5 | 93.2 | **93.2** |
160
+ | MLQA, Chinese question → English passage, nDCG@10 | 67.8 | 68.2 | **67.8** |
161
+ | Screenshots, image embedding only, MRR@10 | 92.9 | 92.9 | **92.9** |
162
+ | Screenshots, image + OCR-text score fusion, MRR@10 | 96.7 | 96.7 | **96.8** |
163
+
164
+ About the test sets:
165
+
166
+ - **Simulated personal knowledge base.** 2,829 chunks of notes, Wikipedia pages, open-source documentation and code,
167
+ mixed Chinese and English, with 113 queries written by an LLM.
168
+ - **MLQA.** 200 questions.
169
+ - **Screenshots.** 100 screenshots: 60 synthetic app screens and 40 Wikipedia pages, half Chinese and half English,
170
+ with 100 queries. OCR is Apple Vision.
171
+ - **Score fusion.** `z(image score) + 0.5 · z(OCR-text score)`, where z standardizes scores per query.
172
+
173
+ **Speed** (M3 Max, one call, warm):
174
+
175
+ | | Neural Engine | GPU |
176
+ |---|---|---|
177
+ | `embed_32` / `48` / `64` / `128` / `256` / `512` | 3.0 / 3.5 / 3.9 / 6.3 / 13.3 / 32.0 ms | not measured |
178
+ | `vision_70` / `vision_140` / `vision_280`, one image | 43 ms / 123 ms / not tried | 35 / 70 / 154 ms |
179
+ | 2,740 knowledge-base chunks (82 tokens on average), one per call / with `pack_256` | 165 / 189 texts/s | not measured |
180
+
181
+ An image needs one `embed_S` call after the image model. The GPU times are short runs at full GPU clock; under
182
+ sustained load the GPU slowed down (see Energy).
183
+
184
+ **Neural Engine placement** (`MLComputePlan`): every op runs on the Neural Engine in all seven text functions (3,862
185
+ ops each, 3,863 in `pack_256`) and in `vision_70` and `vision_140` (2,389 ops each). We did not check `vision_280` on
186
+ the Neural Engine.
187
+
188
+ int8 has about the same speed as fp16. The gain is size: text model and table 552 → 281 MB, image model 306 → 155 MB.
189
+
190
+ **Energy.** Same machine, on AC power in High Power mode. The 100 screenshots ran in a loop for 30 s, each setup
191
+ twice, and idle power was subtracted. The text model ran on the Neural Engine in every case.
192
+
193
+ | | Image model on the Neural Engine | Image model on the GPU |
194
+ |---|---|---|
195
+ | Time per screenshot (image model + text model) | 136 ms in both runs | 84 ms, then 92 ms |
196
+ | Power above idle | 4.1 W | 46 W, then 37 W |
197
+ | **Energy per screenshot** | **0.55 J** | **3.4–3.9 J** |
198
+ | Image model alone: first run → second run | 123 ms → 123 ms; 0.50 → 0.51 J | 70 ms → 146 ms; 3.9 → 1.8 J |
199
+
200
+ - **The Neural Engine uses about 7× less energy per screenshot.** Indexing 10,000 screenshots costs about 1.5 Wh on
201
+ the Neural Engine and about 10 Wh on the GPU; the battery of this 16-inch MacBook Pro holds 100 Wh.
202
+ - **The GPU is faster only in short runs.** It drew about 54 W at first. After about 1.5 minutes of GPU load, the
203
+ system lowered the GPU clock from about 1.3 GHz to 0.6–0.8 GHz. The image model then took 146 ms per screenshot,
204
+ slower than the Neural Engine, which stayed at 123 ms.
205
+ - **Recommendation:** run `vision_70` and `vision_140` on the Neural Engine (`cpuAndNeuralEngine`), especially for
206
+ background indexing. Use the GPU for `vision_280`, which we did not try on the Neural Engine. On the GPU the int8
207
+ image tokens match FluidInference's fp16 package (cosine ≥ 0.999 for every image function on test inputs).
208
+
209
+ ### Limitations
210
+
211
+ - **Tested on one machine only:** M3 Max with macOS 26.7. The models need macOS 15 / iOS 18 or later, because they are
212
+ multifunction models.
213
+ - **First load is slow.** The first load on a device compiles each function for the Neural Engine. FluidInference reports
214
+ several minutes for the seven text functions. Core ML caches the result. Apps should warm the functions up in the background,
215
+ because a `.mlmodelc` cannot be compiled for the Neural Engine ahead of time.
216
+ - **Fixed shapes.** Inputs longer than 512 tokens must be truncated.
217
+ - **`vision_280` was not tried on the Neural Engine.** Run it on the GPU.
218
+ - **Small test sets.** The test sets are small (100–200 queries each) and some queries are LLM-written. Treat the
219
+ numbers as a check that int8 loses nothing, not as a benchmark.
220
+ - **No audio.** Audio is not included. In our tests EmbeddingGemma 2's audio embeddings were weak for Chinese speech and
221
+ for cross-language search, and speech-to-text followed by text embedding worked better. If you need the audio
222
+ encoder, use FluidInference's fp16 package.
223
+
224
+ ### License and attribution
225
+
226
+ - **License.** Apache 2.0, the same as the source models.
227
+ - **Google.** [EmbeddingGemma 2](https://huggingface.co/google/embeddinggemma-2) is by Google DeepMind. Deployments
228
+ must follow the [Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy).
229
+ - **FluidInference.** The Core ML conversion (fp16-safe RMSNorm, functions, packing, image pipeline) is
230
+ [FluidInference's](https://huggingface.co/FluidInference/embeddinggemma-2-coreml).
231
+ - **This repo.** We added the int8 models, the int8 token table, the compilation and the tests.
232
+ - **No affiliation.** This repo is not affiliated with Google or FluidInference.
233
+
234
+ ---
235
+
236
+ <a id="中文"></a>
237
+
238
+ ## 中文
239
+
240
+ 本仓库提供 [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2) 的文本编码器和图像编码器,
241
+ 基于 [FluidInference/embeddinggemma-2-coreml](https://huggingface.co/FluidInference/embeddinggemma-2-coreml) 的 Core ML 版本。
242
+ 我们做了三处改动:
243
+
244
+ - **模型权重 int8**:两个模型的权重都压成了 int8,体积减半;计算仍用 fp16。
245
+ - **词表 int8**:词表也压成了 int8,每行配一个 fp16 缩放系数,体积同样减半。
246
+ - **预先编译**:两个模型都编译成了 `.mlmodelc`,App 可以直接加载,不用再调用 `MLModel.compileModel`。
247
+
248
+ 在我们的测试中,检索效果和 fp32 原版一样(见下文“验证”)。文本模型完全在 Apple 神经网络引擎(ANE)上运行。
249
+ 本仓库不含音频编码器。
250
+
251
+ 输出和 `SentenceTransformer("google/embeddinggemma-2").encode(...)` 相同:768 维、已归一化的向量。
252
+ 如果想用 512、256 或 128 维,和原版一样取前 N 维,再重新归一化即可。
253
+
254
+ ### 文件
255
+
256
+ | 文件 | 内容 | 大小 |
257
+ |---|---|---|
258
+ | `text/EmbeddingGemma2Text.mlmodelc` | 文本模型,int8 权重;7 个函数共用一份权重 | 147 MB |
259
+ | `text/embeddings.int8` | 词表,262,144 × 512 的 int8 原始数据,按行存放 | 134 MB |
260
+ | `text/embeddings.int8.scale.f16` | 词表每行一个 fp16 缩放系数(共 262,144 个) | 0.5 MB |
261
+ | `text/tokenizer.json` | Gemma 原版分词器,未改动 | 32 MB |
262
+ | `vision/EmbeddingGemma2Vision.mlmodelc` | 图像编码器,int8 权重;函数 `vision_70`、`vision_140`、`vision_280` | 155 MB |
263
+ | `vision/position_embeddings.f16` | 图块的 x、y 位置表,fp16 | 3 MB |
264
+ | `config.json` | 形状、函数列表、特殊 token、任务前缀、图块排列方式 | |
265
+ | `SHA256SUMS` | 所有文件的校验和 | |
266
+
267
+ 只用文本:需要 `config.json` 和 `text/`,约 313 MB。还要搜图片:再加 `vision/`,约 158 MB。
268
+ 本页的 MB 指 10⁶ 字节(FluidInference 的 README 用的是 MiB)。
269
+
270
+ ### 和 FluidInference 原版的区别
271
+
272
+ | | FluidInference | 本仓库 |
273
+ |---|---|---|
274
+ | 模型权重 | fp16 | **int8**:线性对称,按输出通道量化;只压缩元素数超过 2048 的权重 |
275
+ | 词表 | `embeddings.bf16`,268 MB | **`embeddings.int8` + 每行一个 fp16 缩放系数**,134 MB;`scale = 该行绝对值的最大值 / 127` |
276
+ | 格式 | `.mlpackage` | **`.mlmodelc`**,用 coremltools 9 编译 |
277
+ | 文本 / 图像模型体积 | 284 / 306 MB | **147 / 155 MB** |
278
+ | 音频编码器 | 有,在 GPU 上跑,fp16 | 不含 |
279
+
280
+ 函数名、输入和输出都没变,调用方法可以直接参考 FluidInference 的 README 和它的 Swift 代码
281
+ ([FluidUse](https://github.com/FluidInference/FluidUse) 里的 `EmbeddingGemma2Manager`)。调用上唯一的区别是查词表(见下面第 3 步)。但文件布局、`config.json` 和词表格式都不同,FluidUse 不改代码无法直接加载本仓库。
282
+
283
+ **int8 模型是怎么做的**:coremltools 的 int8 压缩接口(`linear_quantize_weights`)不支持多函数模型,所以我们分四步:
284
+
285
+ 1. 通过 MIL 程序把每个函数拆成单独的模型;
286
+ 2. 逐个压成 int8;
287
+ 3. 用 `ct.utils.save_multifunction` 合并回去,相同的权重只存一份;
288
+ 4. 用 `ct.utils.compile_model` 编译。
289
+
290
+ 编译后的模型和编译前的 `.mlpackage` 输出完全一致:余弦相似度 1.000000,最大差值 0。
291
+
292
+ ### 用法(文本)
293
+
294
+ 1. **加前缀**:加上任务前缀,例如文档用 `title: none | text: `,查询用 `task: search result | query: `。所有前缀都在 `config.json` 里。
295
+ 2. **分词**:用 `text/tokenizer.json` 分词。序列必须以 `<bos>`(2)开头、以 `<eos>`(1)结尾,分词器会自动加上这两个。
296
+ 超过 512 个 token 时,保留前 511 个,最后接 `<eos>`。
297
+ 3. **查词表**:对每个 token id,从 `embeddings.int8` 取出对应的行,乘以 `scale[id] × √512`(√512 ≈ 22.627417),转成 fp16。
298
+ 4. **运行**:调用能放下这段文本的最小 `embed_S`,S ∈ {32, 48, 64, 128, 256, 512}。
299
+ - 输入是 `inputs_embeds` [1, S, 512] 和 `attention_mask` [1, S](有 token 的位置为 1,补齐放在右侧);
300
+ - 输出是 `embedding` [1, 768];
301
+ - 想一次算最多 8 段短文本,用 `pack_256`,见 FluidInference 的 README。
302
+
303
+ ```swift
304
+ import CoreML
305
+
306
+ // 加载编译好的模型中的一个函数(需要 macOS 15 / iOS 18 或更高版本)
307
+ let config = MLModelConfiguration()
308
+ config.computeUnits = .cpuAndNeuralEngine
309
+ config.functionName = "embed_128"
310
+ let model = try MLModel(contentsOf: textURL, configuration: config) // text/EmbeddingGemma2Text.mlmodelc
311
+
312
+ // 查一个 token 的行:int8 行 × 该行的缩放系数 × √512
313
+ func row(_ id: Int, table: UnsafePointer<Int8>, scales: UnsafePointer<Float16>, into out: UnsafeMutablePointer<Float16>) {
314
+ let s = Float(scales[id]) * 22.627417
315
+ for j in 0..<512 { out[j] = Float16(Float(table[id * 512 + j]) * s) }
316
+ }
317
+ ```
318
+
319
+ ```python
320
+ import numpy as np, coremltools as ct
321
+ from tokenizers import Tokenizer
322
+
323
+ tok = Tokenizer.from_file("text/tokenizer.json")
324
+ table = np.memmap("text/embeddings.int8", dtype=np.int8, mode="r").reshape(262144, 512)
325
+ scale = np.fromfile("text/embeddings.int8.scale.f16", dtype=np.float16).astype(np.float32)
326
+
327
+ ids = tok.encode("task: search result | query: 周末去哪里爬山").ids # 分词器会自动加上 <bos>(2)和 <eos>(1)
328
+ x = np.zeros((1, 64, 512), np.float16); m = np.zeros((1, 64), np.float16)
329
+ x[0, :len(ids)] = table[ids] * scale[ids, None] * 22.627417; m[0, :len(ids)] = 1
330
+ model = ct.models.CompiledMLModel("text/EmbeddingGemma2Text.mlmodelc",
331
+ compute_units=ct.ComputeUnit.CPU_AND_NE, function_name="embed_64")
332
+ v = model.predict({"inputs_embeds": x, "attention_mask": m})["embedding"][0]
333
+ v /= np.linalg.norm(v)
334
+ ```
335
+
336
+ ### 用法(图片)
337
+
338
+ 和 FluidInference 的 README 相同:
339
+
340
+ 1. 按原比例缩放图片;
341
+ 2. 切成 16 px 的图块;
342
+ 3. 运行 `vision_70`、`vision_140` 或 `vision_280`;
343
+ 4. 把得到的 token 放进 `<bos> <|image> … <image|> <eos>`,再用文本模型算出向量。
344
+
345
+ 特殊 token 的行同样从 `embeddings.int8` 里查,方法同上面第 3 步。
346
+
347
+ ### 验证
348
+
349
+ 在一台 MacBook Pro(M3 Max,macOS 26.7)上测试。效果测试时,文本和图像都跑在神经网络引擎上(`cpuAndNeuralEngine`)。
350
+ 下面的“int8”指 int8 模型加 int8 词表,也就是本仓库发布的版本。
351
+
352
+ **和 fp32 原版的相似度**(参照:sentence-transformers,PyTorch fp32):
353
+
354
+ | | 余弦相似度,最低 / 平均 |
355
+ |---|---|
356
+ | 模拟个人知识库中的 64 段文本(48 个文本块、16 条查询) | 0.9995 / 0.9998 |
357
+ | 100 张截图,140 个图像 token | 0.998 / 0.9994 |
358
+
359
+ **检索效果:**
360
+
361
+ | 测试集 | fp32 原版 | FluidInference fp16 | **本仓库(int8)** |
362
+ |---|---|---|---|
363
+ | 模拟个人知识库,nDCG@10 | 93.5 | 93.2 | **93.2** |
364
+ | MLQA,中文问题找英文段落,nDCG@10 | 67.8 | 68.2 | **67.8** |
365
+ | 截图,只用图像向量,MRR@10 | 92.9 | 92.9 | **92.9** |
366
+ | 截图,图像和 OCR 文字按分数融合,MRR@10 | 96.7 | 96.7 | **96.8** |
367
+
368
+ 测试集说明:
369
+
370
+ - **模拟个人知识库**:2,829 个文本块,内容包括笔记、维基百科页面、开源文档和代码,中英混合;113 条查询由大模型编写。
371
+ - **MLQA**:200 个问题。
372
+ - **截图**:100 张,其中 60 张合成的软件界面、40 张维基百科页面,中英各半;查询 100 条;文字识别用 Apple Vision。
373
+ - **分数融合**:`z(图像分数) + 0.5 · z(OCR 文字分数)`,z 表示在每条查询内把分数标准化。
374
+
375
+ **速度**(M3 Max,单次调用,已预热):
376
+
377
+ | | 神经网络引擎 | GPU |
378
+ |---|---|---|
379
+ | `embed_32` / `48` / `64` / `128` / `256` / `512` | 3.0 / 3.5 / 3.9 / 6.3 / 13.3 / 32.0 ms | 未测 |
380
+ | `vision_70` / `vision_140` / `vision_280`,每张图 | 43 ms / 123 ms / 未试 | 35 / 70 / 154 ms |
381
+ | 2,740 个知识库文本块(平均 82 个 token):逐段 / 用 `pack_256` 拼接 | 每秒 165 / 189 段 | 未测 |
382
+
383
+ 每张图在图像模型之后,还要调用一次 `embed_S`。GPU 的耗时是 GPU 满频时短时间跑出来的;持续运行时 GPU 会变慢(见下面的“能耗”)。
384
+
385
+ **算子分配**(`MLComputePlan`):7 个文本函数(每个 3,862 个算子,`pack_256` 是 3,863 个)以及 `vision_70`、`vision_140`
386
+ (每个 2,389 个算子)的所有算子都在神经网络引擎上。`vision_280` 没有在神经网络引擎上检查。
387
+
388
+ int8 的速度和 fp16 基本一样,好处在体积:文本模型加词表从 552 MB 降到 281 MB,图像模型从 306 MB 降到 155 MB。
389
+
390
+ **能耗**:同一台机器,接电源,高性能模式。100 张截图循环跑 30 秒,每种配置跑两轮,扣除空闲功耗。文本模型都在神经网络引擎上。
391
+
392
+ | | 图像模型在神经网络引擎上 | 图像模型在 GPU 上 |
393
+ |---|---|---|
394
+ | 每张截图耗时(图像模型 + 文本模型) | 两轮都是 136 ms | 84 ms,第二轮 92 ms |
395
+ | 比空闲多出的功率 | 4.1 W | 46 W,第二轮 37 W |
396
+ | **每张截图的能耗** | **0.55 J** | **3.4–3.9 J** |
397
+ | 只跑图像模型:第一轮 → 第二轮 | 123 ms → 123 ms;0.50 → 0.51 J | 70 ms → 146 ms;3.9 → 1.8 J |
398
+
399
+ - **神经网络引擎每张截图的能耗约为 GPU 的 1/7**:给 1 万张截图建索引,在神经网络引擎上约耗 1.5 Wh,在 GPU 上约 10 Wh;
400
+ 这台 16 英寸 MacBook Pro 的电池是 100 Wh。
401
+ - **GPU 只在短时间内更快**:一开始 GPU 功率约 54 W。GPU 持续工作约 1.5 分钟后,系统把 GPU 频率从约 1.3 GHz 降到 0.6–0.8 GHz,
402
+ 图像模型每张要 146 ms,比神经网络引擎还慢;神经网络引擎一直稳定在 123 ms。
403
+ - **建议**:`vision_70` 和 `vision_140` 在神经网络引擎上运行(`cpuAndNeuralEngine`),后台批量建索引时尤其如此。
404
+ `vision_280` 没有在神经网络引擎上试过,请用 GPU。在 GPU 上,int8 图像模型输出的 token 和 FluidInference 的 fp16 版本一致
405
+ (用测试输入检查,每个图像函数的余弦相似度都 ≥ 0.999)。
406
+
407
+ ### 局限
408
+
409
+ - **只在一台机器上测过**:M3 Max,macOS 26.7。模型是多函数模型,需要 macOS 15 / iOS 18 或更高版本。
410
+ - **第一次加载很慢**:在每台设备上第一次加载时,系统要把每个函数编译给神经网络引擎;FluidInference 报告 7 个文本函数共需几分钟。
411
+ Core ML 会缓存编译结果。`.mlmodelc` 没法提前编译到神经网络引擎这一步,所以建议 App 在后台预热各个函数。
412
+ - **形状固定**:超过 512 个 token 的输入必须截断。
413
+ - **`vision_280` 没有在神经网络引擎上试过**:请在 GPU 上运行。
414
+ - **测试集很小**:每组 100–200 条查询,部分查询由大模型编写。这些数字只用来确认 int8 没有损失效果,不能当作基准成绩。
415
+ - **不含音频**:在我们的测试中,EmbeddingGemma 2 的音频向量对中文语音和跨语言搜索效果较弱,先转文字再算文本向量效果更好。
416
+ 如果需要音频编码器,请使用 FluidInference 的 fp16 版本。
417
+
418
+ ### 许可证和来源
419
+
420
+ - **许可证**:Apache 2.0,和原模型相同。
421
+ - **Google**:[EmbeddingGemma 2](https://huggingface.co/google/embeddinggemma-2) 由 Google DeepMind 发布。使用时须遵守
422
+ [Gemma 禁止用途政策](https://ai.google.dev/gemma/prohibited_use_policy)。
423
+ - **FluidInference**:Core ML 转换由 [FluidInference](https://huggingface.co/FluidInference/embeddinggemma-2-coreml) 完成,
424
+ 包括防 fp16 溢出的 RMSNorm、各个函数、拼接功能和图像流程。
425
+ - **本仓库**:我们做了 int8 模型、int8 词表、编译和测试。
426
+ - **无关联声明**:本仓库与 Google、FluidInference 没有关联。
SHA256SUMS ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 LICENSE
2
+ ff37d6627c6823228eddaa4b45edf7daf694b2b9d6b45d6f0147a68c5cf2ab55 config.json
3
+ cbca8ceddbfe6edab5888ec5341b48fb9ad3d08117f84c36fd81837fd8c8a9bd text/EmbeddingGemma2Text.mlmodelc/analytics/coremldata.bin
4
+ b494840b269a9cb533d7249f6fb54194e9cdd3bd318be464f01ebda87ab72d16 text/EmbeddingGemma2Text.mlmodelc/coremldata.bin
5
+ 437fb306eb2bd5c4889126a21e65622cd0423a55d77737b8a4be55f189143723 text/EmbeddingGemma2Text.mlmodelc/model.mil
6
+ 60b4533a5103ebc2aab25ebcb8c0b9911f0793f7209e8f3858a033f58377a8e5 text/EmbeddingGemma2Text.mlmodelc/weights/weight.bin
7
+ 4b940b7da3ee169138c07d0a7383a6f3f67aaee04dad6f47d7b4cac88b74ec77 text/embeddings.int8
8
+ e77843e932248346050e51b00a6b9af1bfbc18ed75e4adb82d41f08c29218d25 text/embeddings.int8.scale.f16
9
+ 4d777ef5bdc1aa36227abdfb77c3e49e7b9c892d16e1b6bda41c393504828be4 text/tokenizer.json
10
+ e72b415885cf750027a103728f64cb0a7c85a9d43fa081ae88dbe8f4f4a15a1b vision/EmbeddingGemma2Vision.mlmodelc/analytics/coremldata.bin
11
+ 7523f8bb196ec158fa62946e823e78447f09bc3370218d68af522c956ffa0463 vision/EmbeddingGemma2Vision.mlmodelc/coremldata.bin
12
+ fc4aa6c9db192994c4552331d30c3b521a4c1dd3fc13c54edbccd378607d627d vision/EmbeddingGemma2Vision.mlmodelc/model.mil
13
+ 5d8ca6ff93f928c5d704e51773ae94313545803fc7691f4b4fd9602fbdcb885b vision/EmbeddingGemma2Vision.mlmodelc/weights/weight.bin
14
+ 17de9480acc23638c0634a97ed89e51ed664433256d7d6f109587dcd91c79124 vision/position_embeddings.f16
config.json ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "base_model": "google/embeddinggemma-2",
3
+ "converted_from": "FluidInference/embeddinggemma-2-coreml",
4
+ "format": "coreml-compiled",
5
+ "modality": [
6
+ "text",
7
+ "image"
8
+ ],
9
+ "precision": {
10
+ "weights": "int8 (linear symmetric, per output channel)",
11
+ "activations": "fp16"
12
+ },
13
+ "minimum_os": {
14
+ "macOS": "15.0",
15
+ "iOS": "18.0"
16
+ },
17
+ "hidden_size": 512,
18
+ "embedding_dim": 768,
19
+ "matryoshka_dims": [
20
+ 768,
21
+ 512,
22
+ 256,
23
+ 128
24
+ ],
25
+ "embed_scale": 22.627417,
26
+ "text": {
27
+ "model": "text/EmbeddingGemma2Text.mlmodelc",
28
+ "compute_units": "cpuAndNeuralEngine",
29
+ "tokenizer": "text/tokenizer.json",
30
+ "token_table": {
31
+ "file": "text/embeddings.int8",
32
+ "dtype": "int8",
33
+ "shape": [
34
+ 262144,
35
+ 512
36
+ ],
37
+ "scale_file": "text/embeddings.int8.scale.f16",
38
+ "scale_dtype": "float16",
39
+ "scale_shape": [
40
+ 262144
41
+ ],
42
+ "use": "row = int8 values * scale[id] * embed_scale, passed as fp16"
43
+ },
44
+ "functions": {
45
+ "embed_32": {
46
+ "tokens": 32
47
+ },
48
+ "embed_48": {
49
+ "tokens": 48
50
+ },
51
+ "embed_64": {
52
+ "tokens": 64
53
+ },
54
+ "embed_128": {
55
+ "tokens": 128
56
+ },
57
+ "embed_256": {
58
+ "tokens": 256
59
+ },
60
+ "embed_512": {
61
+ "tokens": 512
62
+ },
63
+ "pack_256": {
64
+ "tokens": 256,
65
+ "slots": 8
66
+ }
67
+ }
68
+ },
69
+ "bos_token_id": 2,
70
+ "eos_token_id": 1,
71
+ "pad_token_id": 0,
72
+ "prompts": {
73
+ "document": "title: none | text: ",
74
+ "search_query": "task: search result | query: ",
75
+ "question_answering": "task: question answering | query: ",
76
+ "fact_checking": "task: fact checking | query: ",
77
+ "code_retrieval": "task: code retrieval | query: ",
78
+ "classification": "task: classification | query: ",
79
+ "clustering": "task: clustering | query: ",
80
+ "sentence_similarity": "task: sentence similarity | query: "
81
+ },
82
+ "vision": {
83
+ "model": "vision/EmbeddingGemma2Vision.mlmodelc",
84
+ "compute_units": "cpuAndNeuralEngine for vision_70 and vision_140 (about 7x less energy per image than the GPU in our tests); cpuAndGPU for vision_280 (not tried on the Neural Engine)",
85
+ "functions": {
86
+ "vision_70": {
87
+ "tokens": 70,
88
+ "patches": 630
89
+ },
90
+ "vision_140": {
91
+ "tokens": 140,
92
+ "patches": 1260
93
+ },
94
+ "vision_280": {
95
+ "tokens": 280,
96
+ "patches": 2520
97
+ }
98
+ },
99
+ "patch_size": 16,
100
+ "pooling_kernel": 3,
101
+ "resize": "aspect-preserving, bicubic + antialias, sides multiple of 48 px, at most 9 x tokens patches",
102
+ "pixel_scale": "RGB / 255 (the model applies 2x - 1)",
103
+ "patch_layout": "row-major patches, each [16 rows][16 cols][RGB]",
104
+ "position_table": {
105
+ "file": "vision/position_embeddings.f16",
106
+ "dtype": "float16",
107
+ "shape": [
108
+ 2,
109
+ 1024,
110
+ 768
111
+ ],
112
+ "use": "table[0][x] + table[1][y] per patch, zero for padding"
113
+ },
114
+ "boi_token_id": 255999,
115
+ "eoi_token_id": 258882,
116
+ "text_sequence": "<bos> <|image> [image tokens] <image|> <eos> -> smallest embed_S that fits"
117
+ }
118
+ }
text/EmbeddingGemma2Text.mlmodelc/analytics/coremldata.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbca8ceddbfe6edab5888ec5341b48fb9ad3d08117f84c36fd81837fd8c8a9bd
3
+ size 243
text/EmbeddingGemma2Text.mlmodelc/coremldata.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b494840b269a9cb533d7249f6fb54194e9cdd3bd318be464f01ebda87ab72d16
3
+ size 972
text/EmbeddingGemma2Text.mlmodelc/model.mil ADDED
The diff for this file is too large to render. See raw diff
 
text/EmbeddingGemma2Text.mlmodelc/weights/weight.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60b4533a5103ebc2aab25ebcb8c0b9911f0793f7209e8f3858a033f58377a8e5
3
+ size 138959936
text/embeddings.int8 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b940b7da3ee169138c07d0a7383a6f3f67aaee04dad6f47d7b4cac88b74ec77
3
+ size 134217728
text/embeddings.int8.scale.f16 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e77843e932248346050e51b00a6b9af1bfbc18ed75e4adb82d41f08c29218d25
3
+ size 524288
text/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d777ef5bdc1aa36227abdfb77c3e49e7b9c892d16e1b6bda41c393504828be4
3
+ size 32170510
vision/EmbeddingGemma2Vision.mlmodelc/analytics/coremldata.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e72b415885cf750027a103728f64cb0a7c85a9d43fa081ae88dbe8f4f4a15a1b
3
+ size 243
vision/EmbeddingGemma2Vision.mlmodelc/coremldata.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7523f8bb196ec158fa62946e823e78447f09bc3370218d68af522c956ffa0463
3
+ size 689
vision/EmbeddingGemma2Vision.mlmodelc/model.mil ADDED
The diff for this file is too large to render. See raw diff
 
vision/EmbeddingGemma2Vision.mlmodelc/weights/weight.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d8ca6ff93f928c5d704e51773ae94313545803fc7691f4b4fd9602fbdcb885b
3
+ size 152429760
vision/position_embeddings.f16 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:17de9480acc23638c0634a97ed89e51ed664433256d7d6f109587dcd91c79124
3
+ size 3145728