本仓库包含了 timm 中的 tiny_vit_21m_512.dist_in22k_ft_in1k 模型在华为昇腾 NPU 上的适配与推理实现。
tiny_vit_21m_512.dist_in22k_ft_in1k (timm / HuggingFace Hub)本模型基于 timm 库加载预训练权重,模型权重通过 ModelScope 下载。在昇腾 NPU 上通过 torch_npu 实现硬件加速。
pip install -r requirements.txtpython inference.pypip install -r requirements.txtpython inference.pypython compare_cpu_npu.py| 指标 | 数值 |
|---|---|
| CPU 推理耗时 | 1.9195s |
| NPU 推理耗时 | 0.0104s |
| MAE (平均绝对误差) | 0.00367987 |
| Max Error (最大误差) | 0.0209806 |
| MSE (均方误差) | 2.185e-05 |
| 相对误差 | 0.00418713 |
| 误差百分比 | 0.4187 |
| 余弦相似度 | 0.99999135 |
| Top-5 索引一致性 | 是 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 1.9195 |
| NPU | 0.0104 |
CPU inference time: 1.9195s
Top-5 indices: [551, 844, 549, 838, 419]
Top-5 values: [5.699982, 4.822712, 4.754692, 4.524559, 4.315609]
NPU inference time: 0.0104s
Top-5 indices: [551, 844, 549, 838, 419]
Top-5 values: [5.702669, 4.818471, 4.74679, 4.528192, 4.321177]
CPU/NPU Relative Error: 0.4187%Mean Absolute Error (MAE): 0.00367987
Max Absolute Error: 0.0209806
Cosine Similarity: 0.99999135
Relative Error: 0.00418713运行截图由 acend- 工具生成,展示推理成功画面。