--- license: apache-2.0 base_model: google/embeddinggemma-2 library_name: coreml pipeline_tag: feature-extraction tags: - coreml - apple-silicon - multimodal - embeddings - gemma --- # EmbeddingGemma 2 (Multimodal) — Core ML Core ML conversions of Google's official [`google/embeddinggemma-2`](https://huggingface.co/google/embeddinggemma-2) multimodal checkpoint (744M parameters) for on-device text, image, video, and audio embeddings on Apple Silicon. The model is packaged as three weight-sharing **iOS 18 / macOS 15 multifunction FP16 `.mlpackage` bundles**, (one shared backbone and two standalone media encoders), along with the shared tokenizer and processor configuration files. > **Standalone text embedder:** `backbone_fp16.mlpackage` works on its own as a regular text embedder (up to `8,192` tokens). You do not need to download or load the vision or audio packages for text-only use—just pass zeros for `media_features`. For conversion scripts, verification suites, and the interactive architecture walkthrough, see the GitHub repository: [`Mannyking/embeddinggemma-2-coreml`](https://github.com/Mannyking/embeddinggemma-2-coreml). --- ## Available Core ML Packages | Package | Minimum OS Target | Static Functions (Tiers) | Saved Size | Precision | | --- | --- | --- | ---: | --- | | `backbone_fp16.mlpackage` | iOS/iPadOS 18, macOS 15 | `s128`, `s512`, `s2048`, `s4096`, `s8192` | 521 MB | FP16 weights + FP32 RMSNorm / RoPE / reductions | | `vision_fp16.mlpackage` | iOS/iPadOS 18, macOS 15 | `v70`, `v140`, `v280` | 329 MB | FP16 weights + FP32 RMSNorm / pooling | | `audio_fp16.mlpackage` | iOS/iPadOS 18, macOS 15 | `a8`, `a16`, `a30` | 561 MB | FP16 weights + FP32 RMSNorm / reductions | All three packages share one deduplicated FP16 weight file across their respective static functions. If you only need text embeddings at ≤512 tokens or want a smaller INT4 footprint (`175.9 MB`), see [`Mannyking/embeddinggemma-2-text-270m-coreml`](https://huggingface.co/Mannyking/embeddinggemma-2-text-270m-coreml). --- ## Platform Compatibility & Memory (`Physical footprint`) All packages require **iOS/iPadOS 18 or macOS 15 and newer** (required for Core ML multifunction `.mlpackage` bundles) and execute on Metal GPU under `ALL` compute units on Apple Silicon. Memory below is reported as Apple's **Peak `Physical footprint`**, measured in isolated Python worker processes on macOS Apple Silicon (includes ~290 MB of Python/`coremltools` baseline, so native Swift apps are lower): | Model / Combination | Tier(s) | Latency (GPU) | Peak `Physical footprint` | Cosine vs. PyTorch F32 | | --- | --- | ---: | ---: | ---: | | Shared backbone | `s128` | `9.6 ms` | `452 MB` | `1.000000` | | Shared backbone | `s512` | `15.2 ms` | `494 MB` | `1.000000` | | Shared backbone | `s2048` | `57.3 ms` | `934 MB` | `1.000000` | | Shared backbone | `s4096` | `158.0 ms` | `1.9 GB` | `1.000000` | | Shared backbone | `s8192` | `512.4 ms` | `5.6 GB` | `1.000000` | | Vision encoder | `v70` / `v140` / `v280` | `12.0` / `24.4` / `53.5 ms` | `404` / `448` / `536 MB` | `0.999987`–`0.999993` | | Audio encoder | `a8` / `a16` / `a30` | `15.4` / `19.4` / `25.5 ms` | `424` / `459` / `510 MB` | `0.999867`–`0.999989` | | Vision + Backbone (E2E) | `v280` + `s512` | — | `647 MB` | `0.999984` | | Audio + Backbone (E2E) | `a8` + `s512` | — | `552 MB` | `0.999999` | | Audio + Backbone (E2E) | `a30` + `s2048` | — | `1.0 GB` | `0.999990` | **Mobile guidance:** All Vision and Audio tiers plus Backbone `s128`, `s512`, and `s2048` fit comfortably within iPhone memory limits. `s4096` (`1.9 GB`) and `s8192` (`5.6 GB`) are best reserved for iPad Pro or Mac. --- ## Inputs, Outputs, and Preprocessing Tokenization, official task prompts, image patching, video frame sampling, and 16 kHz log-mel spectrogram extraction run outside the Core ML packages: - **Shared backbone (`s{N}`, `N ∈ {128, 512, 2048, 4096, 8192}`):** - Inputs: `input_ids` (`Int32 [1, N]`), `attention_mask` (`Int32 [1, N]`), `media_features` (`Float32 [1, N, 512]`, zeros for text-only calls) - Output: `embedding` (`Float32 [1, 768]`, L2-normalized). Optional Matryoshka truncation (`512`, `256`, `128`) slices the leading dimensions and re-normalizes. - **Vision encoder (`v70` / `v140` / `v280`, patch counts `630` / `1260` / `2520`):** - Inputs: `pixel_values` (`Float32 [1, P, 768]`), `image_position_ids` (`Int32 [1, P, 2]`, `-1` for padding) - Output: `Float32 [1, T, 512]` soft tokens (`T ∈ {70, 140, 280}`) - **Audio encoder (`a8` / `a16` / `a30`, mel frames `816` / `1632` / `3024`):** - Inputs: `input_features` (`Float32 [1, F, 128]`), `input_features_mask` (`Int32 [1, F]`) - Output: `Float32 [1, T, 512]` soft tokens (`T ∈ {204, 408, 756}`) - **Special token IDs:** ` = 0`, ` = 1`, ` = 2`, ` = 3`. --- ## Download and Compile Download all packages or select only the modalities you need: ```sh # Download everything hf download Mannyking/embeddinggemma-2-coreml --local-dir models/ # Or download only the shared backbone + tokenizer hf download Mannyking/embeddinggemma-2-coreml \ --include "backbone_fp16.mlpackage/**" "tokenizer*" "config.json" \ --local-dir models/ ``` Precompile `.mlpackage` bundles to `.mlmodelc` on macOS (or add them directly to an Xcode target): ```sh xcrun coremlcompiler compile models/backbone_fp16.mlpackage models/ xcrun coremlcompiler compile models/vision_fp16.mlpackage models/ xcrun coremlcompiler compile models/audio_fp16.mlpackage models/ ```