faxenoff commited on
Commit
a2f1eb6
Β·
verified Β·
1 Parent(s): 79db0e8

Model card: R2 (gte-modernbert distill) + reranker section

Browse files
Files changed (1) hide show
  1. README.md +79 -79
README.md CHANGED
@@ -13,7 +13,7 @@ tags:
13
  - knowledge-distillation
14
  pipeline_tag: feature-extraction
15
  base_model:
16
- - nomic-ai/CodeRankEmbed
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 embedding model** purpose-built to vectorize a **code graph** (functions, methods,
28
- doc-chunks) for on-device semantic code search. It ships with the
29
- [UltraCode](https://github.com/faxenoff/ultracode) MCP server, running as a TensorRT / TVM / OpenVINO / ONNX engine.
30
 
31
- It is **deliberately specialized for short code units, not long documents** β€” long-text handling was
32
- intentionally dropped (max sequence **128 tokens**) to maximize embedding throughput. Code-graph nodes
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-only 32k SentencePiece vocab**.
38
- - **Mean pooling** baked into the graph β€” output is already pooled (`[batch, 768]`); just **L2-normalize**.
39
- - Trained at sequence length **128**; length buckets s/m/l = seq **40 / 64 / 128**.
40
 
41
- ## How it was made
42
 
43
- Knowledge-distilled (embedding regression) from the teacher **[`nomic-ai/CodeRankEmbed`](https://huggingface.co/nomic-ai/CodeRankEmbed)**
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
- Why shallow-wide (4l/768h) + code vocab: on an internal code-search golden set this **beat** both a
49
- deeper 6-layer variant and the earlier 64k-prose-vocab cut β€” depth hurt, a code-tuned vocab and a
50
- wide body helped.
 
 
51
 
52
- ## Built for speed
 
 
 
 
53
 
54
- This model trades long-context capability for raw throughput on short code units:
 
55
 
56
- - **Short context by design** β€” max **128 tokens**, no long-document path. Code-graph nodes are short
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
- ## Intended use
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- - **Semantic code search / code retrieval**, and general (multilingual) text retrieval as a fallback.
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 daemon runs the bundled engines directly (this repo is its CDN), but the FP32 `model.onnx` is
72
- **also bundled** for standalone use. The recipe below runs it with `onnxruntime`: tokenize with the
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
- This repo holds **pre-compiled, ready-to-run engines**, named per
95
- **runtime Γ— GPU arch Γ— OS Γ— length-bucket** β€” grab the compiled model that matches your runtime and
96
- hardware and use it directly, with no compilation on your machine.
97
 
98
- - **TensorRT** `*.engine` β€” NVIDIA, INT8 W8A16, per arch Γ— OS Γ— bucket:
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` (the model's SentencePiece; specials baked at
105
- pad=0 / unk=1 / bos=2 / eos=3, byte-fallback) + `tokenizer_config.json`. The daemon loads the SP directly.
106
- - **ONNX source** β€” `model.onnx` (+ `model.onnx.data`) FP32 and `model_int8qdt.onnx` (INT8 W8A16) β€” for
107
- standalone `onnxruntime` / optimum use, and the source the engines are compiled from.
108
 
109
- ## Evaluation β€” in-scope CoIR (sub-CoIR)
110
 
111
- CoIR is a broad code-retrieval benchmark, but **4 of its 10 tasks are out of scope** for a code-graph
112
- search engine (code↔code translation, multi-turn dialogue, long problem-statements β€” the daemon never
113
- performs these). The honest, relevant view is the **in-scope subset** β€” the retrieval patterns this
114
- model is actually built for (NDCG@10, full corpora):
115
 
116
- | CoIR task (in-scope) | NDCG@10 | Pattern |
117
  |---|--:|---|
118
- | codesearchnet (6-lang avg) | **74.64** | docstring / NL β†’ code (the core path) |
119
- | stackoverflow-qa | 53.18 | short question β†’ code |
120
- | synthetic-text2sql | 50.15 | NL β†’ SQL |
121
- | codefeedback-st | 47.71 | NL instruction β†’ code |
122
- | codesearchnet-ccr (6-lang avg) | 44.30 | code β†’ related code (clone/dup) |
123
- | cosqa | 32.14 | NL question β†’ code (noisy / hard) |
124
- | **In-scope average (sub-CoIR)** | **51.56** | |
125
 
126
- codesearchnet per language (NL→code): python **91.96**, go 82.27, java 76.02, php 68.98, ruby 65.94, js 62.66.
 
127
 
128
- > The full 10-task official CoIR average (36.67) is dragged down by the 4 out-of-scope tasks and is not
129
- > representative of the real query mix. For scale, the 1.5B-class `bge-code-v1` scores 81.77 on full
130
- > CoIR β€” this is a **54.5M** model (27Γ— smaller) tuned for one job.
131
 
132
- On the daemon's own `search-gold` golden set (its real query distribution): **hit@5 0.692** β€” +80% over
133
- the retired v1.1 cut (0.385). Binary (1-bit) vectors retain ~91% of float NDCG before rescore.
134
 
135
  ## Performance (embeddings / sec)
136
 
137
  | Backend | Hardware | Throughput |
138
  |---|---|--:|
139
- | TensorRT INT8 | NVIDIA RTX 5060 (sm_120) | **~20,000 emb/s** |
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 **genuine concurrent multi-device execution**: three independent workers β€” one
146
- bound to each of the iGPU, NPU and CPU β€” embed different batches **at the same time**, and the
147
- throughputs add up. This is **not** OpenVINO's `AUTO` mode (which selects a *single* device per
148
- inference and never runs the three simultaneously); the daemon length-sorts inputs and fans the buckets
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 (`nomic-ai/CodeRankEmbed`) is MIT, and the XLM-R architecture is MIT. As is standard
157
- practice for distilled embedding models, the **weights are released under MIT**. For transparency,
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
- unsettled; this is **not legal advice**. A data-clean variant can be retrained without the mMARCO
171
- splits if needed.
172
 
173
  ## Attribution
174
 
175
- Distilled from **[nomic-ai/CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed)** (MIT). Backbone: XLM-RoBERTa (MIT).
 
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).