all-MiniLM-L6-v2 Core ML

Core ML conversion of sentence-transformers/all-MiniLM-L6-v2 for on-device text embeddings on iOS/macOS.

Model Details

Property Value
Parameters 22.7M
Embedding dim 384
Max input tokens 256
Original model ~90 MB (FP32)
Core ML size ~43 MB (FP16)
Compute units CPU + Neural Engine
Min deployment iOS 18 / macOS 15

Files

  • all-minilm-l6-v2.mlpackage/ β€” Core ML model package (portable format). Compile with xcrun coremlcompiler for your target device.
  • all-minilm-l6-v2.mlmodelc/ β€” Pre-compiled model for Apple Silicon Macs.
  • tokenizer/ β€” BERT WordPiece tokenizer (tokenizer.json, vocab.txt, config files).

Usage

Swift (iOS/macOS)

import CoreML

let model = try MLModel(contentsOf: modelURL)
let prediction = try await model.prediction(input: [
    "input_ids": inputIds,
    "attention_mask": attentionMask,
    "token_type_ids": tokenTypeIds
])
let embedding = prediction.featureValue(for: "div_1")!.multiArrayValue!
// Shape: (1, 384), L2-normalized

Python (validation)

import coremltools as ct
from transformers import AutoTokenizer

model = ct.models.MLModel("all-minilm-l6-v2.mlpackage")
tokenizer = AutoTokenizer.from_pretrained("tokenizer/")

encoded = tokenizer("Hello world", return_tensors="np",
                    padding="max_length", truncation=True, max_length=256)
prediction = model.predict({
    "input_ids": encoded["input_ids"].astype("int32"),
    "attention_mask": encoded["attention_mask"].astype("int32"),
    "token_type_ids": encoded["token_type_ids"].astype("int32"),
})
embedding = prediction["div_1"]  # (1, 384), L2-normalized

Accuracy

Metric Value
Max element diff vs PyTorch FP32 ~0.001
Cosine similarity vs original > 0.99995

Conversion was done with FP16 precision β€” effectively lossless for semantic search.

Conversion Pipeline

sentence-transformers/all-MiniLM-L6-v2 (PyTorch)
  β†’ torch.export (dynamo)
  β†’ coremltools 9.0 (FP16, iOS18)
  β†’ all-minilm-l6-v2.mlpackage
  β†’ xcrun coremlcompiler
  β†’ all-minilm-l6-v2.mlmodelc

License

Apache 2.0 (same as the original model).

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support