bge-reranker-v2-m3-burnpack
Original model: https://huggingface.co/BAAI/bge-reranker-v2-m3
Original authors: the BAAI / FlagEmbedding team (Chen et al., 2024), built on the
multilingual BAAI/bge-m3 backbone (XLM-RoBERTa large)
ONNX export used: https://huggingface.co/onnx-community/bge-reranker-v2-m3-ONNX
(fp32 onnx/model.onnx + onnx/model.onnx_data, produced by the
onnx-community/convert-to-onnx space β the BAAI repository ships no ONNX)
Converted by: Lucie666, using burn-onnx β format only
This is not an original model, and no part of it is my work. It is a mechanical format conversion of BAAI/bge-reranker-v2-m3 β nothing was trained, fine-tuned, distilled, quantised or modified. No new weights were produced. All credit belongs to the authors above.
If you are looking for the model itself, go to BAAI/bge-reranker-v2-m3. This repository only exists so people running Burn don't each redo the conversion.
Note on metadata: Hugging Face's
base_model_relationfield only acceptsadapter,merge,quantizedorfinetune. None describes a pure format conversion, so the field is deliberately left unset rather than filled with an inaccurate value β these weights are not quantised, they are the original f32 values.
The file model.bpk holds the same weights as the upstream ONNX export, re-serialised
into Burn's burnpack format so they can be loaded by a pure-Rust inference stack β no
Python, no PyTorch, no ONNX Runtime at inference time.
Why this exists
bge-reranker-v2-m3 is the strongest openly licensed multilingual cross-encoder of its
generation (about 100 languages, long inputs). At 2.2 GB and 24 layers it is a server
model; in rag3weaver it is the
quality-first reranker behind SearchOptions.rerank, next to the 470 MB
mmarco-mMiniLMv2-L12-H384-v1 (multilingual default) and the 90 MB
ms-marco-MiniLM-L-6-v2 (English, browser).
Provenance
BAAI/bge-reranker-v2-m3 model.safetensors
β
β onnx-community/convert-to-onnx (PyTorch 2.8 export β onnx/model.onnx + model.onnx_data, 2 271 088 656 bytes)
βΌ
β burn-onnx 0.22.0-pre.1 (mechanical ONNX β Burn conversion, LoadStrategy::Bytes)
βΌ
model.bpk weights, burnpack format
model.rs model graph, generated Rust source (not distributed here)
Nothing in this pipeline is hand-written. config.json and tokenizer.json used at
conversion and at runtime are the ones from the BAAI repository (the onnx-community copy
only differs by _name_or_path and the transformers version).
A caveat before you regenerate. Burnpack serialisation is not byte-deterministic: two builds from the same ONNX produce files of identical size but different bytes. The tensor values are unaffected. The checksum below verifies this download, not a reproduction.
Reproducing it
// build.rs
use burn_onnx::{ModelGen, LoadStrategy};
fn main() {
ModelGen::new()
.input("onnx/model.onnx") // model.onnx_data must sit next to it
.out_dir("model/")
.load_strategy(LoadStrategy::Bytes)
.run_from_script();
}
The weights exceed the 2 GB ONNX protobuf limit and live in external data; burn-onnx
β₯ 0.22.0-pre.1 reads them without any setting (0.21 panics). The generated graph uses
burn::nn::LinearLayout::Col for the classification head, which exists from
burn 0.22.0-pre.2 β generated code and runtime must match versions. Conversion took
28 s wall and 2.4 GB of RAM; loading the model for inference takes about 6.7 GB.
Verifying the download
sha256 3ed858274ab4661332058318c8b961f0ac822af4aed899187557745107fb32e3
size 2271128324 bytes (2.12 GiB)
Model interface
pub fn forward(
&self,
input_ids: Tensor<2, Int>,
attention_mask: Tensor<2, Int>,
) -> Tensor<2> // logits [B, 1]
The graph is the full XLMRobertaForSequenceClassification: <s> token β dense
(Linear(1024β1024) + tanh) β out_proj Linear(1024β1). The output is the raw
logit: higher means more relevant; apply a sigmoid yourself if you want a probability.
Only the order is meaningful.
Tokenisation is not included: use the upstream tokenizer.json from
BAAI/bge-reranker-v2-m3 (SentencePiece Unigram, 250 002 entries; <s> = 0,
<pad> = 1, </s> = 2). It shares its vocabulary with bge-m3 but not its
normalizer (a trailing-whitespace strip), so do not substitute one for the other. There
are no token_type_ids: a (query, passage) pair is one sequence
<s> query </s></s> passage </s>, padded with id 1. The model accepts up to 8192
positions; rerankers are normally run at 512.
Numerical parity
Checked against a reference candle implementation (XLM-RoBERTa backbone from
candle-transformers + the upstream classification head β classifier.dense
(tanh) and classifier.out_proj β loaded from model.safetensors, CPU) on seven
(query, passage) pairs: the Berlin example of the MS MARCO model card in English, the
same triple in French, and a cross-language pair (French query, English passage):
pair burn (wgpu) candle (CPU) |Ξ|
------------------------------------------------------------------------------------------------
EN berlin population / 3.5 million inhabitants 6.798565 6.798559 5.7e-06
EN berlin population / Metropolitan Museum of Art -11.028526 -11.028533 6.7e-06
EN berlin population / Berlin Wall fell in 1989 -9.748907 -9.748901 5.7e-06
FR combien β¦ berlin / 3,5 millions d'habitants 6.165921 6.165920 4.8e-07
FR combien β¦ berlin / Metropolitan Museum of Art -11.032015 -11.032012 2.9e-06
FR combien β¦ berlin / mur de Berlin tombΓ© en 1989 -10.509789 -10.509794 5.7e-06
FR query / EN "3.5 million inhabitants" passage 5.617373 5.617373 9.5e-07
max |Ξ| = 6.7e-6 on raw logits, rankings identical in both languages and across languages. The residual is f32 accumulation noise from a different operation order.
Runtime backend for this check: Burn + wgpu/Vulkan on an AMD Radeon AI PRO R9700 (Navi 48, RDNA4, gfx1201) via RADV.
License
Apache-2.0, inherited from BAAI/bge-reranker-v2-m3. All credit for the model belongs to its authors:
@misc{li2023making,
title={Making Large Language Models A Better Foundation For Dense Retrieval},
author={Chaofan Li and Zheng Liu and Shitao Xiao and Yingxia Shao},
year={2023},
eprint={2312.15503},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@misc{chen2024bge,
title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation},
author={Jianlv Chen and Shitao Xiao and Peitian Zhang and Kun Luo and Defu Lian and Zheng Liu},
year={2024},
eprint={2402.03216},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Model tree for Lucie666/bge-reranker-v2-m3-burnpack
Base model
BAAI/bge-reranker-v2-m3