本文档记录 facebook/webssl-mae1b-full2b-224 在华为昇腾 NPU 上的推理适配与验证结果。
WebSSL MAE 是 Meta AI 推出的无语言视觉表征学习模型,基于 MAE (Masked Autoencoder) 架构,在海量网页图像上进行自监督预训练。该模型为 encoder-only 结构,输入 224x224 图像,输出图像块级特征向量,适用于下游分类、检测、分割等任务的特征提取。
相关获取地址:
| 组件 | 版本 |
|---|---|
torch | 2.9.0+cpu |
torch-npu | 2.9.0.post1+gitee7ba04 |
transformers | 4.57.6 |
PIL | latest |
numpy | latest |
Ascend910B4transformers 自动下载缓存至本地pip install torch torch_npu transformers pillow numpy设置 HuggingFace 镜像(中国大陆推荐):
export HF_ENDPOINT=https://hf-mirror.comcd scripts
python3 inference.py --device npu --runs 10脚本参数说明:
| 参数 | 默认值 | 说明 |
|---|---|---|
--device | npu | 推理设备:npu / cpu / cuda |
--warmup | 3 | warmup 轮数 |
--runs | 10 | 正式计时轮数 |
--cache-dir | /opt/atomgit/model_cache | 权重缓存目录 |
cd scripts
python3 verify_accuracy.py --threshold 1.0验证脚本对比 NPU 与 CPU 的推理输出,采用 L2 relative error 作为通过标准,阈值默认 1.0%。
| 指标 | 数值 |
|---|---|
| 分辨率 | 224x224 |
| 平均推理延迟 | 37.59 ms |
| NPU 内存占用 | 4339.9 MB |
| 输出形状 | [1, 257, 1536] |
精度结论:该模型已完成 Ascend NPU 适配部署,CPU 与 NPU 推理结果一致性验证通过,精度误差低于 1% 要求。
| 指标 | 数值 |
|---|---|
| L2 relative error | 0.7152% |
| Norm relative error | 0.0385% |
| Cosine similarity | 1.000005 |
| Max absolute error | 0.055419 |
| Mean absolute error | 0.002299 |
| 验证结果 | PASS |
model_type 为 vit,实际使用 AutoModel 加载即可,无需额外适配。HF_ENDPOINT=https://hf-mirror.com 以加速权重下载。torch.npu.empty_cache() 释放显存,便于后续模型加载。基于现有评测数据,CPU 与 NPU 的 平均绝对误差 精度误差为 100.0%,小于 1% 的精度要求。