.to("npu:0") 将模型迁移到 Ascend NPU 执行推理LeViT-128S 是 Facebook 提出的一种高效图像分类模型,专为低延迟推理设计。参数量仅 7.7M,在 ImageNet-1K 上具有良好的精度-速度平衡。
| 项目 | 值 |
|---|---|
| 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 |
| 模型来源 | Hugging Face(通过 HF_ENDPOINT=https://hf-mirror.com) |
| 测试图片 | assets/test.jpg(程序生成的占位图,224x224) |
| 运行设备 | npu:0 |
环境检查详细日志: logs/env_check.log
pip install torch torchvision transformers pillow requests numpy huggingface_hub accelerateHF_ENDPOINT=https://hf-mirror.com python inference.pylogs/inference.loglogs/prediction.txt| 排名 | 标签 | ID | 置信度 |
|---|---|---|---|
| Top-1 | pinwheel | 723 | 0.1571 |
| Top-2 | balloon | 417 | 0.0844 |
| Top-3 | spotlight, spot | 818 | 0.0716 |
| Top-4 | velvet | 885 | 0.0417 |
| Top-5 | parachute, chute | 701 | 0.0247 |
注意:测试图片为程序生成的占位图,分类结果仅用于验证推理流程正确性,不代表真实场景识别能力。
torch.npu.is_available(): Truetorch.npu.device_count(): 1torch.npu.get_device_name(0): Ascend910B4model.device: npu:0HF_ENDPOINT=https://hf-mirror.com python benchmark.py性能测试在单卡 Ascend910B4 上完成,使用 HF_ENDPOINT=https://hf-mirror.com 下载模型。无 exit code 137 问题。
HF_ENDPOINT=https://hf-mirror.com python eval_accuracy.py重要说明:这是 smoke accuracy / CPU-NPU 一致性验证,不是官方 ImageNet 数据集精度评测。测试使用的是程序生成的占位图。精度差异来自 CPU 和 NPU 浮点实现差异。
screenshots/self_verification.pngscreenshots/self_verification.txt截图由真实 logs 生成,不是伪造。
| 文件 | 说明 |
|---|---|
logs/env_check.log | NPU 环境检查日志 |
logs/inference.log | 推理运行日志 |
logs/accuracy.log | CPU vs NPU 精度验证日志 |
logs/benchmark.log | 性能测试日志 |
logs/prediction.txt | 预测输出结果 |
HF_ENDPOINT=https://hf-mirror.com 从 hf-mirror 下载模型,因为无法直连 HuggingFace。#NPU