Views
No views yet
| File | Format | Size | Speed vs FP32 | Cosine Similarity | Notes |
|---|---|---|---|---|---|
model_qint4.onnx | INT4 MatMulNBits + GatherBlockQuantized | 14 MB | ~2× | 0.94 | Block-wise (b=32), symmetric. Uses ONNX Runtime contrib ops. |
model_qint4_qdq.onnx | INT8 QDQ (DequantizeLinear + MatMul/Gather) | 23 MB | ~1× | 0.966 | Per-tensor uint8. Pure standard ONNX ops, no contrib. |
1import onnxruntime as ort
2from transformers import AutoTokenizer
3
4tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
5
6# INT4 (speed-first)
7session = ort.InferenceSession("model_qint4.onnx")
8
9# INT8 QDQ (accuracy-first)
10# session = ort.InferenceSession("model_qint4_qdq.onnx")
11
12tokens = tokenizer(["hello world"], return_tensors="np", padding=True, truncation=True)
13outputs = session.run(None, {
14 "input_ids": tokens["input_ids"],
15 "attention_mask": tokens["attention_mask"],
16 "token_type_ids": tokens["token_type_ids"],
17})
18embedding = outputs[1] # pooled output (1 × 384)MatMulNBitsQuantizer with block_size=32, is_symmetric=True,
accuracy_level=4, op_types_to_quantize=("MatMul", "Gather"). Produces
MatMulNBits and GatherBlockQuantized ops (contrib, opset 21).quantize_dynamic with weight_type=QuantType.QUInt8,
op_types_to_quantize=["MatMul", "Gather"]. Wraps MatMul/Gather in standard
DequantizeLinear/QuantizeLinear pairs.model.onnx in
sentence-transformers/all-MiniLM-L6-v2.1# Install dependencies
2pip install onnx onnxruntime
3
4# Download source + generate both quantized variants
5./generate.sh
6
7# Or generate and upload to Hugging Face
8# ./generate.sh --upload