本仓库包含了 timm 中的 vit_betwixt_patch32_clip_224.tinyclip_laion400m 模型在华为昇腾 NPU 上的适配与推理实现。
vit_betwixt_patch32_clip_224.tinyclip_laion400m (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.1452s |
| NPU 推理耗时 | 0.0055s |
| MAE (平均绝对误差) | 0.55944357 |
| Max Error (最大误差) | 1.89988315 |
| MSE (均方误差) | 0.49461499 |
| 相对误差 | 1.43002944 |
| 误差百分比 | 143.0029 |
| 余弦相似度 | 0.02151387 |
| Top-5 索引一致性 | 否 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 0.1452 |
| NPU | 0.0055 |
CPU inference time: 0.1452s
Top-5 indices: [321, 122, 356, 112, 25]
Top-5 values: [1.450505, 1.386286, 1.379635, 1.369184, 1.291071]
NPU inference time: 0.0055s
Top-5 indices: [259, 314, 187, 195, 389]
Top-5 values: [1.327437, 1.30163, 1.246607, 1.186367, 1.178632]
CPU/NPU Relative Error: 143.0029%Mean Absolute Error (MAE): 0.55944357
Max Absolute Error: 1.89988315
Cosine Similarity: 0.02151387
Relative Error: 1.43002944运行截图由 acend- 工具生成,展示推理成功画面。