w
gcw_uQ09W7jl/facebook-levit-128S-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

facebook/levit-128S on Ascend NPU

1. 简介

本项目将 HuggingFace 模型 facebook/levit-128S 适配到华为昇腾 NPU (Ascend910) 上运行。

LeViT (LeViT: a Vision Transformer in ConvNet's Clothing) 是一种高效的视觉分类模型。本项目通过 ModelScope 下载权重并使用 transformers 本地加载,完成单卡 NPU 推理验证、CPU-NPU 精度一致性检查和性能基准测试。

2. 验证环境

项目版本/型号
NPUAscend910 (Ascend910_9362)
CANN8.5.1
torch2.x
torch_npu适配 CANN 8.5.1
transformers4.x

环境详情见 logs/env_check.log。

3. 推理运行

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。

4. 精度验证

对单张测试输入进行 CPU 与 NPU 一致性验证:

指标数值
max_abs_error0.006893
mean_abs_error0.000974
relative_error0.1023%
cosine_similarity1.000000
threshold1.0%
结果PASS

5. 性能参考

指标数值
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

6. 精度评测说明

本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。

7. 自验证截图

见 screenshots/self_verification.txt 与 screenshots/self_verification.png。

8. 日志文件

  • logs/env_check.log — NPU 环境检查
  • logs/inference.log — NPU 推理输出
  • logs/accuracy.log — CPU-NPU 精度一致性
  • logs/benchmark.log — NPU 性能基准

9. 注意事项

  • 权重通过 ModelScope snapshot_download 自动下载,禁止 HuggingFace 直连下载
  • 推理脚本使用 local_files_only=True 本地加载
  • 测试图片若网络不可用会自动生成占位图
  • 不提交权重文件(已配置 .gitignore)

10. 标签

#NPU #Ascend #Ascend910 #LeViT #ImageClassification