本项目将 ModelScope timm/mobilenetv4_hybrid_medium.ix_e550_r384_in1k 模型适配到单卡昇腾 NPU (Ascend910) 上运行。
snapshot_download + 本地 safetensors 权重加载resolve_model_data_config + create_transform| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| torch | 2.x |
| torch_npu | 与 CANN 匹配版本 |
| timm | latest |
| modelscope | latest |
环境检查日志见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理结果 (NPU):
=== NPU Inference ===
model: timm/mobilenetv4_hybrid_medium.ix_e550_r384_in1k
input_shape: [1, 3, 384, 384]
output_shape: [1, 1000]
NPU Top-5 Predictions:
Top-1: class_644 (0.001407)
Top-2: class_111 (0.001379)
Top-3: class_399 (0.001265)
Top-4: class_506 (0.001242)
Top-5: class_475 (0.001234)
weights_path: /opt/atomgit/.cache/modelscope/hub/models/timm/mobilenetv4_hybrid_medium___ix_e550_r384_in1k/model.safetensors
missing_keys: 0, unexpected_keys: 0日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.000036 |
| mean_abs_error | 0.000006 |
| relative_error | 0.0065% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
CPU vs NPU Top-1/Top-5 完全一致。
在 Ascend910 NPU 单卡上测得(输入 1x3x384x384,预热 2 次,正式 10 次):
| 指标 | 数值 |
|---|---|
| avg_latency_ms | 13.713 |
| min_latency_ms | 13.232 |
| max_latency_ms | 14.219 |
| p50_latency_ms | 13.687 |
| p90_latency_ms | 14.211 |
| p95_latency_ms | 14.215 |
| throughput_ips | 72.93 |
性能日志保存在 logs/benchmark.log。
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png 和 screenshots/self_verification.txt。
| 日志 | 说明 |
|---|---|
logs/env_check.log | NPU 环境检查 |
logs/inference.log | NPU 推理输出 |
logs/accuracy.log | CPU-NPU 精度一致性 |
logs/benchmark.log | NPU 性能基准 |
modelscope.snapshot_download 获取并本地加载。.gitignore 已排除 *.bin, *.safetensors, *.pth, *.pt, *.ckpt, *.onnx。assets/test.jpg 为占位图(400x300 灰色图),不影响推理流程验证。#NPU #Ascend #Ascend910 #timm #MobileNetV4 #ImageNet