本文档记录 iic/nlp_gte_sentence-embedding_chinese-small 在昇腾 NPU 上的适配验证结果。
| 组件 | 版本 |
|---|---|
torch | 2.9.0 |
torch-npu | 2.9.0.post1 |
transformers | 4.57.6 |
CANN | 8.5.1 |
python inference.py --model-id iic/nlp_gte_sentence-embedding_chinese-small --device npu:0或使用 evaluate.py 进行完整验证:
python evaluate.py --model-id iic/nlp_gte_sentence-embedding_chinese-small --device npu:0 --output report.json运行 inference.py 的实际输出:
$ python3 inference.py --model-id iic/nlp_gte_sentence-embedding_chinese-small --device npu:0
[1/5] 加载模型: iic/nlp_gte_sentence-embedding_chinese-small
参数量: 30,258,688
[2/5] 迁移到 npu:0
[3/5] Tokenize 输入 (max_length=128)
[4/5] 运行推理验证
输出形状: [1, 128, 512]
是否有 NaN: False
[5/5] 性能基准测试 (10 轮)
平均延迟: 4.69 ms
峰值显存: 0.08 GB
[额外] CPU vs NPU 精度对比
Cosine Similarity: 1.000000
Max Abs Error: 0.002320
精度误差: 0.0000%
✅ 精度满足要求(< 1%)
✓ 验证通过| 指标 | 结果 |
|---|---|
| 输出形状 | [1, 128, 512] |
| 是否有 NaN | 否 ✅ |
| 推理状态 | 正常 ✅ |
| 指标 | 数值 |
|---|---|
| 平均延迟 | 4.70 ms |
| 峰值显存 | 0.08 GB |
| 测试轮数 | 10 |
✅ NPU vs CPU 精度对比
| 指标 | 数值 |
|---|---|
| Cosine Similarity | 0.999999 |
| Max Abs Error | 0.002320 |
| 精度误差 | 0.0000% |
| 是否满足要求 | 是(< 1%)✅ |
| 材料 | 文件 | 说明 |
|---|---|---|
| 推理脚本 | inference.py | 独立可运行的 NPU 推理代码 |
| 精度评测代码 | evaluate.py | CPU vs NPU cosine similarity 对比 |
| 环境检查 | env_check.py | NPU 环境验证脚本 |
| 运行日志 | logs/*.log | 完整执行日志(可复现) |
| 自验证截图 | screenshots/ | 终端验证截图 |
| 精度报告 | report.json | 结构化评测数据 |
| 部署文档 | DEPLOY.md | 环境搭建与验证指南 |
| 依赖清单 | requirements.txt | Python 依赖(uv/pip 安装) |
本模型适配由以下 Agent Skill 完成(6.2 必填)
| 项目 | 内容 |
|---|---|
| Skill 名称 | nlp-encoder-npu-adapt |
| 触发条件 | BERT/GTE/StructBERT 句子编码器适配到昇腾 NPU |
| 覆盖模型 | 2 个 NLP Sentence Encoder 模型 |
| 核心能力 | 文本编码、Mean Pooling、FP16 推理、精度验证、性能基准 |
Agent 自动执行:
# 下载模型
modelscope download --model iic/nlp_gte_sentence-embedding_chinese-small --cache_dir ./models
# 运行验证
python wave1/1h_nlp_encoder/evaluate_nlp.py \
--model-id iic/nlp_gte_sentence-embedding_chinese-small \
--device npu:0 --dtype float16 --max-length 128 \
--cache-dir ./models/iic/nlp_gte_sentence-embedding_chinese-small \
--output report.json# Step 1: 环境检查
python3 env_check.py
# Step 2: 验证模型
python3 evaluate.py --model-id iic/nlp_gte_sentence-embedding_chinese-small --device npu:0 --output report.json
# Step 3: 运行推理
python3 inference.py --model-id iic/nlp_gte_sentence-embedding_chinese-small --device npu:0贡献者: xujiashuai 参赛赛道: 模型适配赛道 提交时间: 2026-05-17