WebSSL-MAE-700M-FULL2B-224 是一个 632M 参数的 Vision Transformer (ViT-L) 模型,使用 Masked Autoencoder (MAE) 自监督学习在 20亿张网络图片上训练。本项目提供其在华为 Ascend NPU 环境下的部署方案。
/data/ysws/agentsp/webssl-mae700m-full2b-224-ascend/
├── inference.py # 精度测试脚本
├── log.txt # 测试日志
├── README.md # 本文档
└── webssl_teaser.png # 模型架构图docker exec -it test-modelagent bashsource /usr/local/Ascend/ascend-toolkit/set_env.sh模型文件应放在 /data/ysws/agentsp/webssl-mae700m-full2b-224/ 目录下:
cd /data/ysws/agentsp/webssl-mae700m-full2b-224-ascend/
python3 inference.py --precision_testcd /data/ysws/agentsp/webssl-mae700m-full2b-224-ascend/
python3 inference.py| 指标 | 实测值 | 阈值 | 状态 |
|---|---|---|---|
| Max Error (sum) | 1.14e-05 | < 1e-3 | PASS |
| Max Error (mean) | 1.06e-10 | < 1e-5 | PASS |
| Max Error (std) | 9.31e-10 | < 1e-5 | PASS |
| 操作 | 耗时 |
|---|---|
| 模型加载 | ~7s |
| CPU 参考计算 (20 tensors) | 0.12s |
| NPU 推理 (20 tensors) | 0.26s |
| 完整推理 (1, 3, 224, 224) | ~6.3s |
完整测试日志保存在 log.txt
import torch
from pathlib import Path
from safetensors.torch import load_file
model_path = "/data/ysws/agentsp/webssl-mae700m-full2b-224"
# 加载模型权重
state_dict = load_file(f"{model_path}/model.safetensors")
# 移动到 NPU
tensor = state_dict["cls_token"].to("npu:0")from transformers import AutoImageProcessor, ViTModel
from PIL import Image
processor = AutoImageProcessor.from_pretrained("facebook/webssl-mae700m-full2b-224")
model = ViTModel.from_pretrained("facebook/webssl-mae700m-full2b-224").cuda().eval()
image = Image.open("path/to/image.jpg")
inputs = processor(images=image, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model(**inputs)
encoder_hidden_states = outputs.last_hidden_stateWebSSL-MAE-700M-FULL2B-224 是一个 ViT-Large 模型 (比 300M 版本更大):
| 组件 | 参数 | 说明 |
|---|---|---|
| patch_embed | 3→1280 | Conv2d 14x14 |
| cls_token | 1,1,1280 | 可学习 [CLS] token |
| position_embeddings | 1,257,1280 | 位置编码 |
| encoder.layers (32层) | 每层 ~19M | ViTBlock 堆叠 |
| norm | LayerNorm(1280) | 最终归一化 |
每层 ViTBlock 包含:
A: 检查 NPU 驱动是否正确安装,确保 CANN 环境变量已 source。
A: 632M 参数模型文件较大 (~2.5GB),safetensors 解析需要一些时间。
A: 632M 参数完整推理约 6 秒属于正常范围,可使用批处理提升吞吐量。
本项目遵循 WebSSL-MAE-700M-FULL2B-224 原始许可证 (cc-by-nc-4.0)。