冬
gcw_IDzXRVNw/multi-qa-mpnet-base-dot-v1-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

multi-qa-mpnet-base-dot-v1 昇腾 NPU 适配部署文档

1. 模型简介

multi-qa-mpnet-base-dot-v1 是基于 MPNet 的句子嵌入模型,专门针对多选题问答场景优化。该模型能够将文本映射为 768 维的稠密向量,用于语义搜索和相似度匹配。

模型架构

属性值
模型类型MPNetForMaskedLM
基础模型microsoft/mpnet-base
参数量109.49 M
Hidden Size768
Num Layers12
Num Attention Heads12
Vocab Size30,527
Max Position Embeddings514

模型特点

  • 句子嵌入: 生成固定维度的句子级嵌入向量
  • 多选题优化: 专门针对问答场景训练
  • Dot Product: 使用点积作为相似度度量
  • 高性能: 在多种语义搜索基准上表现优异

2. 环境依赖清单

2.1 硬件要求

  • 华为昇腾系列 AI 处理器(Ascend 910B/310P 等)
  • 建议 ≥ 2 GB NPU 显存(multi-qa-mpnet-base-dot-v1 推理峰值约 1-2 GB)
  • 本次实测使用 910B2(单卡 64 GB)

2.2 软件依赖

依赖项版本要求说明
操作系统CentOS 7.6+ / Ubuntu 18.04+支持主流 Linux 发行版
CANN5.0.RC2+华为昇腾计算架构
Python3.10+推荐 3.10+
PyTorch2.0.0+推荐 2.12
torch_npu与 PyTorch 版本匹配昇腾 PyTorch 扩展

2.3 安装方式

conda activate pt2100
pip install transformers torch -i https://repo.huaweicloud.com/repository/pypi/simple

3. 分步推理操作流程

步骤 1:准备工作目录

cd /workspace/agent4/multi-qa-mpnet-base-dot-v1-ascend
ls -la /workspace/agent3/sentence-transformers/multi-qa-mpnet-base-dot-v1/

步骤 2:检查 NPU 环境

npu-smi info
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"

步骤 3:运行推理脚本

python inference.py --device npu:0

4. 完整测试用例

测试用例 1:句子嵌入推理(NPU:0)

conda activate pt2100
cd /workspace/agent4/multi-qa-mpnet-base-dot-v1-ascend
python inference.py --device npu:0

实际输出:

============================================================
multi-qa-mpnet-base-dot-v1 昇腾 NPU 推理
============================================================

[Device] npu:0

[Model Path] /workspace/agent3/sentence-transformers/multi-qa-mpnet-base-dot-v1

[Config]
  model_type: mpnet
  hidden_size: 768
  num_hidden_layers: 12
  num_attention_heads: 12
  vocab_size: 30527
  max_position_embeddings: 514

[Memory Before Model Load] Allocated: 0.00 GB, Reserved: 0.00 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 95.4        41                0    / 0             |
+===========================+===============+====================================================+


[Loading] multi-qa-mpnet-base-dot-v1 model weights...
[Loading] multi-qa-mpnet-base-dot-v1 model from ...sentence-transformers/multi-qa-mpnet-base-dot-v1
  Total keys: 200
  Total parameters: 109.49 M

[Model Created] Allocated: 0.91 GB, Reserved: 0.99 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 95.4        41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          4498 / 65536         |
+===========================+===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1738085       | python                   | 1128                   |
+===========================+===============+====================================================+


[Running] multi-qa-mpnet-base-dot-v1 inference...

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 104.4       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          4513 / 65536         |
+===========================+===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1738085       | python                   | 1142                   |
+===========================+===============+====================================================+


[Results]
  Output shape: torch.Size([1, 768])
  Output mean: 0.024535
  Output std: 0.452979

[Memory After Inference] Allocated: 0.91 GB, Reserved: 0.99 GB

[Done]

性能指标

指标值
模型参数量109.49 M
推理显存峰值~1-2 GB
输入 Shape(1, 128)
输出 Shape(1, 768)

5. 参考链接

  • Sentence-Transformers
  • MPNet Paper
  • HuggingFace 模型页