本项目将 ModelScope timm/vgg19.tv_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/vgg19.tv_in1k
input_shape: [1, 3, 224, 224]
output_shape: [1, 1000]
NPU Top-5 Predictions:
Top-1: class_883 (0.165030)
Top-2: class_943 (0.076639)
Top-3: class_948 (0.064251)
Top-4: class_738 (0.051736)
Top-5: class_945 (0.051140)
weights_path: /opt/atomgit/.cache/modelscope/hub/models/timm/vgg19___tv_in1k/model.safetensors
missing_keys: 0, unexpected_keys: 0日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.006112 |
| mean_abs_error | 0.001084 |
| relative_error | 0.0698% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
CPU vs NPU Top-1/Top-5 完全一致。
在 Ascend910 NPU 单卡上测得(输入 1x3x224x224,预热 2 次,正式 10 次):
| 指标 | 数值 |
|---|---|
| avg_latency_ms | 5.346 |
| min_latency_ms | 5.279 |
| max_latency_ms | 5.392 |
| p50_latency_ms | 5.347 |
| p90_latency_ms | 5.380 |
| p95_latency_ms | 5.386 |
| throughput_ips | 187.06 |
性能日志保存在 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。#NPU #Ascend #Ascend910 #timm #VGG #ImageNet