jsjs1258/BAAI-bge-base-en-v1.5-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

BAAI/bge-base-en-v1.5 - Ascend NPU

This is an Ascend NPU-enabled adaptation of BAAI/bge-base-en-v1.5 verified on Ascend 910B.

Model Info

  • Architecture: BertModel (bert, 12 layers, hidden 768, vocab 30522)
  • Route: embedding (CLS pooling + L2 normalize, per 1_Pooling/config.json: pooling_mode_cls_token=true)
  • Weight: 109M params (~418 MB fp32 safetensors)
  • Max length: 512
  • Precision: float32 (torch dtype float32)

NPU Validation

  • Device: Ascend910_9362, 2 NPUs, ~61 GiB free HBM each
  • next(model.parameters()).device -> npu:0, input_ids.device -> npu:0, last_hidden_state.device -> npu:0, normalized_embedding.device -> npu:0
  • First compile infer ~210 ms, stable avg ~7.6 ms/batch (4 sentences), throughput ~525 sentences/s
  • CPU-NPU consistency (same weight, same tokenizer, same inputs): cosine >= 0.9999 per sentence, max_diff ~0.00041, semantic ordering preserved (similar pair 0.88 > unrelated 0.42)

Usage

from 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

Evidence

  • Workflow: agent workflow
  • NPU device call: npu device
  • Model result: model result

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