Y
gcw_hhrLdMXW/UAE-Large-V1
模型介绍
文件和版本
Pull Requests
讨论
分析

WhereIsAI/UAE-Large-V1 昇腾 NPU 部署文档

1. 模型简介

UAE-Large-V1(WhereIsAI/UAE-Large-V1)是一个基于 BERT-large 架构的高性能文本嵌入模型,在 MTEB 榜单上长期位居前列。输出 1024 维语义嵌入向量,广泛应用于语义搜索、文本聚类、检索增强生成(RAG)等任务。

  • 架构:BertModel(1024 hidden, 24 layers, 16 heads)
  • 参数:约 335M
  • 输入:文本(最大 512 token)
  • 输出:1024 维嵌入向量
  • 权重:model.safetensors(1.34GB)
  • 官方仓库:https://huggingface.co/WhereIsAI/UAE-Large-V1

2. 环境依赖清单

组件版本说明
昇腾 NPUAscend910_9362 ×2(64GB HBM)推理硬件
CANN8.5.1昇腾计算框架
torch2.9.0+cpuPyTorch
torch_npu2.9.0.post1昇腾 NPU 插件
transformers4.57.6模型加载
numpy1.26.4科学计算

安装依赖:

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

3. 分步推理操作流程

3.1 环境检查

npu-smi info          # 确认 NPU 健康与显存
python3 -c "import torch, torch_npu; print(torch.npu.device_count())"

3.2 运行推理脚本

cd uae-large-v1-npu-deployment
ASCEND_RT_VISIBLE_DEVICES=0 python3 inference.py

3.3 自定义文本

python3 inference.py --texts "Hello world" "How are you" "Nice to meet you"

3.4 指定设备与基准

python3 inference.py --device npu:0 --warmup 3 --runs 20

4. 测试用例与输出结果

测试输入(4 句):

编号文本语义类别
[0]The man is working on a computer工作/电脑
[1]The woman is reading a book阅读/书籍
[2]The weather is sunny today天气/晴天
[3]A person is typing on a keyboard打字/键盘

输出结果(昇腾 NPU,Ascend910_9362):

嵌入向量维度: (4, 1024)
推理耗时: 225.7 ms

余弦相似度矩阵:
  [0] vs [0]: 1.000000  [0] vs [1]: 0.224143  [0] vs [2]: 0.346306  [0] vs [3]: 0.643179
  [1] vs [0]: 0.224143  [1] vs [1]: 1.000000  [1] vs [2]: 0.308905  [1] vs [3]: 0.389080
  [2] vs [0]: 0.346306  [2] vs [1]: 0.308905  [2] vs [2]: 1.000000  [2] vs [3]: 0.404843
  [3] vs [0]: 0.643179  [3] vs [1]: 0.389080  [3] vs [2]: 0.404843  [3] vs [3]: 1.000000

性能基准 (warmup=3, runs=20):
  平均耗时: 16.41 ms / 4 句

语义验证:[0](电脑工作)与 [3](键盘打字)相似度 0.64,显著高于 [0] 与 [2](天气晴天)的 0.35,符合语义直觉。

验收结论:UAE-Large-V1(BERT-large 1024)在昇腾 NPU 上完整跑通前向传播,嵌入向量语义正确,无算子回退或崩溃。

5. 目录结构

uae-large-v1-npu-deployment/
├── inference.py        # 推理脚本
├── readme.md          # 部署说明
├── requirements.txt   # 环境依赖
├── SKILL.md           # 技能文档
├── model/             # 模型权重
└── assets/            # 截图素材
    ├── agent_workflow.png
    ├── npu_device_call.png
    └── model_result.png