xujiashuai/timm-structbert-siamese-uninu
模型介绍文件和版本Pull Requests讨论分析

structbert-siamese-uninu 在昇腾 NPU 上的适配

1. 简介

  • 模型来源:iic/nlp_structbert_siamese-uninlu_chinese-base
  • 架构:StructBERT-Siamese(6 层 Transformer Encoder + 6 层 CrossAttention)
  • 参数量:59,740,416(编码器部分)
  • 适配状态:成功
  • 适配时间:2026-05-17

2. 验证环境

组件版本
torch2.9.0
torch-npu2.9.0.post1
transformers4.57.6
CANN8.5.1
NPUAscend 910B4

3. 精度评测

指标数值
余弦相似度0.999999
最大绝对误差0.007184
是否满足要求是(< 1%)

4. 性能

指标数值
平均延迟3.85 ms
输出形状[1, 25, 768]

5. 适配说明

该模型采用 StructBERT-Siamese 架构,检查点中的权重以 plm. 为前缀。适配时需进行以下操作:

  1. 移除 plm. 前缀(BertModel 直接使用 embeddings/encoder/pooler)
  2. 自动检测编码器层数为 6 层(配置文件中写为 12 层,但实际检查点仅有 6 层编码器 + 6 层交叉注意力)
  3. 跳过 crossattention.*、head_clsf.*、tail_clsf.* 权重(孪生网络特有层)

6. 推理输出证据

运行 inference.py 的实际输出:

$ python3 inference.py --model-id iic/nlp_structbert_siamese-uninlu_chinese-base --device npu:0

Output shape: [1, 25, 768]
Param count: 59,740,416
是否有 NaN: False
SUCCESS

7. CPU 与 NPU 精度对比

指标数值
Cosine Similarity0.999999
Max Abs Error0.007184
精度误差0.0001%
是否满足要求✅ 是(< 1%)

8. 复现步骤

python3 evaluate.py --model-id iic/nlp_structbert_siamese-uninlu_chinese-base --device npu:0 --output report.json
python3 inference.py --model-id iic/nlp_structbert_siamese-uninlu_chinese-base --device npu:0

贡献者: xujiashuai | 赛道: 模型适配赛道

下载使用量0