MLX
fp16 (unquantized) quantization of
LiquidAI/LFM2.5-Embedding-350M,
a bidirectional LFM2.5 dense bi-encoder (1024-d CLS vector) for multilingual retrieval. Runs on Apple Silicon via MLX.
1# pip install mlx mlx-lm transformers
2# This repo bundles `mlx_lfm2_encoder.py` — the bidirectional LFM2 encoder
3# (CLS pooling / ColBERT MaxSim) that the stock causal LFM2 loaders do NOT provide.
4import mlx.core as mx
5from transformers import AutoTokenizer
6from mlx_lfm2_encoder import load_model
7
8tok = AutoTokenizer.from_pretrained(".", trust_remote_code=True)
9model, _ = load_model(".", head="embedding") # head: "embedding" or "colbert"
10
11# Asymmetric prompts (REQUIRED — the model was trained with them):
12def encode(texts, prefix):
13 enc = tok([prefix + t for t in texts], return_tensors="np", padding=True,
14 truncation=True, max_length=512)
15 out = model(mx.array(enc["input_ids"]), mx.array(enc["attention_mask"]))
16 mx.eval(out)
17 return out # (B, 1024) CLS-pooled, L2-normalized
18
19q = encode(["was the nightmare before christmas a disney film"], "query: ")
20d = encode(["The Nightmare Before Christmas is a 1993 stop-motion film ..."], "document: ")
21scores = (q @ d.T) # cosine similarity
These are
bidirectional encoders (non-causal attention + non-causal short-conv +
CLS pooling). General-purpose causal LFM2 loaders produce
wrong embeddings here, so this repo ships
mlx_lfm2_encoder.py (validated to cosine ≥ 0.999
against the original
transformers model). For the broader MLX embedding ecosystem see
mlx-embeddings.