1import openvino as ov
2import numpy as np
3from transformers import AutoTokenizer
45core = ov.Core()6model = core.compile_model("models/bge-m3-int8-ov/model.xml","CPU")7tokenizer = AutoTokenizer.from_pretrained("models/bge-m3-int8-ov")89text ="What is BGE M3?"10encoded = tokenizer(text, return_tensors="np", padding="max_length", truncation=True, max_length=512)11result = model({"input_ids": encoded["input_ids"].astype(np.int64),"attention_mask": encoded["attention_mask"].astype(np.int64)})12embedding = result["sentence_embedding"]# shape: [1, 1024]
NPU compatibility
OpenVINO IR supports dynamic input shapes, but Intel NPU compilation currently requires static input shapes. The direct optimum-cli export openvino pipeline produced unbounded [-1, -1] inputs: the model worked on CPU but NPU compilation failed with ov_core_compile_model failed with status -1.
This project therefore exports BGE-M3 through a static ONNX graph and converts it to an INT8 OpenVINO IR with fixed [1, 512] inputs. The graph also exposes the CLS token directly as sentence_embedding [1, 1024], so ai2npu does not need to reshape the model or post-process last_hidden_state.