g
gyccc/facebook-levit-384-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

facebook/levit-384 on Ascend NPU

1. 简介

将 HuggingFace 图片分类模型 facebook/levit-384 适配为可在单卡昇腾 NPU(Ascend910B4)上运行的提交工程。

  • 模型类型: LevitForImageClassificationWithTeacher
  • 说明: 该模型包含蒸馏头(distillation head),outputs.logits 为学生模型分类 logits,outputs.teacher_logits 为教师模型输出(本适配未使用)
  • 参数量: 39,128,836
  • 图片分类模型: ImageNet-1K 1000 类

2. 验证环境

项目版本/信息
NPU 型号Ascend910B4
CANN 版本8.5.1
torch 版本2.9.0+cpu
torch_npu 版本2.9.0.post1+gitee7ba04
transformers 版本4.57.6
Python 版本3.11.14

3. 推理运行

依赖安装

pip install -r requirements.txt
# torch_npu 通常由昇腾容器提供,无需单独安装

运行推理

# 设置 HF 镜像(如需要)
export HF_ENDPOINT=https://hf-mirror.com

# 运行推理
python inference.py

日志路径

  • 推理日志: logs/inference.log
  • 预测结果: logs/prediction.txt

4. Smoke 验证

torch.npu.is_available(): True
NPU: Ascend910B4
模型类型: LevitForImageClassificationWithTeacher
说明: outputs.logits 为学生模型分类 logits(含 distillation head)

Top-1: coyote, prairie wolf, brush wolf, Canis latrans (0.9311)
Top-2: red wolf, maned wolf, Canis rufus, Canis niger (0.0526)
Top-3: timber wolf, grey wolf, gray wolf, Canis lupus (0.0068)
Top-4: grey fox, gray fox, Urocyon cinereoargenteus (0.0020)
Top-5: dhole, Cuon alpinus (0.0019)

5. 性能参考

指标值
avg18.36 ms
min18.25 ms
max18.49 ms
p5018.39 ms
p9018.45 ms
p9518.47 ms
images_per_sec54.47

6. 精度评测

CPU vs NPU 一致性验证(smoke accuracy,非官方 ImageNet 精度):

指标值
max_abs_diff1.637161e-03
mean_abs_diff3.412865e-04
prob_max_diff1.059175e-04
Top-1 matchTrue
Top-5 matchTrue

7. 自验证截图

见 screenshots/self_verification.png

8. 日志文件

文件说明
logs/env_check.log环境检查日志
logs/inference.log推理日志
logs/prediction.txt预测结果
logs/accuracy.log精度验证日志
logs/benchmark.log性能测试日志

9. 注意事项

  • 本模型为 LevitForImageClassificationWithTeacher,包含蒸馏头。outputs.logits 为学生模型分类 logits,outputs.teacher_logits 为教师模型输出(本适配未使用)。所有日志和 README 中均已说明。
  • Processor 使用 LevitImageProcessor(slow processor),HuggingFace 建议未来版本可使用 fast processor
  • 测试图片为真实下载图片(非占位图)
  • HuggingFace 官方源超时,使用 hf-mirror.com 镜像下载模型

10. 标签

#NPU