Instructions to use handwoven8588/CodeRankEmbed-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use handwoven8588/CodeRankEmbed-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible embeddings server: llama serve -hf handwoven8588/CodeRankEmbed-GGUF:Q8_0 --embeddings
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible embeddings server: llama serve -hf handwoven8588/CodeRankEmbed-GGUF:Q8_0 --embeddings
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible embeddings server: ./build/bin/llama serve -hf handwoven8588/CodeRankEmbed-GGUF:Q8_0 --embeddings
- Llama new
- LM Studio
- Jan
- Ollama
How to use handwoven8588/CodeRankEmbed-GGUF with Ollama:
ollama run hf.co/handwoven8588/CodeRankEmbed-GGUF:Q8_0
- Unsloth Desktop
- Docker Model Runner
How to use handwoven8588/CodeRankEmbed-GGUF with Docker Model Runner:
docker model run hf.co/handwoven8588/CodeRankEmbed-GGUF:Q8_0
- Lemonade
How to use handwoven8588/CodeRankEmbed-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull handwoven8588/CodeRankEmbed-GGUF:Q8_0
Run and chat with the model
lemonade run user.CodeRankEmbed-GGUF-Q8_0
List all available models
lemonade list
- Atomic Chat
Add CodeRankEmbed f16 + Q8_0 GGUFs and model card
Browse files- .gitattributes +2 -0
- CodeRankEmbed-Q8_0.gguf +3 -0
- CodeRankEmbed-f16.gguf +3 -0
- README.md +120 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
CodeRankEmbed-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
CodeRankEmbed-f16.gguf filter=lfs diff=lfs merge=lfs -text
|
CodeRankEmbed-Q8_0.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:14615b1e4f4c24f3599309deaef97e54dc4f8c59cd2842dbc7c94e3bda1fdaeb
|
| 3 |
+
size 146033152
|
CodeRankEmbed-f16.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8017b5bca09c111b5264cd686274b361aa54213a10cdf307eced3a3a0940444c
|
| 3 |
+
size 274181632
|
README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model:
|
| 4 |
+
- nomic-ai/CodeRankEmbed
|
| 5 |
+
base_model_relation: quantized
|
| 6 |
+
library_name: gguf
|
| 7 |
+
pipeline_tag: feature-extraction
|
| 8 |
+
language:
|
| 9 |
+
- code
|
| 10 |
+
tags:
|
| 11 |
+
- gguf
|
| 12 |
+
- llama.cpp
|
| 13 |
+
- flash-attention
|
| 14 |
+
- code-retrieval
|
| 15 |
+
- embeddings
|
| 16 |
+
- nomic-bert
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# CodeRankEmbed-GGUF
|
| 20 |
+
|
| 21 |
+
GGUF quantizations of [`nomic-ai/CodeRankEmbed`](https://huggingface.co/nomic-ai/CodeRankEmbed) β a 137M-parameter `nomic-bert` code-embedding model (768-dim, CLS-pooled, trained to 2048 tokens).
|
| 22 |
+
|
| 23 |
+
`CodeRankEmbed`'s stock attention is **eager-only** β there is no flash-attention or SDPA path in its `trust_remote_code` modeling file, so peak memory grows as `O(batch Γ heads Γ seqΒ²)` and it OOMs at high batch even at 137M params. **This repo is one of two ways we give it flash attention** β the **llama.cpp / GGUF runtime path**. Converting to GGUF discards the eager Python entirely; llama.cpp re-implements the architecture in its own graph and runs *its own* flash-attention kernel. The result, built from the original FP32 safetensors and verified end-to-end: faithful metadata, flash attention engages, **retrieval-lossless** vs the full-precision reference, and ~5.8Γ lower peak VRAM.
|
| 24 |
+
|
| 25 |
+
## Two paths to flash attention
|
| 26 |
+
|
| 27 |
+
The same eager-only model, fixed two different ways:
|
| 28 |
+
|
| 29 |
+
| Path | Repo | How | Runtime & deps | Reach for it when |
|
| 30 |
+
|---|---|---|---|---|
|
| 31 |
+
| **PyTorch native varlen** | [`handwoven8588/CodeRankEmbed-flash-attn`](https://huggingface.co/handwoven8588/CodeRankEmbed-flash-attn) | `flash_attn` varlen baked into `modeling_hf_nomic_bert.py` (same weights β identical embeddings) | sentence-transformers / PyTorch; needs `flash_attn` + a CUDA half-precision GPU | you serve through PyTorch/ST and want full/half-precision embeddings without changing stack |
|
| 32 |
+
| **GGUF + llama.cpp** *(this repo)* | `handwoven8588/CodeRankEmbed-GGUF` | convert to GGUF; inherit llama.cpp's own ggml flash-attention kernel | llama.cpp (`llama-server`); **no** torch / `flash_attn` / triton; quantized, small | you serve through llama.cpp, want to drop `trust_remote_code`, or want a small (CPU-capable) artifact |
|
| 33 |
+
|
| 34 |
+
## Files
|
| 35 |
+
|
| 36 |
+
| File | Quant | Size | Cosine vs FP32 sentence-transformers |
|
| 37 |
+
|---|---|---|---|
|
| 38 |
+
| `CodeRankEmbed-f16.gguf` | F16 | 274 MB | 0.99999 β very high quality |
|
| 39 |
+
| `CodeRankEmbed-Q8_0.gguf` | Q8_0 | 146 MB | 0.998 β high quality |
|
| 40 |
+
|
| 41 |
+
Both are **retrieval-lossless** on our simplish delexicalized code-search benchmark (below).
|
| 42 |
+
|
| 43 |
+
## Quick start β serve as an embedder
|
| 44 |
+
|
| 45 |
+
CodeRankEmbed is **CLS-pooled** and uses a **query-only instruction prefix**. Both are serve-time settings the GGUF does not carry β you must set them:
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
llama-server -m CodeRankEmbed-Q8_0.gguf --embeddings --pooling cls -c 2048 --embd-normalize 2 -fa on -ngl 99
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
- **Pooling β `--pooling cls`** (NOT mean). nomic-embed-*text* is mean-pooled; copy-pasting its serve command silently lowers recall. This is the single most likely mistake.
|
| 52 |
+
- **Query prefix** β prepend `Represent this query for searching relevant code: ` to **queries only**, never to documents/code. Do it client-side; the GGUF doesn't carry the sentence-transformers prompt.
|
| 53 |
+
- **Normalization β `--embd-normalize 2`** (L2) so downstream cosine is correct.
|
| 54 |
+
- **Context / RoPE** β cap at the trained length (`-c 2048`); the unusual `rope.freq_base = 1000` is baked in and must not be overridden.
|
| 55 |
+
- **Flash attention β `-fa on`** (or `-fa auto` on GPU) is what cuts peak VRAM ~5.8Γ (see below). On a CPU-only backend the fused kernel falls back and the win evaporates β but it still runs.
|
| 56 |
+
|
| 57 |
+
## Quality β retrieval-lossless, not just high cosine
|
| 58 |
+
|
| 59 |
+
Cosine β 0.998 is necessary but not sufficient: it does not prove *ranking* is preserved. We validated on a **delexicalized** code-retrieval benchmark β Nβ1170 graded queries with the lexical overlap stripped against the deployed tokenizer, so only semantic matching can recover the gold β measuring nDCG@10 across a difficulty curve L0 (original query) β Lall (every content token paraphrased away):
|
| 60 |
+
|
| 61 |
+
| model | L0 | L1 | L3 | Lall | drop (L0βLall) |
|
| 62 |
+
|---|---|---|---|---|---|
|
| 63 |
+
| BM25 (deployed tokenizer) | 0.608 | 0.512 | 0.462 | 0.456 | 0.152 |
|
| 64 |
+
| FP32 (sentence-transformers, reference) | 0.954 | 0.944 | 0.920 | 0.916 | 0.038 |
|
| 65 |
+
| **GGUF f16** | 0.954 | 0.944 | 0.921 | 0.916 | 0.037 |
|
| 66 |
+
| **GGUF Q8_0** | 0.954 | 0.943 | 0.921 | 0.916 | 0.038 |
|
| 67 |
+
|
| 68 |
+
Every difference from the FP32 reference is **β€ 0.0006 nDCG@10 at every level**, including at Lall where the lexical shortcut is entirely gone. The degradation **slope** β the quantity that would expose a real loss of code understanding β is flat: FP32 0.0379, f16 0.0374, Q8_0 0.0377 (Ξslope β0.0002). Quantizing to eight bits costs **no** retrieval quality on the queries hard enough to measure it.
|
| 69 |
+
|
| 70 |
+
## Efficiency β the GGUF flash-attention win
|
| 71 |
+
|
| 72 |
+
The full-precision model's eager attention has peak memory `O(batch Γ heads Γ seqΒ²)`. The GGUF path discards that Python entirely and runs llama.cpp's own flash-attention kernel, which engages even for this bidirectional encoder. Measured on an RTX 3090 Ti (24 GB), 16 sequences Γ 2048-token context:
|
| 73 |
+
|
| 74 |
+
| | peak VRAM |
|
| 75 |
+
|---|---|
|
| 76 |
+
| `-fa off` (eager) | 11.9 GB |
|
| 77 |
+
| `-fa on` | 2.0 GB (**~5.8Γ less**) |
|
| 78 |
+
|
| 79 |
+
The same corpus that OOMs the FP32 reference at batch 64 embeds end-to-end in seconds on the GGUF.
|
| 80 |
+
|
| 81 |
+
## Quant choice & roadmap
|
| 82 |
+
|
| 83 |
+
We ship **f16** and **Q8_0**; both are retrieval-lossless above. No importance matrix (imatrix) is attached: `llama.cpp` consumes an imatrix only at β€ Q6_K and ignores it at Q8_0 and above, so a "dynamic" Q8 and a uniform Q8 are byte-identical β there is no per-tensor lever to pull at eight bits.
|
| 84 |
+
|
| 85 |
+
A lower-bit **dynamic Q4/Q3** (imatrix-driven, where the lever *does* exist) is a sensible next step for this encoder and is **not yet measured** β we expect to add and validate it here later. No claim is made about sub-Q8 quality for this model in the meantime.
|
| 86 |
+
|
| 87 |
+
## Build provenance
|
| 88 |
+
|
| 89 |
+
Built from the original FP32 `nomic-ai/CodeRankEmbed` safetensors with a current-master `llama.cpp` (`convert_hf_to_gguf.py` β `llama-quantize`), June 2026. Every metadata field above was checked against the source; cosine parity was proven against the FP32 sentence-transformers model, and the Q8_0 matches the community `awhiteside/CodeRankEmbed-Q8_0-GGUF` artifact to 1.000000.
|
| 90 |
+
|
| 91 |
+
**One converter fix was required.** Dense (non-MoE) NomicBERT models trip a bug in the converter's BERT path: `NomicBertModel.modify_tensors` reads MoE expert hparams unconditionally, which a dense model doesn't have.
|
| 92 |
+
|
| 93 |
+
```diff
|
| 94 |
+
# conversion/bert.py
|
| 95 |
+
- n_experts = self.find_hparam(["num_local_experts", "num_experts"])
|
| 96 |
+
+ n_experts = self.find_hparam(["num_local_experts", "num_experts"]) if self.is_moe else 0
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
(This likely explains why pre-made CodeRankEmbed GGUFs exist at all β whoever built them hit and worked around the same thing.)
|
| 100 |
+
|
| 101 |
+
## License & citation
|
| 102 |
+
|
| 103 |
+
**MIT**, inherited from [`nomic-ai/CodeRankEmbed`](https://huggingface.co/nomic-ai/CodeRankEmbed). MIT requires attribution β retaining the license/notice, satisfied by the credit here β **not** citation. The CodeRankEmbed authors (the CoRNStack team) additionally *request* citation; please cite their work:
|
| 104 |
+
|
| 105 |
+
```bibtex
|
| 106 |
+
@misc{suresh2025cornstackhighqualitycontrastivedata,
|
| 107 |
+
title={CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking},
|
| 108 |
+
author={Tarun Suresh and Revanth Gangi Reddy and Yifei Xu and Zach Nussbaum and Andriy Mulyar and Brandon Duderstadt and Heng Ji},
|
| 109 |
+
year={2025},
|
| 110 |
+
eprint={2412.01007},
|
| 111 |
+
archivePrefix={arXiv},
|
| 112 |
+
primaryClass={cs.CL},
|
| 113 |
+
url={https://arxiv.org/abs/2412.01007},
|
| 114 |
+
}
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## Related
|
| 118 |
+
|
| 119 |
+
- **Base model:** [`nomic-ai/CodeRankEmbed`](https://huggingface.co/nomic-ai/CodeRankEmbed)
|
| 120 |
+
- **The other flash-attention path** (PyTorch, native `flash_attn` varlen): [`handwoven8588/CodeRankEmbed-flash-attn`](https://huggingface.co/handwoven8588/CodeRankEmbed-flash-attn)
|