w
gcw_uQ09W7jl/timm-vit_giant_patch14_clip_224.laion2b-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

timm/vit_giant_patch14_clip_224.laion2b on Ascend NPU

1. 简介

本项目将 ModelScope 上的 timm/vit_giant_patch14_clip_224.laion2b 模型适配到单卡昇腾 NPU (Ascend910)。该模型是 CLIP 视觉编码器,参数量约 1012.6M,输入 224x224 图像,输出 1024 维特征向量。

  • 原始模型: https://www.modelscope.cn/models/timm/vit_giant_patch14_clip_224.laion2b
  • 架构: VisionTransformer (ViT-Giant)
  • 参数量: 1012.6M
  • 输入: [1, 3, 224, 224]
  • 输出: [1, 1024]

2. 验证环境

项目版本/型号
NPUAscend910
CANN8.5.1
Python3.11.14
PyTorch(environment built-in)
torch_npu(environment built-in)
timmlatest

环境检查日志: logs/env_check.log

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU):

Model: timm/vit_giant_patch14_clip_224.laion2b
Input shape: [1, 3, 224, 224]
Output shape: [1, 1024]
Output dtype: torch.float32

Top-5 outputs (index, value):
  1. index=986, value=19.222082
  2. index=81, value=2.903720
  3. index=555, value=2.687925
  4. index=245, value=2.347381
  5. index=354, value=2.206648

日志保存在 logs/inference.log。

4. 精度验证

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

指标数值
max_abs_error0.044161
mean_abs_error0.008519
relative_error1.3408%
cosine_similarity0.999943
threshold1.0%
resultFAIL (详见下方说明)

精度说明: 本模型为 1012.6M 参数的大模型,CPU-NPU element-wise relative_error 为 1.3408%,略超 1.0% 阈值。但 cosine_similarity 达到 0.999943(接近完美),且 CPU/NPU 的 Top-5 输出完全一致,表明模型在 NPU 上的行为与 CPU 高度一致。对于大模型,该误差源于 NPU/CPU 浮点运算的硬件级累积差异,在工程应用(特征提取、相似度计算)中完全可接受。

5. 性能参考

指标数值
avg_latency_ms23.281
min_latency_ms21.933
max_latency_ms24.871
p50_latency_ms22.741
p90_latency_ms24.609
p95_latency_ms24.740
throughput_ips42.95

测试条件: NPU Ascend910, 10 次迭代(2 次 warmup),batch_size=1, 输入 [1, 3, 224, 224]。

日志保存在 logs/benchmark.log。

6. 精度评测说明

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

7. 自验证截图

关键验证结果摘要:

  • 环境: NPU Ascend910 可用,设备名 Ascend910_9362
  • 推理: 输出 shape [1, 1024],Top-5 一致
  • 精度: relative_error=1.3408%, cosine_similarity=0.999943, Top-5 match=True
  • 性能: avg_latency=23.28ms, throughput=42.95 ips

8. 日志文件

  • logs/env_check.log — 环境检查
  • logs/inference.log — 推理结果
  • logs/accuracy.log — 精度验证
  • logs/benchmark.log — 性能基准

9. 注意事项

  1. 模型权重约 3.8GB,首次下载需较长时间,由 modelscope.snapshot_download 自动完成。
  2. 权重加载使用本地 model.safetensors,不依赖 HuggingFace 自动下载。
  3. 该模型为 CLIP 视觉编码器,输出为 1024 维图像嵌入,适用于相似度计算、检索等下游任务,非传统分类模型(1024 维对应 CLIP 嵌入空间)。

10. 标签

#NPU #Ascend #Ascend910 #timm #ViT #CLIP