本仓库包含了 timm 中的 vit_base_patch8_224.augreg_in21k_ft_in1k 模型在华为昇腾 NPU 上的适配与推理实现。
vit_base_patch8_224.augreg_in21k_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 推理耗时 | 3.3023s |
| NPU 推理耗时 | 0.0063s |
| MAE (平均绝对误差) | 0.0084696 |
| Max Error (最大误差) | 0.0316858 |
| MSE (均方误差) | 0.00011324 |
| 相对误差 | 0.00637843 |
| 误差百分比 | 0.6378 |
| 余弦相似度 | 0.99998047 |
| Top-5 索引一致性 | 是 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 3.3023 |
| NPU | 0.0063 |
CPU inference time: 3.3023s
Top-5 indices: [610, 557, 417, 701, 746]
Top-5 values: [5.841973, 5.839848, 5.393415, 5.378192, 4.948293]
NPU inference time: 0.0063s
Top-5 indices: [557, 610, 417, 701, 746]
Top-5 values: [5.83481, 5.832632, 5.399004, 5.373003, 4.953431]
CPU/NPU Relative Error: 0.6378%Mean Absolute Error (MAE): 0.0084696
Max Absolute Error: 0.0316858
Cosine Similarity: 0.99998047
Relative Error: 0.00637843运行截图由 acend- 工具生成,展示推理成功画面。