bge-m3-burnpack
Original model: https://huggingface.co/BAAI/bge-m3
Original authors: Jianlv Chen, Shitao Xiao, Peitian Zhang, Kun Luo, Defu Lian, Zheng Liu (BAAI)
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-m3 β nothing was trained, fine-tuned, distilled, quantised or modified. No new weights were produced. All credit, and all research merit, belongs to the BAAI authors listed above.
If you are looking for the model itself, go to BAAI/bge-m3. This repository only exists to save a 2.2 GB conversion step for people running Burn.
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 model, re-serialized into
Burn's burnpack format so they can be loaded by a pure-Rust
inference stack.
Why this exists
BAAI/bge-m3 ships PyTorch weights and an ONNX export. Neither can be loaded directly by
Burn. Running BGE-M3 in a Rust-only stack β no Python, no PyTorch, no ONNX Runtime at
inference time β requires the weights in Burn's own format.
This repository is that artifact, so downstream users don't each have to redo a 2.2 GB conversion.
Provenance
BAAI/bge-m3 onnx/model.onnx + onnx/model.onnx_data
β
β burn-onnx 0.22.0-pre.1 (mechanical ONNX β Burn conversion)
βΌ
model.bpk weights, burnpack format
model.rs model graph, generated Rust source (not distributed here)
Nothing in this pipeline is hand-written.
A caveat worth knowing before you regenerate. Burnpack serialisation is not byte-deterministic: two builds from the same ONNX, with the same settings, produce files of identical size but different bytes. The tensor values are unaffected β a regenerated model gives numerically identical outputs (verified: same max|Ξ| to the digit against the same reference).
So the checksum below verifies this download, not a reproduction. If you regenerate, expect a different hash and a model that behaves the same. This is also why a canonical published copy is useful: you cannot rebuild a bit-identical one.
Reproducing it
// build.rs
use burn_onnx::{ModelGen, LoadStrategy};
fn main() {
ModelGen::new()
.input("onnx/model.onnx") // from BAAI/bge-m3, with model.onnx_data alongside
.out_dir("model/")
.load_strategy(LoadStrategy::Bytes)
.run_from_script();
}
Requires burn-onnx >= 0.22.0-pre.1. Version 0.21.0 cannot be used: it fails on
ONNX external-data tensors (base_path is not threaded through the zero-copy mmap path
in onnx-ir), and this model necessarily uses external data since the ONNX protobuf
format caps at 2 GB.
Verifying the download
sha256 3edce43cf80ce99a19922e430d5d2ef4e47864fff2114654968c1a3726fbac9d
size 2266989828 bytes (2.111 GiB)
Model interface
pub fn forward(
&self,
input_ids: Tensor<2, Int>,
attention_mask: Tensor<2, Int>,
) -> (Tensor<3>, Tensor<2>)
// token_embeddings [B,S,1024] sentence_embedding [B,1024]
sentence_embeddingβ dense, CLS-pooled and L2-normalised (matches upstream1_Pooling/config.json,pooling_mode_cls_token: true)token_embeddingsβ per-token hidden states, needed to compute BGE-M3's learned sparse representation (sparse_linear.ptβ ReLU β scatter by token id)
Tokenisation is not included: use the upstream tokenizer.json with <pad> = id 1.
Numerical parity
Checked against the reference candle implementation
(candle-transformers::models::xlm_roberta::XLMRobertaModel) running on CPU, over a fixed
sentence set:
sentence cosine max|Ξ| mean|Ξ|
---------------------------------------------
[0] 1.00000000 3.10e-07 6.77e-08
[1] 1.00000000 3.50e-07 4.33e-08
[2] 1.00000000 2.40e-07 5.26e-08
The residual is f32 accumulation noise across 24 layers from a different operation order β not a divergence.
Runtime backend for this check: Burn + wgpu/Vulkan on an AMD Radeon AI PRO R9700 (Navi 48, RDNA4, gfx1201) via RADV.
License
MIT, inherited from BAAI/bge-m3. All credit for the model belongs to its authors:
@misc{bge-m3,
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}
}
Model tree for Lucie666/bge-m3-burnpack
Base model
BAAI/bge-m3