本项目将 HuggingFace 模型 facebook/levit-128S 适配到华为昇腾 NPU (Ascend910) 上运行。
LeViT (LeViT: a Vision Transformer in ConvNet's Clothing) 是一种高效的视觉分类模型。本项目通过 ModelScope 下载权重并使用 transformers 本地加载,完成单卡 NPU 推理验证、CPU-NPU 精度一致性检查和性能基准测试。
| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 (Ascend910_9362) |
| CANN | 8.5.1 |
| torch | 2.x |
| torch_npu | 适配 CANN 8.5.1 |
| transformers | 4.x |
环境详情见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理结果 (NPU):
Rank 1: class=985, score=0.469832
Rank 2: class=738, score=0.108866
Rank 3: class=325, score=0.084923
Rank 4: class=309, score=0.032874
Rank 5: class=947, score=0.023634
Output shape: torch.Size([1, 1000])
Model: LevitForImageClassificationWithTeacher日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.006893 |
| mean_abs_error | 0.000974 |
| relative_error | 0.1023% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg_latency(ms) | 7.387 |
| min_latency(ms) | 7.324 |
| max_latency(ms) | 7.580 |
| p50_latency(ms) | 7.363 |
| p90_latency(ms) | 7.465 |
| p95_latency(ms) | 7.522 |
| throughput(img/s) | 135.38 |
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.txt 与 screenshots/self_verification.png。
logs/env_check.log — NPU 环境检查logs/inference.log — NPU 推理输出logs/accuracy.log — CPU-NPU 精度一致性logs/benchmark.log — NPU 性能基准snapshot_download 自动下载,禁止 HuggingFace 直连下载local_files_only=True 本地加载.gitignore)#NPU #Ascend #Ascend910 #LeViT #ImageClassification