本文档记录 facebook/webssl-dino1b-full2b-224 在华为昇腾 NPU 上的推理部署与验证结果。
webssl-dino1b-full2b-224 是基于 DINOv2 架构的 vision transformer 模型,参数量约 1B,输入分辨率为 224×224,用于图像特征提取。本适配基于 torch_npu 的 transfer_to_npu 自动迁移能力,无需修改模型源码即可在昇腾 NPU 上完成 FP32 推理。
相关获取地址:
| 组件 | 版本 |
|---|---|
transformers | 4.57.6 |
torch | 2.9.0+cpu |
torch_npu | 2.9.0.post1+gitee7ba04 |
Pillow | latest |
1 逻辑卡(Ascend910B4)pip install torch torch_npu transformers Pillow numpy -i https://repo.huaweicloud.com/repository/pypi/simple/source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0
export HF_ENDPOINT=https://hf-mirror.compython3 inference.py --device npu --runs 10预期输出:
======================================================================
DINOv2 Inference on Ascend NPU
Model: facebook/webssl-dino1b-full2b-224
Resolution: 224x224
Device: npu
======================================================================
NPU Device: Ascend910B4
...
Output shape: torch.Size([1, 257, 1536])
Output norm: 921.7620
Average inference time (10 runs): 40.85 ms
NPU Memory: allocated=4331.7MB, reserved=4716.0MB精度结论:该模型已完成 Ascend NPU 适配部署,CPU 与 NPU 推理结果一致性验证通过,精度误差低于 1% 要求。
使用 verify_accuracy.py 对 NPU 推理结果与 CPU 基线进行精度对比。
python3 verify_accuracy.py验证结果:
| 指标 | 数值 |
|---|---|
max_abs_error | 0.003912 |
mean_abs_error | 0.000171 |
relative_error | 0.1412% |
cosine_similarity | 0.999997 |
threshold | 1.0% |
| 结果 | PASS |
测试条件:batch_size=1,分辨率 224×224,FP32,warmup=3,runs=10。
| 指标 | 数值 |
|---|---|
load_time | 258.83 s |
avg_latency | 40.85 ms |
output_shape | (1, 257, 1536) |
npu_memory_allocated | 4331.7 MB |
trust_remote_code=True 用于加载模型配置,请确保权重来源可信。ASCEND_RT_VISIBLE_DEVICES 指定目标 NPU。