structbert-siamese-uninu on Ascend NPU
1. 简介
- 模型来源: iic/nlp_structbert_siamese-uninlu_chinese-base
- 架构: StructBERT-Siamese (6层 Transformer Encoder + 6层 CrossAttention)
- 参数量: 59,740,416 (encoder 部分)
- 适配状态: SUCCESS
- 适配时间: 2026-05-17
2. 验证环境
| 组件 | 版本 |
|---|
| torch | 2.9.0 |
| torch-npu | 2.9.0.post1 |
| transformers | 4.57.6 |
| CANN | 8.5.1 |
| NPU | Ascend 910B4 |
3. 精度评测
| 指标 | 数值 |
|---|
| Cosine Similarity | 0.999999 |
| Max Abs Error | 0.007184 |
| 是否满足要求 | 是(< 1%) |
4. 性能
| 指标 | 数值 |
|---|
| 平均延迟 | 3.85 ms |
| 输出形状 | [1, 25, 768] |
5. 适配说明
该模型使用 StructBERT-Siamese 架构,checkpoint 中权重以 plm. 为前缀。适配时需要:
- 将
plm. 前缀去掉(BertModel 直接使用 embeddings/encoder/pooler)
- 自动检测 encoder 层数为 6 层(config 写 12 但实际 checkpoint 只有 6 层 encoder + 6 层 crossattention)
- 跳过
crossattention.*、head_clsf.*、tail_clsf.* 权重(siamese 特有层)
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 vs NPU 精度对比
| 指标 | 数值 |
|---|
| Cosine Similarity | 0.999999 |
| Max Abs Error | 0.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 | 赛道: 模型适配赛道