本项目将 timm/tiny_vit_21m_224.dist_in22k_ft_in1k 图像分类模型适配到华为昇腾 NPU(Ascend910)。
使用 ModelScope 的 snapshot_download 功能下载权重,通过 timm.create_model(pretrained=False) 加载本地权重,并借助 torch_npu 将模型迁移至 npu:0 设备执行推理。项目包含推理验证、CPU 与 NPU 精度一致性检查以及性能基准测试。
| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | [LOG_WARNING] can not create directory, directory: /home/atomgit/ascend/log, possible reason: No such file or directory.path string is NULLpath string is NULL2.9.0+cpu |
| torch_npu | [LOG_WARNING] can not create directory, directory: /home/atomgit/ascend/log, possible reason: No such file or directory.path string is NULLpath string is NULL2.9.0.post1+gitee7ba04 |
| timm | [LOG_WARNING] can not create directory, directory: /home/atomgit/ascend/log, possible reason: No such file or directory.path string is NULLpath string is NULL1.0.27 |
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.013995 |
| mean_abs_error | 0.003792 |
| relative_error | 0.4300% |
| cosine_similarity | 0.999992 |
| threshold | 1.0% |
| 结果 | PASS |
在单卡 Ascend910 NPU 上的性能表现:
| 指标 | 数值 |
|---|---|
| avg latency | 8.126 ms |
| throughput | 123.07 images/sec |
详细指标见 logs/benchmark.log。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
logs/inference.log — 推理输出logs/accuracy.log — 精度一致性验证logs/benchmark.log — 性能基准测试logs/env_check.log — 环境检查pretrained=False,从本地 safetensors 文件加载权重。timm.data.resolve_model_data_config + create_transform,自动匹配模型配置。#NPU #Ascend #Ascend910 #timm #TinyViT #image-classification