Feature Extraction
Transformers
ONNX
nomic_bert
quantized
int8
code-search
embedding
nomic-bert
text-embeddings-inference
Instructions to use mrsladoje/CodeRankEmbed-onnx-int8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mrsladoje/CodeRankEmbed-onnx-int8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="mrsladoje/CodeRankEmbed-onnx-int8")# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("mrsladoje/CodeRankEmbed-onnx-int8") model = AutoModel.from_pretrained("mrsladoje/CodeRankEmbed-onnx-int8") - Notebooks
- Google Colab
- Kaggle
docs: update README with reduce_range=True rationale and Zen 3 fix
Browse files
README.md
CHANGED
|
@@ -1,124 +1,115 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
-
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
-
|
| 13 |
-
|
| 14 |
-
--
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
The ~2Γ CPU speedup is real compute acceleration (not just faster file loading), coming from ONNX Runtime's `MatMulIntegerToFloat` fused kernels operating on INT8 weights. VNNI-capable CPUs (Intel 10th gen+, AMD Zen4+) may see even larger gains.
|
| 117 |
-
|
| 118 |
-
## Attribution
|
| 119 |
-
|
| 120 |
-
- **Original model:** [nomic-ai/CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed) β MIT License
|
| 121 |
-
- **ONNX conversion:** [jalipalo/CodeRankEmbed-onnx](https://huggingface.co/jalipalo/CodeRankEmbed-onnx) β MIT License (inherited)
|
| 122 |
-
- **INT8 quantization:** this repository β MIT License
|
| 123 |
-
|
| 124 |
-
All work in this repository respects and complies with the MIT license of the original model.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- onnx
|
| 5 |
+
- quantized
|
| 6 |
+
- int8
|
| 7 |
+
- code-search
|
| 8 |
+
- embedding
|
| 9 |
+
- nomic-bert
|
| 10 |
+
base_model: nomic-ai/CodeRankEmbed
|
| 11 |
+
license: mit
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# CodeRankEmbed-onnx-int8
|
| 15 |
+
|
| 16 |
+
INT8 quantized ONNX version of [nomic-ai/CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed)
|
| 17 |
+
for code search and embedding.
|
| 18 |
+
|
| 19 |
+
## Quantization
|
| 20 |
+
|
| 21 |
+
Dynamic INT8 quantization with **`reduce_range=True`** for cross-platform
|
| 22 |
+
correctness:
|
| 23 |
+
|
| 24 |
+
```python
|
| 25 |
+
from onnxruntime.quantization import quantize_dynamic, QuantType
|
| 26 |
+
|
| 27 |
+
quantize_dynamic(
|
| 28 |
+
model_input='CodeRankEmbed_fp32.onnx',
|
| 29 |
+
model_output='CodeRankEmbed_int8.onnx',
|
| 30 |
+
weight_type=QuantType.QInt8,
|
| 31 |
+
per_channel=True,
|
| 32 |
+
reduce_range=True, # clamp weights to [-64, 63] for AVX2 kernel safety
|
| 33 |
+
)
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
### Why `reduce_range=True`
|
| 37 |
+
|
| 38 |
+
ORT's CPU INT8 MatMul kernels have two paths on x86:
|
| 39 |
+
|
| 40 |
+
| CPU | Path | Full-range INT8 weights |
|
| 41 |
+
|---|---|---|
|
| 42 |
+
| Intel Cascade Lake+ / Ice Lake+ (VNNI) | `VPDPBUSD` | β correct |
|
| 43 |
+
| AMD Zen 4+ (VNNI / Genoa+) | `VPDPBUSD` | β correct |
|
| 44 |
+
| Apple Silicon (arm64 NEON + AMX) | separate arm64 kernels | β correct |
|
| 45 |
+
| **Intel pre-2019 / AMD Zen 3 Milan (AVX2 only)** | `pmaddubsw + phaddsw + paddd` | **β int16 accumulator overflows β degenerate output** |
|
| 46 |
+
|
| 47 |
+
`reduce_range=True` clamps weights to `[-64, 63]` (7-bit signed range), giving
|
| 48 |
+
the AVX2 `int16` intermediate enough headroom to avoid overflow. VNNI and arm64
|
| 49 |
+
paths are unaffected (they handle full-range INT8 natively).
|
| 50 |
+
|
| 51 |
+
### Known issue with earlier quantization
|
| 52 |
+
|
| 53 |
+
A previous version of this model was quantized **without** `reduce_range=True`.
|
| 54 |
+
It worked correctly on VNNI-capable CPUs and Apple Silicon, but produced
|
| 55 |
+
degenerate embeddings (all texts mapping to near-identical vectors) on
|
| 56 |
+
**AMD Zen 3 EPYC** and similar pre-VNNI x86 hosts β verified on RunPod
|
| 57 |
+
RTX 5090 pods with EPYC 7543. This version fixes that. See commit history.
|
| 58 |
+
|
| 59 |
+
## Performance
|
| 60 |
+
|
| 61 |
+
- **Size**: 139 MB (FP32 source: 548 MB) β **~75% reduction**
|
| 62 |
+
- **Output dim**: 768
|
| 63 |
+
- **Expected cosine vs FP32**: β₯ 0.96 on production inputs
|
| 64 |
+
- **Inference speedup (VNNI CPUs)**: ~2Γ vs FP32
|
| 65 |
+
- **Inference speedup (pre-VNNI CPUs)**: ~1.5Γ vs FP32 (smaller win, but correct)
|
| 66 |
+
|
| 67 |
+
### Validation (Mac M3 Max, ORT 1.24.3, 4-text probe)
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
T0 "how to parse json in python" T3 "parse json data python" cos=0.7749 (similar)
|
| 71 |
+
T0 "how to parse json in python" T2 "sql inner join three tables" cos=0.1123 (dissimilar)
|
| 72 |
+
Semantic separation 0.6626 (β₯ 0.15 healthy)
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## Usage
|
| 76 |
+
|
| 77 |
+
```python
|
| 78 |
+
import onnxruntime as ort
|
| 79 |
+
from transformers import AutoTokenizer
|
| 80 |
+
|
| 81 |
+
tokenizer = AutoTokenizer.from_pretrained("mrsladoje/CodeRankEmbed-onnx-int8")
|
| 82 |
+
session = ort.InferenceSession("model.onnx")
|
| 83 |
+
|
| 84 |
+
inputs = tokenizer(
|
| 85 |
+
"your code or query here",
|
| 86 |
+
padding=True, truncation=True, max_length=512, return_tensors="np"
|
| 87 |
+
)
|
| 88 |
+
outputs = session.run(None, dict(inputs))
|
| 89 |
+
# sentence_embedding is typically the second output; it's 768-dim L2-normalized
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
## Files
|
| 93 |
+
|
| 94 |
+
- `onnx/model.onnx` β INT8 quantized model (139 MB)
|
| 95 |
+
- `tokenizer.json`, `vocab.txt`, `config.json`, `special_tokens_map.json`, `tokenizer_config.json`
|
| 96 |
+
β from the base nomic-ai/CodeRankEmbed distribution
|
| 97 |
+
|
| 98 |
+
## SHA256 (v2 β with `reduce_range=True`)
|
| 99 |
+
|
| 100 |
+
```
|
| 101 |
+
4eae31d09b1843103a1ebd5e2b2e24b5a5cad441a33906b35b12b1e2ed91d1db
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
Pin this in your downloader to guarantee you got the corrected weights and not
|
| 105 |
+
a stale cached copy of v1.
|
| 106 |
+
|
| 107 |
+
## Base model
|
| 108 |
+
|
| 109 |
+
[nomic-ai/CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed) (137M params),
|
| 110 |
+
based on [Snowflake/snowflake-arctic-embed-m-long](https://huggingface.co/Snowflake/snowflake-arctic-embed-m-long).
|
| 111 |
+
ONNX conversion derived from [jalipalo/CodeRankEmbed-onnx](https://huggingface.co/jalipalo/CodeRankEmbed-onnx).
|
| 112 |
+
|
| 113 |
+
## License
|
| 114 |
+
|
| 115 |
+
MIT (inherited from base model).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|