本项目将 timm/convnext_base.clip_laion2b 适配到华为昇腾 NPU (Ascend910) 上运行。该模型是基于 ConvNeXt-Base 架构、使用 CLIP 在 LAION-2B 数据集上预训练的图像分类模型,通过 timm 加载,输出 640 维 logits。
| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 (x2) |
| CANN | 8.5.1 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0 |
| timm | 1.0.27 |
| Python | 3.11.14 |
环境检查日志: logs/env_check.log
pip install -r requirements.txt
python inference.py推理结果 (NPU):
Input shape: [1, 3, 256, 256]
Output shape: [1, 640]
Output logits sample: [-0.0874, -0.1260, -0.0281, 0.1408, -0.0665]
Top-5 predictions:
1. class=493, prob=0.0091
2. class=521, prob=0.0052
3. class=320, prob=0.0046
4. class=30, prob=0.0037
5. class=505, prob=0.0036日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.013091 |
| mean_abs_error | 0.001230 |
| relative_error | 0.6091% |
| cosine_similarity | 0.999982 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| warmup_runs | 2 |
| benchmark_runs | 10 |
| avg_ms | 14.857 |
| min_ms | 14.832 |
| max_ms | 14.876 |
| p50_ms | 14.857 |
| p90_ms | 14.876 |
| p95_ms | 14.876 |
| throughput | 67.31 img/s |
日志保存在 logs/benchmark.log。
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.txt 与 screenshots/self_verification.png。
logs/env_check.log - 环境检查logs/inference.log - 推理输出logs/accuracy.log - 精度一致性验证logs/benchmark.log - 性能基准测试snapshot_download 自动下载到本地缓存,运行时会自动复用已下载的权重。timm.create_model(..., pretrained=False) 创建后加载本地 safetensors 权重,避免 HuggingFace 自动下载。resolve_model_data_config + create_transform 进行标准化预处理。#NPU #Ascend #Ascend910 #timm #ConvNeXt #CLIP