Downloads · 30 days
16
26% of all-time downloads
monju-lab/modernbert-ja-130m-int8-onnx
modernbert-ja-130m-int8-onnx is a feature extraction model from monju-lab. Use it when you need embeddings to search or compare text. It is set up for transformers. The card lists the license as mit.
ONNX export of sbintuitions/modernbert-ja-130m (132.5M params, 19 layers, RoPE, local+global attention), converted for the feature-extraction task so it outputs lasthiddenstate for building sentence embeddings via mea…
Downloads · 30 days
16
26% of all-time downloads
All-time downloads
62
Public
Repo size
135 MB
Likes
0
Public
Click a slice to open those files.
.onnx133 MB · 94%
From the Hugging Face model README
ONNX export of sbintuitions/modernbert-ja-130m (132.5M params, 19 layers, RoPE, local+global attention), converted for the feature-extraction task so it outputs last_hidden_state for building sentence embeddings via mean pooling.
Two variants are provided in onnx/:
| File | Precision | Size | Use case |
|---|---|---|---|
onnx/model.onnx | fp32 | 505 MB | Reference / highest fidelity |
onnx/model_quantized.onnx | int8 (dynamic) | 127 MB (~4x smaller) | Recommended for CPU serving |
Measured on a CPU-only sandbox (onnxruntime CPUExecutionProvider), single-sequence inference, over a 20-sentence Japanese set covering paraphrase pairs, related pairs, and unrelated pairs. Quality is reported two ways against the original PyTorch fp32 model: mean cosine similarity of individual embeddings, and Spearman rank correlation of the full pairwise similarity matrix (i.e. does the variant preserve which sentences rank as more/less similar — what actually matters for a sentence-similarity use case).
| Variant | Latency (mean, batch=1) | vs. PyTorch | File size | Cosine sim to original | Similarity-ranking correlation (Spearman ρ) |
|---|---|---|---|---|---|
| PyTorch fp32 (original) | 58.4 ms | 1.0x | 505 MB (safetensors) | 1.0000 | 1.0000 |
| ONNX fp32 | 24.4 ms | 2.4x faster | 505 MB | 1.0000 | 1.0000 |
| ONNX int8 (dynamic) | 11.0 ms | 5.3x faster | 127 MB (4x smaller) | 0.9903 (min 0.9788) | 0.9333 |
Takeaways:
onnx/model.onnx) is a free win: 2.4x lower latency with zero quality loss (cosine similarity 1.0000 against the original PyTorch outputs). Use this when fidelity matters most and storage isn't the constraint.onnx/model_quantized.onnx) adds a further 2.2x latency reduction on top of ONNX fp32 (5.3x vs. the original PyTorch model) and cuts file size ~4x, at the cost of some embedding precision (mean cosine similarity 0.990, ranking correlation 0.933 rather than a perfect 1.0). In our test this did not flip the relative order of clearly-similar vs. clearly-dissimilar sentence pairs, but the ranking correlation is noticeably below the fp32 variants, so it's worth validating against your own similarity/retrieval eval set before relying on it for fine-grained ranking.onnxruntime/PyTorch are numerically less mature. It isn't included here — happy to add onnx/model_fp16.onnx if you plan to serve on GPU.Recommendation: use onnx/model_quantized.onnx if you need the smallest footprint and fastest CPU inference and can tolerate ~1-2% embedding drift; use onnx/model.onnx if you want the latency win from ONNX with no measurable quality change.
onnxruntime directlyimport numpy as np
import onnxruntime as ort
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("<this-repo>")
session = ort.InferenceSession("onnx/model_quantized.onnx", providers=["CPUExecutionProvider"])
def embed(sentences):
enc = tokenizer(sentences, padding=True, return_tensors="np")
last_hidden_state, = session.run(
None, {"input_ids": enc["input_ids"], "attention_mask": enc["attention_mask"]}
)
mask = enc["attention_mask"][..., None].astype(np.float32)
summed = (last_hidden_state.astype(np.float32) * mask).sum(axis=1)
counts = np.clip(mask.sum(axis=1), 1e-9, None)
return summed / counts # mean-pooled sentence embeddings
embs = embed(["今日はいい天気ですね。", "本日は晴れて気持ちがいいです。"])
cos_sim = (embs[0] @ embs[1]) / (np.linalg.norm(embs[0]) * np.linalg.norm(embs[1]))
print(cos_sim)
optimumfrom optimum.onnxruntime import ORTModelForFeatureExtraction
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("<this-repo>")
model = ORTModelForFeatureExtraction.from_pretrained("<this-repo>", file_name="onnx/model_quantized.onnx")
optimum (optimum.exporters.onnx), task feature-extraction, opset 18.onnxruntime.quantization.quantize_dynamic (QInt8 weights).last_hidden_state using the attention mask, as shown above. The base model has no officially recommended pooling strategy since it's released as a masked-language-model checkpoint rather than a tuned sentence-embedding model; mean pooling is the standard default for this class of encoder.Base model card, license (MIT), and full training details: sbintuitions/modernbert-ja-130m.