Model card: R2 (gte-modernbert distill) + reranker section
Browse files
README.md
CHANGED
|
@@ -13,7 +13,7 @@ tags:
|
|
| 13 |
- knowledge-distillation
|
| 14 |
pipeline_tag: feature-extraction
|
| 15 |
base_model:
|
| 16 |
-
-
|
| 17 |
datasets:
|
| 18 |
- Fsoft-AIC/the-vault-function
|
| 19 |
- unicamp-dl/mmarco
|
|
@@ -24,54 +24,59 @@ datasets:
|
|
| 24 |
|
| 25 |
# code-daemon-embed-v1
|
| 26 |
|
| 27 |
-
A small, fast **code
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
It is **
|
| 32 |
-
|
| 33 |
-
are short (entity names, signatures, doc-chunks); spending capacity and latency on a long-context path
|
| 34 |
-
would only slow the hot path it never uses.
|
| 35 |
|
| 36 |
-
- **768-dim** embeddings, **Matryoshka (MRL)** truncatable to **512 / 256** with graceful decay.
|
| 37 |
-
- **~54.5M params** β XLM-RoBERTa architecture, **4 layers / 768 hidden**, **code-
|
| 38 |
-
- **Mean pooling
|
| 39 |
-
- Trained at sequence length **128**
|
| 40 |
|
| 41 |
-
##
|
| 42 |
|
| 43 |
-
|
| 44 |
-
(MIT, 137M, a strong code retriever). The student is a fresh, shallow-wide XLM-R encoder trained
|
| 45 |
-
from scratch on the teacher's passage embeddings over a ~32M-sample code + text corpus, with a
|
| 46 |
-
custom 32k code-oriented SentencePiece vocabulary (syntax + identifier lexicon rather than prose).
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
(entity names, signatures, doc-chunks), so the model and its engines are tuned only for that, avoiding
|
| 58 |
-
the cost of a wide dynamic shape range.
|
| 59 |
-
- **Rectangular TensorRT profiles** β each length bucket is built with a *fixed* shape (min == opt == max),
|
| 60 |
-
not a dynamic range, so the autotuner locks one optimal kernel set per bucket:
|
| 61 |
-
**s** = batch 64 Γ seq 40 Β· **m** = batch 128 Γ seq 64 Β· **l** = batch 256 Γ seq 128.
|
| 62 |
-
- **INT8 (W8A16)** weights; **mean-pool + projection + L2-norm fused into the graph** (one pass β `[B, 768]`).
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
- Embed **queries and documents the same way** (no instruction prefix β the student was distilled on
|
| 68 |
-
passage embeddings, unlike the teacher whose prefix is query-only). Mean-pool β **L2-normalize**.
|
| 69 |
-
- For smaller indexes, truncate to **256** or **512** dims (MRL) before normalizing.
|
| 70 |
|
| 71 |
-
The
|
| 72 |
-
|
| 73 |
-
bundled `sentencepiece.bpe.model`, run, and the pooled `[B,768]` is already produced β just
|
| 74 |
-
L2-normalize:
|
| 75 |
|
| 76 |
```python
|
| 77 |
import onnxruntime as ort, sentencepiece as spm, numpy as np
|
|
@@ -91,71 +96,67 @@ def embed(texts, max_len=128, mrl_dim=768):
|
|
| 91 |
|
| 92 |
## What's in this repo β ready-to-run compiled engines
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
hardware and use it directly, with no compilation on your machine.
|
| 97 |
|
| 98 |
-
- **TensorRT** `*.engine` β NVIDIA, INT8 W8A16
|
| 99 |
`code-daemon-embed-v1-{s,m,l}_{win_x64,linux_x64}_trt_sm_{86,89,120}.engine`
|
| 100 |
(sm_86 β RTX 30xx / A-series Β· sm_89 β RTX 40xx / L4 Β· sm_120 β RTX 50xx).
|
| 101 |
- **TVM** `*_tvm_vulkan.{dll,so}` β Vulkan fallback for non-TRT / older NVIDIA & other GPUs, per bucket.
|
| 102 |
- **OpenVINO** `*.xml` + `*.bin` β Intel **CPU / iGPU / NPU**, per bucket.
|
| 103 |
- **Metal** `*_tvm_metal.*` β Apple Silicon (macOS), per bucket.
|
| 104 |
-
- **Tokenizer** β `sentencepiece.bpe.model` (
|
| 105 |
-
|
| 106 |
-
- **ONNX source** β `model.onnx` (+ `model.onnx.data`) FP32 and `model_int8qdt.onnx` (INT8 W8A16)
|
| 107 |
-
standalone `onnxruntime` / optimum use, and the source the engines are compiled from.
|
| 108 |
|
| 109 |
-
## Evaluation β
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
model is actually built for (NDCG@10, full corpora):
|
| 115 |
|
| 116 |
-
| CoIR task
|
| 117 |
|---|--:|---|
|
| 118 |
-
| codesearchnet (6-lang avg) | **
|
| 119 |
-
| stackoverflow-qa |
|
| 120 |
-
| synthetic-text2sql |
|
| 121 |
-
|
|
| 122 |
-
|
|
| 123 |
-
| cosqa |
|
| 124 |
-
| **
|
| 125 |
|
| 126 |
-
|
|
|
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
## Performance (embeddings / sec)
|
| 136 |
|
| 137 |
| Backend | Hardware | Throughput |
|
| 138 |
|---|---|--:|
|
| 139 |
-
| TensorRT INT8 | NVIDIA RTX 5060 (sm_120) | **~
|
| 140 |
| OpenVINO INT4 | Intel iGPU (Xe2, Lunar Lake) | ~580 emb/s |
|
| 141 |
| OpenVINO INT4 | Intel NPU (NPU4) | ~574 emb/s |
|
| 142 |
| OpenVINO INT8 | Intel CPU (Core Ultra) | ~375 emb/s |
|
| 143 |
| OpenVINO β **all 3 in parallel** | iGPU + NPU + CPU concurrently | ~1,290 emb/s |
|
| 144 |
|
| 145 |
-
The combined figure is
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
across all three devices. TRT is infer throughput on the bucketed batch path; OV figures measured on a
|
| 150 |
-
Core Ultra (Lunar Lake) laptop.
|
| 151 |
|
| 152 |
## License & training data
|
| 153 |
|
| 154 |
Released under the **MIT license**.
|
| 155 |
|
| 156 |
-
The teacher (`
|
| 157 |
-
practice for distilled embedding models, the **weights are released under MIT**. For
|
| 158 |
-
the training corpus the teacher embedded includes:
|
| 159 |
|
| 160 |
| Dataset | License note |
|
| 161 |
|---|---|
|
|
@@ -166,10 +167,9 @@ the training corpus the teacher embedded includes:
|
|
| 166 |
| `jinaai/negation-dataset` | see source repo |
|
| 167 |
|
| 168 |
β οΈ If your use requires strict training-data-license compliance, note that **mMARCO derives from
|
| 169 |
-
MS MARCO (non-commercial)**. Whether a distilled model inherits dataset-use terms is legally
|
| 170 |
-
|
| 171 |
-
splits if needed.
|
| 172 |
|
| 173 |
## Attribution
|
| 174 |
|
| 175 |
-
Distilled from **[
|
|
|
|
| 13 |
- knowledge-distillation
|
| 14 |
pipeline_tag: feature-extraction
|
| 15 |
base_model:
|
| 16 |
+
- Alibaba-NLP/gte-modernbert-base
|
| 17 |
datasets:
|
| 18 |
- Fsoft-AIC/the-vault-function
|
| 19 |
- unicamp-dl/mmarco
|
|
|
|
| 24 |
|
| 25 |
# code-daemon-embed-v1
|
| 26 |
|
| 27 |
+
A small, fast **code-embedding model** for semantic code search and code retrieval. It maps short code
|
| 28 |
+
units β function and method bodies, signatures, docstrings β and short natural-language queries into a
|
| 29 |
+
shared **768-dim** vector space.
|
| 30 |
|
| 31 |
+
It is **specialized for short code, not long documents**: the maximum sequence is **128 tokens**,
|
| 32 |
+
trading long-context capability for high throughput and strong quality on short units.
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
- **768-dim** embeddings, **Matryoshka (MRL)** β truncatable to **512 / 256** dims with graceful decay.
|
| 35 |
+
- **~54.5M params** β XLM-RoBERTa architecture, **4 layers / 768 hidden**, a **code-oriented 32k SentencePiece vocab**.
|
| 36 |
+
- **Mean pooling fused into the graph** β the output is already pooled (`[batch, 768]`); just **L2-normalize**.
|
| 37 |
+
- Trained at sequence length **128** (length buckets s / m / l = seq **40 / 64 / 128**).
|
| 38 |
|
| 39 |
+
## Where it's good β and where it isn't
|
| 40 |
|
| 41 |
+
Measured on CoIR (NDCG@10, full corpora). Use it for:
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
**Strong:**
|
| 44 |
+
- **Code β related code** β finding similar or duplicate implementations (its best relative area).
|
| 45 |
+
- **Natural-language β code** β docstring or description β function (strongest on Python).
|
| 46 |
+
- **Short question β code** β "how / where does Xβ¦".
|
| 47 |
+
- **NL β SQL** and **NL instruction β code**.
|
| 48 |
|
| 49 |
+
**Weak / out of scope:**
|
| 50 |
+
- **Long documents** β hard 128-token cap; longer inputs are truncated. This is not a long-context retriever.
|
| 51 |
+
- **Noisy / ambiguous NLβcode** (hard, under-specified queries) β mid quality.
|
| 52 |
+
- **General English prose** (medical / financial / news) β the code-specialized 32k vocab trades
|
| 53 |
+
general-text coverage for code. Multilingual text works as a fallback, not a specialty.
|
| 54 |
|
| 55 |
+
Embed **queries and documents the same way** β no instruction prefix. For smaller indexes, truncate to
|
| 56 |
+
**256** or **512** dims (MRL) before normalizing.
|
| 57 |
|
| 58 |
+
## How it was made
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
Knowledge-distilled (embedding regression) from **[`Alibaba-NLP/gte-modernbert-base`](https://huggingface.co/Alibaba-NLP/gte-modernbert-base)**
|
| 61 |
+
(Apache-2.0, ~150M, a strong general + code retriever on a ModernBERT backbone). The student is a fresh,
|
| 62 |
+
shallow-wide XLM-R encoder trained from scratch on the teacher's passage embeddings over a ~30M-sample
|
| 63 |
+
code + text corpus, with a custom 32k code-oriented SentencePiece vocabulary (syntax + identifier lexicon
|
| 64 |
+
rather than prose). The shallow-wide 4-layer / 768-hidden shape keeps inference cheap while distilling at
|
| 65 |
+
the teacher's full 768-dim width.
|
| 66 |
+
|
| 67 |
+
## Built for speed
|
| 68 |
+
|
| 69 |
+
- **Short context by design** β max **128 tokens**, no long-document path, so the engines avoid a wide
|
| 70 |
+
dynamic shape range.
|
| 71 |
+
- **Rectangular TensorRT profiles** β each length bucket is a *fixed* shape (min == opt == max), one
|
| 72 |
+
optimal kernel set per bucket: **s** = batch 64 Γ seq 40 Β· **m** = batch 128 Γ seq 64 Β·
|
| 73 |
+
**l** = batch 256 Γ seq 128.
|
| 74 |
+
- **INT8 (W8A16)** weights; **mean-pool + projection + L2-norm fused into the graph** (one pass β `[B, 768]`).
|
| 75 |
|
| 76 |
+
## Usage (standalone ONNX)
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
The FP32 `model.onnx` is bundled. Tokenize with the bundled `sentencepiece.bpe.model`, run, and the
|
| 79 |
+
pooled `[B, 768]` output is already produced β just L2-normalize:
|
|
|
|
|
|
|
| 80 |
|
| 81 |
```python
|
| 82 |
import onnxruntime as ort, sentencepiece as spm, numpy as np
|
|
|
|
| 96 |
|
| 97 |
## What's in this repo β ready-to-run compiled engines
|
| 98 |
|
| 99 |
+
Pre-compiled engines, named per **runtime Γ GPU arch Γ OS Γ length-bucket** β pick the one matching your
|
| 100 |
+
runtime and hardware; no compilation needed.
|
|
|
|
| 101 |
|
| 102 |
+
- **TensorRT** `*.engine` β NVIDIA, INT8 W8A16:
|
| 103 |
`code-daemon-embed-v1-{s,m,l}_{win_x64,linux_x64}_trt_sm_{86,89,120}.engine`
|
| 104 |
(sm_86 β RTX 30xx / A-series Β· sm_89 β RTX 40xx / L4 Β· sm_120 β RTX 50xx).
|
| 105 |
- **TVM** `*_tvm_vulkan.{dll,so}` β Vulkan fallback for non-TRT / older NVIDIA & other GPUs, per bucket.
|
| 106 |
- **OpenVINO** `*.xml` + `*.bin` β Intel **CPU / iGPU / NPU**, per bucket.
|
| 107 |
- **Metal** `*_tvm_metal.*` β Apple Silicon (macOS), per bucket.
|
| 108 |
+
- **Tokenizer** β `sentencepiece.bpe.model` (specials at pad=0 / unk=1 / bos=2 / eos=3, byte-fallback) +
|
| 109 |
+
`tokenizer_config.json`.
|
| 110 |
+
- **ONNX source** β `model.onnx` (+ `model.onnx.data`) FP32 and `model_int8qdt.onnx` (INT8 W8A16).
|
|
|
|
| 111 |
|
| 112 |
+
## Evaluation β CoIR (NDCG@10, full corpora)
|
| 113 |
|
| 114 |
+
Retrieval quality on the CoIR tasks that match this model's design (short code + retrieval). Four of
|
| 115 |
+
CoIR's ten tasks β codeβcode translation, multi-turn dialogue, long problem-statements β exceed the
|
| 116 |
+
128-token / retrieval scope and are not shown.
|
|
|
|
| 117 |
|
| 118 |
+
| CoIR task | NDCG@10 | Pattern |
|
| 119 |
|---|--:|---|
|
| 120 |
+
| codesearchnet (6-lang avg) | **73.17** | docstring / NL β code |
|
| 121 |
+
| stackoverflow-qa | 62.70 | short question β code |
|
| 122 |
+
| synthetic-text2sql | 61.32 | NL β SQL |
|
| 123 |
+
| codesearchnet-ccr (6-lang avg) | **57.30** | code β related code |
|
| 124 |
+
| codefeedback-st | 56.38 | NL instruction β code |
|
| 125 |
+
| cosqa | 35.51 | NL question β code (noisy / hard) |
|
| 126 |
+
| **Average** | **57.73** | |
|
| 127 |
|
| 128 |
+
Per language β codesearchnet (NLβcode): python **88.82**, java 75.78, php 73.71, go 73.49, ruby 64.10, js 63.09.
|
| 129 |
+
Per language β codesearchnet-ccr (codeβcode): ruby **65.67**, java 62.87, js 61.05, python 55.88, go 51.53, php 46.77.
|
| 130 |
|
| 131 |
+
**Binary (1-bit sign) vectors** retain **94.4%** of the float NDCG before any rescore β the embeddings
|
| 132 |
+
are clean by sign, so a Hamming (XOR + popcount) index over 1-bit codes gives a ~32Γ memory / search win
|
| 133 |
+
at a small quality cost.
|
| 134 |
|
| 135 |
+
> For scale, the 1.5B-parameter `bge-code-v1` scores 81.77 on full CoIR β this is a **54.5M** model
|
| 136 |
+
> (27Γ smaller) tuned for short-code retrieval.
|
| 137 |
|
| 138 |
## Performance (embeddings / sec)
|
| 139 |
|
| 140 |
| Backend | Hardware | Throughput |
|
| 141 |
|---|---|--:|
|
| 142 |
+
| TensorRT INT8 | NVIDIA RTX 5060 (sm_120) | **~24,000 emb/s** |
|
| 143 |
| OpenVINO INT4 | Intel iGPU (Xe2, Lunar Lake) | ~580 emb/s |
|
| 144 |
| OpenVINO INT4 | Intel NPU (NPU4) | ~574 emb/s |
|
| 145 |
| OpenVINO INT8 | Intel CPU (Core Ultra) | ~375 emb/s |
|
| 146 |
| OpenVINO β **all 3 in parallel** | iGPU + NPU + CPU concurrently | ~1,290 emb/s |
|
| 147 |
|
| 148 |
+
The combined OpenVINO figure is genuine concurrent multi-device execution β three workers (iGPU, NPU,
|
| 149 |
+
CPU) embed different batches at the same time and the throughputs add up. This is **not** OpenVINO's
|
| 150 |
+
`AUTO` mode (which picks a single device per inference). Measured on a Core Ultra (Lunar Lake) laptop;
|
| 151 |
+
the TensorRT figure is on the bucketed batch path.
|
|
|
|
|
|
|
| 152 |
|
| 153 |
## License & training data
|
| 154 |
|
| 155 |
Released under the **MIT license**.
|
| 156 |
|
| 157 |
+
The teacher (`Alibaba-NLP/gte-modernbert-base`) is Apache-2.0, and the XLM-R architecture is MIT. As is
|
| 158 |
+
standard practice for distilled embedding models, the **weights are released under MIT**. For
|
| 159 |
+
transparency, the training corpus the teacher embedded includes:
|
| 160 |
|
| 161 |
| Dataset | License note |
|
| 162 |
|---|---|
|
|
|
|
| 167 |
| `jinaai/negation-dataset` | see source repo |
|
| 168 |
|
| 169 |
β οΈ If your use requires strict training-data-license compliance, note that **mMARCO derives from
|
| 170 |
+
MS MARCO (non-commercial)**. Whether a distilled model inherits dataset-use terms is legally unsettled;
|
| 171 |
+
this is **not legal advice**. A data-clean variant can be retrained without the mMARCO splits if needed.
|
|
|
|
| 172 |
|
| 173 |
## Attribution
|
| 174 |
|
| 175 |
+
Distilled from **[Alibaba-NLP/gte-modernbert-base](https://huggingface.co/Alibaba-NLP/gte-modernbert-base)** (Apache-2.0). Backbone: XLM-RoBERTa (MIT).
|