Views
No views yet
KaLM-Embedding/KaLM-Reranker-V1-Nano,
KaLM's "fast but not late interaction" (FBNL) document reranker. It runs natively on the
Apple Silicon GPU via Metal.Weights are NOT redistributed here. This repo ships only the MLX forward pass (modeling_kalm_mlx.py) and this card. The actual model weights are loaded at runtime from thebase_modelabove, out of your local HuggingFace cache. Download them separately (see Usage). The base weights and their license belong to the KaLM team and Google (see License).
scaled_dot_product_attention that concatenates the decoder's self-attention KV with
cross-attention KV computed over the cached passage encodings.softmax([logit_yes, logit_no])[yes], read from the decoder's
final position.config.json (encoder.text_config + decoder +
rope_parameters). The same modeling_kalm_mlx.py file therefore serves both Nano
(0.27B activated, H=640, 18 layers) and Small (1B activated, H=1152, 26 layers) — just
pass the model id.mx.load() (no torch, no conversion). The tokenizer is the original,
loaded via HuggingFace AutoTokenizer (the tokenizers library only — no torch model).modeling_kalm_mlx.py is hand-written
from the architecture — encoder, chunk/Matryoshka pool, and the merged self+cross
attention decoder. RoPE inverse-frequency tables are computed from config and validated
identical to the on-disk buffers.| File | Purpose |
|---|---|
modeling_kalm_mlx.py | Torch-free MLX inference module. Exposes load(model_id) and rerank(query, docs, top_n). Config-generalized — serves both Nano and Small. |
requirements.txt | mlx, safetensors, transformers, numpy. |
.gitignore | Ignores __pycache__/ and *.safetensors (weights are never committed here). |
README.md | This card. |
mx.compile, concurrency, and precompute all landed
within measurement noise.What this does NOT prove: that the port is faithful does not establish a task-accuracy number on any end-to-end benchmark. See the honesty note in Quality.
| Model | MacBook Pro (MacBookPro18,4) |
| Chip | Apple M1 Max (10 cores: 8 performance + 2 efficiency) |
| GPU | Apple Silicon unified-memory GPU, driven via Metal (MLX runs natively on it) |
| Memory | 64 GB unified |
| macOS | 26.5.1 (build 25F80) |
Python MLX (mlx.core) | 0.31.2 |
Run it fast (Rust): this model also runs in themlx-rerankserver — torch-free, native Metal,/rerankAPI:RERANK_MODEL=KaLM-Embedding/KaLM-Reranker-V1-Nano rerank --serve. The Python below is the readable reference implementation.
1pip install -r requirements.txt
2# Download the base weights once (NOT included in this repo):
3huggingface-cli download KaLM-Embedding/KaLM-Reranker-V1-Nano1import modeling_kalm_mlx as kalm
2
3# Loads weights + tokenizer from your local HF cache (defaults to the Nano model id;
4# pass "KaLM-Embedding/KaLM-Reranker-V1-Small" — or set KALM_MODEL — to run Small instead).
5kalm.load("KaLM-Embedding/KaLM-Reranker-V1-Nano")
6
7results = kalm.rerank(
8 "How long is my commute?",
9 [
10 "My commute is 45 minutes each way.",
11 "I like coffee.",
12 "The weather was nice today.",
13 ],
14 top_n=3,
15)
16# -> [{"index": 0, "relevance_score": 0.98...},
17# {"index": ..., "relevance_score": ...}, ...] highest first, print(results)python modeling_kalm_mlx.py KaLM-Embedding/KaLM-Reranker-V1-NanoKALM_MODEL (model id), KALM_SUBBATCH (encode sub-batch size,
default 25), KALM_MEM_GB / KALM_CACHE_GB (MLX memory / cache caps).modeling_kalm_mlx.py): released under Apache-2.0,
matching the parent model.KaLM-Embedding/KaLM-Reranker-V1-Nano, released by the KaLM team under Apache-2.0.google/t5gemma-2-270m-270m), so
Google's Gemma Terms of Use also apply to the
underlying base model, in addition to KaLM's Apache-2.0 release. You are responsible for
complying with both when you download and use the weights.