sheepss/WhereIsAI-UAE-Large-V1-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

WhereIsAI/UAE-Large-V1 昇腾 NPU 适配

WhereIsAI/UAE-Large-V1 是基于 AnglE 优化的 BERT-large 架构(BertModel,24 层,hidden 1024, 约 335M 参数)的英文句向量模型,采用 CLS pooling + L2 归一化输出 1024 维 embedding,检索任务 query 需加官方前缀 "Represent this sentence for searching relevant passages:"。本仓库将其适配到 华为昇腾 NPU(Ascend910,torch_npu 2.9.0),完成真实 npu:0 推理验证。

适配结论

项目结果
任务路线embedding(AutoModel + CLS pooling + normalize)
设备npu:0(Ascend910_9362,单卡 HBM 61GB)
dtype / 种子float32 / seed=42
一致性6 条句向量 CPU-NPU cosine ≥ 0.999992,逐维 max diff ≤ 4.190e-04(fp32 阈值 1e-3 内)
任务语义query 与相关段落 cosine 0.7879 ≫ 无关段落 0.2983;相近句对 0.4783 > 无关对
性能稳定吞吐 378.93 sentences/s(batch=6,20 次迭代,torch.npu.synchronize() 前后计时;首次编译 0.2096s 单独计)

工作流证据

agent workflow

NPU 设备调用证明

npu device call

模型参数、输入 input_ids/attention_mask、输出 last_hidden_state、pooling 后向量与归一化结果均在 npu:0。

推理结果

model result

使用方法

pip install -r requirements.txt
python inference.py

inference.py 从本地权重目录加载模型,将全部 Tensor 显式迁移至 npu:0,执行 CLS pooling 句向量推理并打印相似度矩阵。