d
dingdang666/dinov3-vits16-pretrain-lvd1689m-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

dinov3-vits16-pretrain-lvd1689m on Ascend NPU

1. 简介

本文档记录 dinov3-vits16-pretrain-lvd1689m(DINOv3 ViT-Small/16)在昇腾 NPU(Ascend 910B3)环境的适配部署与精度验证结果。

DINOv3 ViT-S/16 是一种基于 Vision Transformer 的视觉特征提取模型(约 21.6M 参数),输出 384 维图像特征向量,在 LVD-1689M 上通过 ViT-7B 教师模型蒸馏获得。本项目完成该模型在昇腾 NPU 上的推理适配,验证 NPU 与 CPU 结果的精度误差 < 1%。

相关地址:

  • 权重下载地址(HuggingFace):https://huggingface.co/facebook/dinov3-vits16-pretrain-lvd1689m
  • 适配代码仓库:https://gitcode.com/dingdang666/dinov3-vits16-pretrain-lvd1689m-NPU

2. 验证环境

组件版本
python3.11.x
torch2.10.0+cpu
torch_npu2.10.0
transformers5.8.1
CANN8.5.1
  • NPU:Ascend 910B3
  • 框架:PyTorch + transformers

3. 模型信息

项目值
模型架构ViT-Small/16 (DINOv3)
参数量~21.6M
特征维度384
Layers12
Attention Heads6
Patch Size16
Register Tokens4
输入尺寸3×224×224
权重格式safetensors
框架PyTorch (transformers)
预训练数据LVD-1689M
许可证DINOv3 License

4. Conda 环境安装

conda create -n dinov3-vits16 python=3.11 -y
conda activate dinov3-vits16
pip install torch==2.10.0 torchvision==0.25.0 --index-url https://repo.huaweicloud.com/repository/pypi/simple/
pip install torch_npu==2.10.0 --index-url https://repo.huaweicloud.com/repository/pypi/simple/
pip install transformers safetensors pillow --index-url https://repo.huaweicloud.com/repository/pypi/simple/

权重下载:

export HF_ENDPOINT=https://hf-mirror.com/
huggingface-cli download facebook/dinov3-vits16-pretrain-lvd1689m --local-dir /path/to/model_dir

5. 推理执行

# NPU 推理(默认)
python3 inference.py --model_path /path/to/model --image_path /path/to/img.jpg

# CPU 推理
python3 inference.py --model_path /path/to/model --image_path /path/to/img.jpg --device cpu

# 精度与性能评测
python3 benchmark.py --model_path /path/to/model

评测结果日志将输出到 log.txt。

6. 参数说明

脚本参数说明默认值
inference.py--model_path模型路径必需
--image_path图像路径必需
--device运行设备npu:0
benchmark.py--model_path模型路径必需
--npu_deviceNPU 设备 IDnpu:0
--num_warmup预热轮数3

7. 精度评测

评测方法

测试图像在 CPU(FP32)和 NPU(FP32)上推理,对比输出特征向量。

精度数据

指标数值
向量级相对误差0.239705%
余弦相似度0.9999970794
SNR52.41 dB
最大绝对误差—
平均绝对误差—

判定结论

指标实测值阈值状态
向量级相对误差0.24%< 1%PASS

8. 性能数据

操作耗时
CPU 推理时间(FP32)1.37 s
NPU 推理时间(FP32,3轮预热后)0.25 s
加速比 (CPU / NPU)5.41 x

9. 注意事项

  1. 使用 AutoModel + AutoImageProcessor 标准 transformers 接口。
  2. DINOv3 ViT 包含 4 个 register token,使用 RoPE 位置编码。
  3. 权重文件(.safetensors)不包含在适配仓库中,需单独下载。
  4. 模型较小(21.6M 参数),NPU 加速比约 5x。