本仓库包含了 timm 中的 swin_s3_small_224.ms_in1k 模型在华为昇腾 NPU 上的适配与推理实现。
swin_s3_small_224.ms_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 推理耗时 | 0.4713s |
| NPU 推理耗时 | 0.0171s |
| MAE (平均绝对误差) | 0.00149978 |
| Max Error (最大误差) | 0.00893593 |
| MSE (均方误差) | 3.76e-06 |
| 相对误差 | 0.00239883 |
| 误差百分比 | 0.2399 |
| 余弦相似度 | 0.99999728 |
| Top-5 索引一致性 | 是 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 0.4713 |
| NPU | 0.0171 |
CPU inference time: 0.4713s
Top-5 indices: [549, 610, 446, 868, 551]
Top-5 values: [3.365184, 2.872148, 2.822342, 2.698633, 2.686674]
NPU inference time: 0.0171s
Top-5 indices: [549, 610, 446, 868, 551]
Top-5 values: [3.363793, 2.866249, 2.820913, 2.706013, 2.685066]
CPU/NPU Relative Error: 0.2399%Mean Absolute Error (MAE): 0.00149978
Max Absolute Error: 0.00893593
Cosine Similarity: 0.99999728
Relative Error: 0.00239883运行截图由 acend- 工具生成,展示推理成功画面。