m0_74196153/aimv2-large-patch14-336-distilled
模型介绍文件和版本Pull Requests讨论分析

Apple AIMv2 Large Patch14 336 Distilled — 昇腾 NPU 适配

1. 简介

本文档记录 apple/aimv2-large-patch14-336-distilled 在 Ascend 910B4 NPU 上的推理适配与验证结果。

AIMv2 336-distilled 为蒸馏版 ViT 模型,输入尺寸 336×336,参数量约 1.15B。

  • 论文: Multimodal Autoregressive Pre-training of Large Vision Encoders
  • 原始权重: ModelScope / HuggingFace

2. 环境

组件版本
PyTorch2.9.0+cpu
torch_npu2.9.0.post1
Transformers4.57.6
CANN8.5.1
NPUAscend 910B4

3. 适配要点

  • 权重 Key 转换: 原始 safetensors 使用 Timm 风格命名,通过 convert_weights.py 自动映射
  • 零算子修改: 所有算子原生支持 NPU
  • 直接加载: 使用本地建模文件直接加载

4. 使用方式

# 安装依赖
pip install torch torch_npu transformers safetensors pillow

# 运行推理(随机输入)
python inference.py

# 运行推理(真实图片)
python inference.py --image path/to/image.jpg

# FP16 推理
python inference.py --dtype float16

5. 精度评测

CPU 与 NPU 同输入逐元素对比(FP32):

seedmax_diffmean_diffcos_sim结果
424.42e-035.83e-051.000057✅ PASS
1233.35e-036.00e-051.000049✅ PASS
2564.72e-035.90e-051.000052✅ PASS
7894.20e-035.83e-051.000055✅ PASS
10244.37e-036.22e-051.000058✅ PASS

结论: CPU 与 NPU 输出余弦相似度 ≈ 1.0,精度符合要求(误差 < 1%)。

6. 性能基准

batch_sizeavg (ms)p50 (ms)p99 (ms)
121.921.922.1
440.340.240.4

测试条件: Ascend 910B4, FP32, 随机输入 336×336, 20 次取平均。

7. 文件说明

├── inference.py                  # 推理入口
├── convert_weights.py            # 权重 key 转换
├── modeling_aimv2_distilled.py   # 模型定义
├── configuration_aimv2_distilled.py  # 模型配置
└── README.md                     # 本文档

8. 引用

@misc{fini2024multimodalautoregressivepretraininglarge,
  author={Fini, Enrico and Shukor, Mustafa and Li, Xiujun and others},
  title={Multimodal Autoregressive Pre-training of Large Vision Encoders},
  year={2024},
  eprint={2411.14402},
  archivePrefix={arXiv},
}
下载使用量0