| 组件 | 版本 |
|---|---|
| torch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| transformers | 4.57.6 |
| Python | 3.11.14 |
| 硬件 | Ascend 910B |
source /usr/local/Ascend/ascend-toolkit/set_env.sh
python3 inference.py --model-dir /data/models/distilbert-base-uncased --device npu:0============================================================
distilbert-base-uncased NPU 文本编码 + CPU/NPU 精度对比
============================================================
| device : npu:0 (x2)
| model : DistilBERT 文本编码 (66.363M params)
| input : 2 组随机 token (seq_len=32)
| out shape: [2, 32, 768] (CLS embedding, dim=768)
| cosine : 0.99998707
| rel_err : 0.573194%
| latency : 4.16 ms
| result : PASS ✅
============================================================| 指标 | 值 |
|---|---|
| 延迟 | 4.16 ms(batch=2, seq_len=32) |
| Cosine Similarity | 0.99998707 |
| 指标 | 值 |
|---|---|
| Cosine Similarity | 0.99998707 |
| 相对误差 | 0.5731% |
适配状态: PASS ✓
torch_npu,并在 inference.py 中显式 import torch_npusource /usr/local/Ascend/ascend-toolkit/set_env.sh,设置 CANN 环境变量/data/models/distilbert-base-uncased/,请勿移动或修改