eardoi/UAE-Large-V1-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

WhereIsAI UAE-Large-V1(昇腾 NPU 适配)

UAE-Large-V1(Universal AnglE Embedding)是 WhereIsAI 发布的高质量英文句向量 嵌入模型(BERT-large,335M 参数)。将文本句子映射为 1024 维向量,在 MTEB 检索/相似度榜单上名列前茅,广泛用于语义检索、RAG、文本相似度等场景。

本项目完成其在**华为昇腾 NPU(Ascend 910B)**上的推理适配与验证。

模型规格

项目说明
模型架构BertModel(BERT-large)
参数量335M
嵌入维度1024
最大序列长度512
池化方式CLS token + L2 归一化
权重格式safetensors(1.3GB)
支持任务句向量嵌入、语义检索、文本相似度

环境要求

项目要求
硬件Ascend 910B 系列(≥1 卡)
CANN≥ 8.0(source /usr/local/Ascend/ascend-toolkit/set_env.sh)
Python3.10 – 3.11
torch / torch_npu2.9.0 / 2.9.0.post1
transformers≥ 4.30

环境准备

source /usr/local/Ascend/ascend-toolkit/set_env.sh
export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
pip install torch_npu==2.9.0.post1 transformers pillow safetensors \
    -i https://repo.huaweicloud.com/repository/pypi/simple/

模型权重

权重通过 HuggingFace 镜像获取:

git clone --depth 1 https://hf-mirror.com/WhereIsAI/UAE-Large-V1 model_src

权重目录包含:model.safetensors(1.3GB)/ tokenizer.json / vocab.txt / config.json 等。

推理

cd /workspace/UAE-Large-V1
python3 inference.py --model_path ./model_src --text "What is the capital of France?" --device npu:0

参数

参数说明默认值
--model_path模型权重目录./model_src
--text输入文本句子(真实文本,必选)-
--device推理设备(npu:0 / cpu)npu:0
--output结果保存文件(可选,向量 CSV)stdout

设备解析:NPU 优先,自动回退 CPU。

验证结果(Ascend 910B, npu:0)

输入:"What is the capital of France?"

输出:

[info] 句向量维度: 1024
[info] 向量前 8 维: [-0.009, -0.0028, 0.0025, -0.0251, 0.0324, -0.0196, 0.0179, -0.0021]
[info] L2 范数: 1.000000

1024 维 L2 归一化句向量正常输出,NPU 推理链路完整跑通。

适配说明

  • 纯 Transformers BERT 架构,无 CUDA 特有 API,直接 .to(npu) 迁移即可。
  • 句向量采用 CLS token 池化 + L2 归一化(UAE 官方 pooling_strategy='cls')。
  • 推理使用 torch.no_grad()。
  • 设备解析 resolve_device():NPU 可用性检测,失败自动回退 CPU。
  • 模型权重不推送到仓库:*.safetensors / *.bin 已加入 .gitignore, 仓库仅包含推理脚本、模型卡片与截图素材。

目录结构

.
├── README.md          # 模型卡片(本文件)
├── inference.py       # NPU 推理脚本
└── assets/            # 适配过程截图素材

引用

  • 模型:https://huggingface.co/WhereIsAI/UAE-Large-V1