xujiashuai/nlp_structbert_siamese-uninlu_chinese-base
模型介绍文件和版本Pull Requests讨论分析

nlp_structbert_siamese-uninlu_chinese-base - Ascend NPU 适配

1. 模型简介

StructBERT Siamese-UniNLU 是一个基于 StructBERT 架构的通用信息抽取模型,采用 Siamese 网络结构和交叉注意力机制,支持实体识别、关系抽取、事件抽取等 NLU 任务。

  • 原始模型: iic/nlp_structbert_siamese-uninlu_chinese-base
  • 框架: PyTorch
  • 任务: Siamese UniNLU (Universal Information Extraction)

2. 昇腾 NPU 适配结果

指标值
Cosine Similarity0.999999
MaxAbsErr0.006291
Relative Error0.0677%
平均延迟7.87 ms
峰值显存0.38 GB
参数量102,267,648
推理精度float32
设备Ascend 910B4

3. 环境要求

组件版本
CANN8.5.1
torch_npu2.9.0.post1
PyTorch2.9.0
Python3.11

4. 快速使用

# 设置环境
source setup_env.sh

# 运行推理 (CPU vs NPU 对比)
python3 inference.py --device npu:0 --dtype float32

5. 推理输出证据

NPU 推理输出(float32, CLS token 对比):

模型: iic/nlp_structbert_siamese-uninlu_chinese-base
设备: npu:0
精度: float32
------------------------------------------------------------
[加载模型...]
[CPU] 推理中...
[NPU] 推理中 (npu:0)...

  CPU emb shape: torch.Size([2, 768])
  NPU emb shape: torch.Size([2, 768])
  Cosine Similarity (per sample): [0.9999991655349731, 0.9999990463256836]
  Cosine Similarity (mean): 0.999999
  MaxAbsErr: 0.006291
  Relative Error: 0.0677%

✓ 推理完成

[Perf] 测延迟...
  平均延迟: 7.87 ms
  峰值显存: 0.38 GB

6. CPU vs NPU 精度对比

指标CPU (float32)NPU (float32)误差
Cosine Similarity基准0.999999< 0.001%
MaxAbsErr-0.006291-
Relative Error-0.0677%< 1% ✓
输出维度[2, 768][2, 768]一致
NaNFalseFalse一致

7. 模型结构

  • Backbone: StructBERT (12 layers, 768 hidden, 12 heads)
  • Cross-Attention: 4 层交叉注意力 (用于 Siamese 结构)
  • 输入: 中文文本
  • 输出: CLS token embedding (768 维)

8. 验证报告

详见 screenshots/verification.txt。

9. Agent Skill

本适配由 Ascend NPU 适配 Agent Skill 自动完成。

下载使用量0