This is an Ascend NPU-enabled adaptation of BAAI/bge-base-en-v1.5 verified on Ascend 910B.
1_Pooling/config.json: pooling_mode_cls_token=true)next(model.parameters()).device -> npu:0, input_ids.device -> npu:0, last_hidden_state.device -> npu:0, normalized_embedding.device -> npu:0from transformers import AutoTokenizer, AutoModel
import torch, torch.nn.functional as F
model_id = "BAAI/bge-base-en-v1.5"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModel.from_pretrained(model_id).to("npu:0").eval()
sentences = ["The weather is sunny today", "It's a bright sunny day for a walk"]
inputs = tokenizer(sentences, padding=True, truncation=True, max_length=512, return_tensors="pt")
inputs = {k: v.to("npu:0") for k, v in inputs.items()}
with torch.no_grad():
outputs = model(**inputs)
embeddings = F.normalize(outputs.last_hidden_state[:, 0], p=2, dim=1) # CLS pooling
print(embeddings.shape) # [2, 768]Or run directly:
pip install -r requirements.txt
python inference.py


Hardware: NPU (Ascend 910B) with torch_npu. All tensors explicitly migrated to npu:0, synchronize before/after timing.