Views
No views yet
nvidia/llama-nemotron-rerank-1b-v2
cross-encoder reranker, built to run natively on Apple Silicon.No weights are redistributed in this repo. The model weights are NVIDIA's and are loaded from thebase_model(nvidia/llama-nemotron-rerank-1b-v2) out of your local Hugging Face cache at runtime. This repo ships only inference code (an MLX forward pass) and documentation — nothing here downloads or re-hosts the weights for you.
nvidia/llama-nemotron-rerank-1b-v2 is not a standard causal LLM, and
mlx_lm cannot load it as-is. Its architecture is
LlamaBidirectionalForSequenceClassification (config model_type: llama_bidirec): a Llama-3.2-1B backbone with bidirectional (non-causal)
attention (is_causal=False on every layer — encoder-style, every token
attends to every other token), followed by masked average pooling over the
non-pad tokens and a linear score head (score.weight, shape [1, 2048],
temperature 1.0) that projects the pooled vector to a single relevance logit.mlx_lm's Llama backbone modules for the
transformer layers, swaps in a bidirectional (padding-only) attention mask, does
the masked-mean pool, and applies the popped score.weight head — reproducing
NVIDIA's reranker on Metal.question:{q} \n \n passage:{p} (one (query, passage)
pair per sequence).nvidia/llama-nemotron-rerank-1b-v2, used as-is.
They are read from the HF-cached parent snapshot and cast to f16 for the
Metal forward. No fine-tuning, no surgery — same weights, faithfully run.safetensors safe_open(..., "pt") (the bf16 tensors decode through the torch path, then cast to f16 MLX
arrays — mlx/numpy loaders cannot decode bf16 directly).mlx-rerank — a torch-free
mlx-rs 0.25 + tokenizers 0.20 runner (single rerank binary) that serves
a /rerank HTTP endpoint. This is the engine you'd actually
deploy.reference_mlx.py in this repo —
a compact, readable MLX forward that loads weights from the HF-cached parent,
does length-sorted sub-batching, masked-mean pooling, and the score-head
projection. Use it to understand or validate the forward.| File | Purpose |
|---|---|
README.md | This model card. |
reference_mlx.py | Python MLX reference forward + a 100-doc micro-benchmark; loads weights from the HF-cached base_model. |
requirements.txt | Python deps for the reference (mlx, mlx-lm, torch, safetensors, transformers, numpy). |
mlx-rerank, not here.| Stack | ms / 100 docs |
|---|---|
| Nemotron-1B MLX (this code, local) | ~1.43 s (sub_batch=10 optimum) |
| Nemotron-1B PyTorch-MPS (same model) | ~5.5 s |
reference_mlx.py ships with range(0, len(docs), 25); lower it to 10 to
reproduce the optimum.0.14934 (MLX) vs 0.15001 (PyTorch) → diff
0.0007.[2, 26, 0] in both MLX and
PyTorch.Model: MacBook Pro (MacBookPro18,4)
Chip: Apple M1 Max (10 CPU cores: 8P + 2E)
GPU: Apple Silicon unified-memory GPU, driven via Metal (MLX runs natively)
RAM: 64 GB unified
macOS: 26.5.1 (build 25F80)mlx.core 0.31.2 (Python reference); the Rust engine uses mlx-rs
0.25 + tokenizers 0.20 on rustc 1.93.0.1pip install -r requirements.txt
2# Ensure the base model is in your HF cache first, e.g.:
3# huggingface-cli download nvidia/llama-nemotron-rerank-1b-v2
4python reference_mlx.pyreference_mlx.py locates the base_model snapshot in
~/.cache/huggingface/hub/..., loads the weights as f16, and runs the
hand-written forward. The included run(...) function takes a query and a list
of documents and returns one relevance score per document (sort descending to
rerank). The __main__ block benchmarks a 100-doc payload.mlx-rerank: a torch-free
mlx-rs runner that serves a /rerank endpoint.1git clone https://github.com/jak-pan/mlx-rerank
2cd mlx-rerank
3cargo run --release --bin rerank
4# POST {"query": "...", "documents": ["...", ...]} to /reranknvidia/llama-nemotron-rerank-1b-v2 (published under the NVIDIA Open Model
License, an NVIDIA-specific community license — not Apache/MIT). The local
snapshot does not pin a license string, so verify the exact license name and
terms on the
NVIDIA model page
before relying on it. This repo redistributes no weights — only inference
code and documentation. The backbone lineage is Llama-3.2-1B
(_name_or_path: nvidia/llama-3.2-nv-rerankqa-1b-v2).