harshav's picture
Link Swift 6.2 package repo (harshav167/clipstral-coreai)
a84354a verified
|
Raw History Blame Contribute Delete
9.62 kB
---
license: apache-2.0
base_model: mistralai/Mistral-Multimodal-Embed-1B
base_model_relation: quantized
library_name: coreai
pipeline_tag: feature-extraction
language:
- multilingual
tags:
- coreai
- apple-silicon
- macos
- neural-engine
- clipstral
- multimodal
- embeddings
- image-text-retrieval
- text-to-video-retrieval
- fp16
- int8
---
# Mistral-Multimodal-Embed-1B (Core AI β€” macOS 27+)
Native **Apple Core AI (`.aimodel`)** conversion of [`mistralai/Mistral-Multimodal-Embed-1B`](https://huggingface.co/mistralai/Mistral-Multimodal-Embed-1B) (**Clipstral-1B**, Apache 2.0) for **macOS 27+ Apple Silicon**, producing shared `1,024`-dim L2-normalized embeddings across **text** (`1..8,192` tokens), **variable-aspect images** (up to `1036px`, zero padding), and **multi-frame video** (any frame count & resolution).
- **Pinned upstream checkpoint:** `mistralai/Mistral-Multimodal-Embed-1B` @ `bfdaf7bd6fd65a1c3c5cbb3cecf884ce153751ff` (`model.safetensors` SHA-256 `e1ce98fbbe92b6110f5ce54a6e3dcc80d045f0b85409c63fae2358eb36e00641`)
- **Toolchain:** `coreai-core 1.0.0`, `coreai-torch 0.4.4`, `coreai-opt 0.5.0`, macOS 27.3, Xcode 27.3 Beta 2
- **Swift 6.2 runtime + CLI:** [`harshav167/clipstral-coreai`](https://github.com/harshav167/clipstral-coreai) β€” zero Python runtime dependencies; supports independent per-tower compute-unit placement (`gpu`, `ane`, `cpu`) and hybrid execution (e.g., GPU text + Neural Engine vision).
---
## Shipped Variants (Pareto Frontier)
Download **only the variant folder you need** plus `manifest.json` and `tokenizer.json` (no need to pull all 4.8 GB).
| Variant folder | Target | Precision | Size (MB) | Shapes | When to use |
|---|---|---|---:|---|---|
| `gpu-fp16/` | Apple GPU | FP16 (unquantized) | 2,485.7 | Dynamic text (`1..8192`), vision (`28..1036`), video | Maximum fidelity (`1.0000` text / `1.0000` vision / `1.0000` video) and fastest long-context GPU speed |
| `gpu-int8-block32/` | Apple GPU | Per-block-32 INT8 weights, FP16 embeddings & projections | **1,545.4** | Dynamic text (`1..8192`), vision (`28..1036`), video | **Best compact all-rounder** β€” 38% smaller than FP16, smaller than MLX `6bit`, `0.9999+` cosine across all 3 modalities |
| `ane-fp16/` | **Apple Neural Engine** | FP16 (`BC1S` `1Γ—1 Conv2d`, `MaxAbsRMSNorm`, 10/10 monolithic `ANE_region_0_0`) | 818.8 (vision) | Static buckets (`224`, `336`, `448`, `448Γ—252`, `252Γ—448`) | **0% GPU contention** vision offload (`31.36 ms` at `224Γ—224`); pair with `gpu-fp16` or `gpu-int8-block32` text/temporal |
*(Dropped candidates that failed quality or compilation gates are **not** shipped: `gpu-fp8-e4m3` dropped below the `0.999` cosine floor and was slower than `gpu-int8-block32`; `gpu-int4-block32` broke retrieval (`0.986` text / `0.849` vision); `ane-pal8` exceeded ANE specialization timeout on macOS 27.3.)*
---
## Benchmarks (Apple M4 Max 64 GB, macOS 27.3)
All runtimes were measured on the exact same machine against the exact same frozen upstream PyTorch `float32` CPU oracle (`warm median of 10 runs`). Precision classes are compared **apples-to-apples**.
### 1. Full Precision (`16-bit`): Core AI `gpu-fp16` vs. MLX `bf16` vs. PyTorch MPS `fp16`
| Runtime & Variant | Target | Size (MB) | Warm Load (s) | Text cos (med / min) | Vision cos (med / min) | Video cos (med / min) | Text `S=16 / 128 / 2048` (ms) | Vision `224 / 448 / 672` (ms) | Video `8f@224 / 16f@224 / 16f@336` (ms) |
|---|---|---:|---:|---|---|---|---|---|---|
| PyTorch MPS `fp16` | GPU | 2,480.0 | β€” | 1.0000 / β€” | 1.0000 / β€” | 1.0000 / β€” | 14.26 / 26.98 / 328.40 | 38.44 / 129.12 / 315.09 | 236.19 / 480.59 / 1112.86 |
| MLX `bf16` (upstream weights) | GPU | 2,500.4 | 1.78 | 0.999962 / 0.999925 | 0.999944 / 0.999220 | 0.999739 / 0.999629 | 10.00 / 23.41 / 277.44 | 34.71 / **108.21** / 272.52 | **204.42 / 388.58** / 944.80 |
| **Core AI `gpu-fp16`** | GPU | 2,485.7 | **1.40** | **1.000000 / 0.999999** | **0.999998 / 0.999912** | **0.999994 / 0.999987** | **7.80 / 16.62 / 212.38** | **31.92** / 112.18 / **272.31** | 221.39 / 439.74 / **929.69** |
| **Core AI `ane-fp16`** (vision) | **ANE** | 818.8 | 5.73 | β€” | 0.999858 / 0.999243 | 0.999490 / 0.999412 | β€” | **31.36** / 162.04 / β€” | 288.05 / 686.66 / β€” |
**16-bit takeaway:** Core AI `gpu-fp16` beats MLX `bf16` on **accuracy across all three modalities** (FP16 10 mantissa bits vs. BF16 7 bits), **warm load** (`1.40s` vs. `1.78s`), **every text length** (`1.28×–1.41Γ—` faster), **`224Γ—224` vision**, **`672Γ—672` vision**, and **`16f@336` video**.
### 2. Quantized (`8-bit` / `6-bit`): Core AI `gpu-int8-block32` vs. MLX `8bit` / `mxfp8` / `6bit`
| Runtime & Variant | Quant Scope | Size (MB) | Warm Load (s) | Text cos (med / min) | Vision cos (med / min) | Video cos (med / min) | Text `S=16 / 128 / 2048` (ms) | Vision `224 / 448 / 672` (ms) | Video `8f@224 / 16f@224` (ms) |
|---|---|---:|---:|---|---|---|---|---|---|
| **Core AI `gpu-int8-block32`** | **All 3 towers** (`int8`, block-32) | **1,545.4** | 2.06 | **0.999942 / 0.999861** | **0.999959 / 0.999869** | **0.999897 / 0.999869** | 8.34 / 19.40 / **239.27** | 36.38 / 117.46 / 298.60 | 254.31 / 502.03 |
| MLX `8bit` (`nativ-community`) | Text only (`8bit` g64); Vision/Temp `bf16` | 1,768.5 | **1.13** | 0.999845 / 0.999754 | 0.999944 / 0.999220 | 0.999739 / 0.999629 | **4.88 / 17.67** / 249.54 | **24.68 / 93.82 / 224.53** | **166.96 / 347.96** |
| MLX `mxfp8` (`nativ-community`) | Text only (`mxfp8` g32); Vision/Temp `bf16` | 1,744.1 | 1.03 | 0.999855 / 0.999602 | 0.999944 / 0.999220 | 0.999739 / 0.999629 | 6.84 / 23.93 / 352.83 | 32.51 / 131.87 / 323.06 | 233.96 / 469.73 |
| MLX `6bit` (`nativ-community`) | Text only (`6bit` g64); Vision/Temp `bf16` | 1,573.3 | 0.82 | 0.998738 / 0.997954 | 0.999944 / 0.999220 | 0.999739 / 0.999629 | 6.50 / 21.53 / 350.63 | 29.35 / 117.15 / 316.25 | 208.46 / 411.02 |
**8-bit takeaway:** Core AI `gpu-int8-block32` quantizes **all three towers** (`1,545 MB` β€” `223 MB` smaller than MLX `8bit` and smaller than MLX `6bit`), achieves **higher cosine accuracy than every MLX quantized build across all three modalities**, and beats MLX `8bit` on long text (`S=512`: `57.1` vs. `60.3 ms`; `S=2048`: `239.3` vs. `249.5 ms`). MLX `8bit` remains faster on short text (`S=16`) and multi-frame `16f@224` video.
### 3. Real Public Dataset Retrieval Parity (`jxie/flickr8k`, `N=100` natural photos)
Paired bootstrap 95% CI against upstream PyTorch `float32` CPU (`R@1 = 0.9000`, `nDCG@10 = 0.9618`) on identical decoded RGB pixels:
| Variant | Text cos (med / min) | Image cos (med / min) | Recall@1 (Ξ” vs. `fp32`) | nDCG@10 (Ξ” vs. `fp32`) | Max similarity matrix Ξ” |
|---|---|---|---|---|---:|
| **Core AI `gpu-fp16`** | **1.000000 / 0.999999** | **0.999996 / 0.999973** | **0.9000 (`+0.0000`)** | **0.9618 (`+0.0000`)** | **0.00091** |
| **Core AI `gpu-int8-block32`** | **0.999963 / 0.999927** | **0.999911 / 0.999447** | **0.9100 (`+0.0100`, CI `[0.00, +0.03]`)** | **0.9655 (`+0.0037`, CI `[0.00, +0.011]`)** | **0.00390** |
### 4. Verification Gates Passed
- **Tokenizer parity:** `2,065 / 2,065` exact token-ID matches (`0` mismatches) across English, CJK, Arabic, Hindi, Thai, Greek, Hebrew, ZWJ emoji, code, whitespace, special tokens, and `8,192`-token truncation vs. upstream `AutoTokenizer`.
- **Float-first image preprocessing parity:** `22 / 22` synthetic fixtures (`max_abs = 2.38e-6`) + `100 / 100` real `jxie/flickr8k` photos (`max_abs = 9.54e-7`), preserving raw RGB samples on embedded ICC profiles to match upstream `PIL`.
- **Concurrency safety:** `150 / 150` bit-exact concurrent async `embed()` calls (`0` torn/mismatched outputs) via per-tower `AsyncMutex` serialization.
- **Static Core AI & ANE audit:** `coreai doctor` `0` issues across all shipped `.aimodel` assets; `ane-fp16` compiles to `10 / 10` monolithic `ANE_region_0_0` programs (`0` graph fragmentation, `0%` GPU fallback).
---
## Quickstart
### Download one variant with `hf` CLI
```bash
# Compact 8-bit GPU variant (1.55 GB)
hf download harshav/Mistral-Multimodal-Embed-1B-CoreAI \
--include "manifest.json" "tokenizer.json" "gpu-int8-block32/*" \
--local-dir ./clipstral-coreai
# Or full-precision FP16 GPU variant (2.49 GB)
hf download harshav/Mistral-Multimodal-Embed-1B-CoreAI \
--include "manifest.json" "tokenizer.json" "gpu-fp16/*" \
--local-dir ./clipstral-coreai
# Optional: add Neural Engine vision offload (+819 MB)
hf download harshav/Mistral-Multimodal-Embed-1B-CoreAI \
--include "ane-fp16/*" \
--local-dir ./clipstral-coreai
```
### Use from Swift 6.2 (macOS 27+, zero Python)
```swift
import MistralMultimodalEmbed
// Auto-download only the chosen variant into ~/Library/Application Support/MistralMultimodalEmbed/Models
let bundleURL = try await ClipstralModelStore.default.downloadVariant(
repoID: "harshav/Mistral-Multimodal-Embed-1B-CoreAI",
variantID: "gpu-int8-block32"
)
let model = try await MistralMultimodalEmbed.load(
bundleURL: bundleURL,
variant: "gpu-int8-block32",
placement: .init(text: .gpu, vision: .gpu, temporal: .gpu)
)
let textVec = try await model.embed(text: "A red bicycle parked beside a brick wall")
let imageVec = try await model.embed(image: cgImage, size: 448, transform: .keepRatio, resampler: .area)
let videoVec = try await model.embed(videoURL: mp4URL, numFrames: 16, size: 224)
```
---
## License & Attribution
Converted from [`mistralai/Mistral-Multimodal-Embed-1B`](https://huggingface.co/mistralai/Mistral-Multimodal-Embed-1B) by Mistral AI under the **Apache 2.0 License** (see `LICENSE`).