Views
No views yet
BAAI/bge-m3 for dense embedding inference with
OpenVINO. NNCF settings: INT4_ASYM, group size 64, ratio 1.0, scale estimation
disabled. NNCF retained protected backup layers as INT8 ASYM.1import numpy as np
2import openvino as ov
3from huggingface_hub import snapshot_download
4from transformers import AutoTokenizer
5
6repo_id = "YOUR_USERNAME/bge-m3-int4-asym-g64-openvino"
7path = snapshot_download(repo_id)
8tokenizer = AutoTokenizer.from_pretrained(path)
9compiled = ov.Core().compile_model(
10 f"{path}/openvino/openvino_model.xml",
11 "GPU", # use "CPU" when needed
12)
13
14tokens = tokenizer(
15 ["xin chào, đây là phép thử"],
16 padding=True,
17 truncation=True,
18 max_length=8192,
19 return_tensors="np",
20)
21embedding = np.asarray(
22 compiled({
23 "input_ids": tokens["input_ids"],
24 "attention_mask": tokens["attention_mask"],
25 })[compiled.output("sentence_embedding")],
26 dtype=np.float32,
27)
28embedding /= np.maximum(np.linalg.norm(embedding, axis=1, keepdims=True), 1e-12)
29print(embedding.shape) # (1, 1024)sentence_embedding output. It does not expose
BGE-M3 sparse or ColBERT retrieval modes. The original model is MIT licensed; see
the BAAI/bge-m3 model card for attribution and citation.