Core ML conversion of ibm-granite/granite-embedding-97m-multilingual-r2, pinned to revision 835ad14087e140460703cf0fae09f97d469d65c2. The original model and this conversion are distributed under Apache 2.0. See LICENSE and the upstream model card for attribution and training details.
The root files and v1 tag retain the original FP32 conversion. The mixed-fp16 folder provides a selective-FP16 conversion with shared weights and separate query128 / passage512 functions. Pin mixed-fp16-v1 for that variant. FP16 is floating-point mixed precision, not integer or palette quantization. See its model card for the interface, numerical checks and limitations.
The sections below describe the original FP32 variant.
| Property | Value |
|---|---|
| Precision | Float32 weights and computation |
| Input shape | Batch 1, exactly 512 tokens |
| Inputs | input_ids and attention_mask, both int32 |
| Output | embedding, 384 dimensions |
| Pooling | CLS token |
| Normalization | L2; compare vectors using a dot product or cosine similarity |
| Padding | Right padding; token ID 179935 |
| Query and passage prefixes | None |
Use the included tokenizer assets with special tokens enabled. Apply identical preprocessing to queries and indexed passages. Split text that exceeds 512 tokens before embedding; do not silently truncate a query.
SemanticEncoder.mlpackage: source Core ML package for coremltools or recompilation for another deployment target.SemanticEncoder.mlmodelc: compiled model for native Core ML integrations.tokenizer.json, tokenizer_config.json, and special_tokens_map.json: tokenizer assets from the pinned source model.semantic-model.json: source revision, conversion settings, tool versions, validation measurements, and file checksums.validation-probes.json and native-validation.json: synthetic reference vectors and native validation results.convert_granite_coreml.py and validate_granite_coreml.swift: conversion and validation source.Download the source package and tokenizer assets:
hf download rankun203/granite-embedding-97m-multilingual-r2-coreml --revision v1 --local-dir ./granite-coreml
Run inference on macOS with coremltools, transformers, and numpy:
import coremltools as ct
import numpy as np
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("./granite-coreml")
text = "Which release date did the team agree on?"
if len(tokenizer.encode(text, add_special_tokens=True)) > 512:
raise ValueError("Split or shorten text before embedding.")
inputs = tokenizer(
text, return_tensors="np", padding="max_length", max_length=512,
truncation=False,
)
model = ct.models.MLModel("./granite-coreml/SemanticEncoder.mlpackage")
embedding = model.predict({
"input_ids": inputs["input_ids"].astype(np.int32),
"attention_mask": inputs["attention_mask"].astype(np.int32),
})["embedding"].reshape(-1)
Native Swift integrations can load SemanticEncoder.mlmodelc using MLModel(contentsOf:configuration:) and supply the same token IDs and attention mask. Compiled artifacts were prepared on macOS; recompile the source package when required by another platform or deployment environment.
The encoder retains the source model's CLS pooling and applies L2 normalization to the output. Conversion uses a fixed 512-token input and float32 computation. Automatic float16 conversion produced non-finite values in attention-mask operations and was rejected.
Seven synthetic English, Chinese, and longer padded probes were compared with the pinned PyTorch model. Native Core ML embeddings had cosine similarity above 0.999999999999 against the reference vectors. A separate Swift tokenizer and inference check matched token IDs exactly and produced embedding cosine similarity above 0.99999 on all seven probes. Detailed numeric measurements are included in the validation files.
The included conversion source records its dependencies in semantic-model.json. Reproduction requires PyTorch, Transformers, NumPy, coremltools, and the macOS Core ML compiler from Xcode. The source model is pinned in the script.
This is a format conversion, not additional model training. Numerical parity on synthetic probes does not establish retrieval quality for a particular language or corpus. This artifact uses a fixed 512-token context, even if the upstream model supports a different limit. Float32 increases download size and memory use. Load time and throughput depend on hardware, compute-unit selection, and compilation caches; no cold-start or cross-device performance claim is made.
SemanticEncoder.mlmodelc/weights/weight.bin 390 MBSemanticEncoder.mlpackage/Data/com.apple.CoreML/weights/weight.bin 390 MBmixed-fp16/SemanticEncoder.mlmodelc/weights/weight.bin 195 MBmixed-fp16/SemanticEncoder.mlpackage/Data/com.apple.CoreML/weights/weight.bin 195 MBSemanticEncoder.mlmodelc/coremldata.bin 0.5 kBmixed-fp16/SemanticEncoder.mlmodelc/coremldata.bin 0.3 kBSemanticEncoder.mlmodelc/analytics/coremldata.bin 0.2 kBmixed-fp16/SemanticEncoder.mlmodelc/analytics/coremldata.bin 0.2 kBibm-granite/granite-embedding-97m-multilingual-r2